Ansible Collection Integration Tests #248
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Ansible Collection Integration Tests | |
on: | |
schedule: | |
- cron: "0 5 * * *" # UTC | |
push: | |
tags: "v*" | |
branches: | |
- "test/**" | |
jobs: | |
integration-test: | |
name: >- | |
Integration test on ansible-core ${{ matrix.ansible }} | |
using Python ${{ matrix.python }} | |
runs-on: ubuntu-22.04 | |
defaults: | |
run: | |
working-directory: ansible_collections/cloudscale_ch/cloud | |
strategy: | |
max-parallel: 1 | |
fail-fast: false | |
matrix: | |
ansible: | |
- 2.13 | |
- 2.14 | |
- 2.15 | |
include: | |
- ansible: 2.13 | |
python: 3.8 | |
- ansible: 2.14 | |
python: 3.9 | |
- ansible: 2.15 | |
python: 3.9 | |
steps: | |
- name: Check out code | |
uses: actions/checkout@v4 | |
with: | |
path: ansible_collections/cloudscale_ch/cloud | |
- name: Set up Python ${{ matrix.python }} | |
uses: actions/setup-python@v4 | |
with: | |
python-version: ${{ matrix.python }} | |
- name: Install ansible and collection dependencies | |
run: | | |
python -m pip install --upgrade pip | |
# Install the latest ansible-core patchlevel version | |
pip install 'ansible-core~=${{ matrix.ansible }}.0' | |
pip install -r tests/requirements.txt | |
- name: Build and install collection | |
run: | | |
ansible-galaxy collection build . | |
ansible-galaxy collection install *.gz | |
- name: Add config file | |
env: | |
CONFIG_FILE: ${{ secrets.CONFIG_FILE }} | |
INI_FILE: tests/integration/cloud-config-cloudscale.ini | |
run: | | |
echo -n "$CONFIG_FILE" > $INI_FILE && [ -s $INI_FILE ] || (>&2 echo no secrets provided; exit 1) | |
- name: Ensure no other integration test is currently running | |
uses: softprops/turnstyle@v1 | |
timeout-minutes: 60 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
same-branch-only: false | |
- name: Run the tests | |
run: >- | |
ansible-test | |
integration | |
--docker | |
--python ${{ matrix.python }} | |
-v | |
--diff | |
--color | |
--allow-unsupported | |
--continue-on-error | |
--coverage | |
cloud/cloudscale/ | |
- name: Generate coverage report. | |
run: >- | |
ansible-test | |
coverage xml | |
-v | |
--requirements | |
--group-by command | |
--group-by version | |
- uses: codecov/codecov-action@v3 | |
with: | |
fail_ci_if_error: false | |
- name: Send mail in case of failure | |
id: send_mail | |
if: ${{ failure() && github.event_name == 'schedule' }} | |
shell: python3 {0} | |
run: | | |
from smtplib import SMTP | |
from email.message import EmailMessage | |
email = EmailMessage() | |
email['TO'] = '${{ secrets.CRON_RCPT }}' | |
email['FROM'] = '[email protected]' | |
email['Subject'] = 'Ansible Cloud Module Integration Test Failure' | |
email.set_content(""" | |
Integration tests using ansible-core ${{ matrix.ansible }} on Python ${{ matrix.python }} failed: | |
https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }} | |
""") | |
with SMTP('${{ secrets.MAILSERVER }}') as smtp: | |
smtp.starttls() | |
smtp.send_message(email) |