CI #27
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
# README FIRST | |
# 1. replace "NAMESPACE" and "COLLECTION_NAME" with the correct name in the env section (e.g. with 'community' and 'mycollection') | |
# 2. If you don't have unit tests remove that section | |
# 3. If your collection depends on other collections ensure they are installed, see "Install collection dependencies" | |
# If you need help please ask in #ansible-community on the Libera.chat IRC network | |
name: CI | |
on: | |
# Run CI against all pushes (direct commits, also merged PRs), Pull Requests | |
push: | |
branches: | |
- main | |
pull_request: | |
workflow_dispatch: | |
# Run CI once per day (at 06:00 UTC) | |
# This ensures that even if there haven't been commits that we are still testing against latest version of ansible-test for each ansible-base version | |
env: | |
NAMESPACE: cwollinger | |
COLLECTION_NAME: alerta | |
jobs: | |
### | |
# Sanity tests (REQUIRED) | |
# | |
# https://docs.ansible.com/ansible/latest/dev_guide/testing_sanity.html | |
sanity: | |
name: Sanity (Ⓐ${{ matrix.ansible }}) | |
strategy: | |
matrix: | |
ansible: | |
# It's important that Sanity is tested against all stable-X.Y branches | |
# Testing against `devel` may fail as new tests are added. | |
# - stable-2.9 # Only if your collection supports Ansible 2.9 | |
- stable-2.11 | |
- stable-2.12 | |
- stable-2.13 | |
- devel | |
runs-on: ubuntu-latest | |
steps: | |
# ansible-test requires the collection to be in a directory in the form | |
# .../ansible_collections/${{env.NAMESPACE}}/${{env.COLLECTION_NAME}}/ | |
- name: Check out code | |
uses: actions/checkout@v3 | |
with: | |
path: ansible_collections/${{env.NAMESPACE}}/${{env.COLLECTION_NAME}} | |
- name: Set up Python | |
uses: actions/setup-python@v3 | |
with: | |
# it is just required to run that once as "ansible-test sanity" in the docker image | |
# will run on all python versions it supports. | |
python-version: '3.10' | |
# Install the head of the given branch (devel, stable-2.10) | |
- name: Install ansible-base (${{ matrix.ansible }}) | |
run: pip install https://github.com/ansible/ansible/archive/${{ matrix.ansible }}.tar.gz --disable-pip-version-check | |
# run ansible-test sanity inside of Docker. | |
# The docker container has all the pinned dependencies that are required | |
# and all python versions ansible supports. | |
- name: Run sanity tests | |
run: ansible-test sanity --docker -v --color --coverage | |
working-directory: ./ansible_collections/${{env.NAMESPACE}}/${{env.COLLECTION_NAME}} | |
# ansible-test support producing code coverage date | |
- name: Generate coverage report | |
run: ansible-test coverage xml -v --requirements --group-by command --group-by version | |
working-directory: ./ansible_collections/${{env.NAMESPACE}}/${{env.COLLECTION_NAME}} | |
# See the reports at https://codecov.io/gh/GITHUBORG/REPONAME | |
- uses: codecov/codecov-action@v3 | |
with: | |
fail_ci_if_error: false | |
### | |
# Unit tests (OPTIONAL) | |
# | |
# https://docs.ansible.com/ansible/latest/dev_guide/testing_units.html | |
units: | |
runs-on: ubuntu-latest | |
name: Units (Ⓐ${{ matrix.ansible }}) | |
strategy: | |
# As soon as the first unit test fails, cancel the others to free up the CI queue | |
fail-fast: true | |
matrix: | |
ansible: | |
# - stable-2.9 # Only if your collection supports Ansible 2.9 | |
- stable-2.11 | |
- stable-2.12 | |
- stable-2.13 | |
- devel | |
steps: | |
- name: Check out code | |
uses: actions/checkout@v3 | |
with: | |
path: ansible_collections/${{env.NAMESPACE}}/${{env.COLLECTION_NAME}} | |
- name: Set up Python | |
uses: actions/setup-python@v3 | |
with: | |
# it is just required to run that once as "ansible-test units" in the docker image | |
# will run on all python versions it supports. | |
python-version: '3.9' | |
- name: Install ansible-base (${{ matrix.ansible }}) | |
run: pip install https://github.com/ansible/ansible/archive/${{ matrix.ansible }}.tar.gz --disable-pip-version-check | |
# OPTIONAL If your unit test requires Python libraries from other collections | |
# Install them like this | |
- name: Install collection dependencies | |
run: ansible-galaxy collection install community.general -p . | |
# Run the unit tests | |
- name: Run unit test | |
run: ansible-test units -v --color --docker --coverage --python 3.9 | |
working-directory: ./ansible_collections/${{env.NAMESPACE}}/${{env.COLLECTION_NAME}} | |
# ansible-test support producing code coverage date | |
- name: Generate coverage report | |
run: ansible-test coverage xml -v --requirements --group-by command --group-by version | |
working-directory: ./ansible_collections/${{env.NAMESPACE}}/${{env.COLLECTION_NAME}} | |
# See the reports at https://codecov.io/gh/GITHUBORG/REPONAME | |
- uses: codecov/codecov-action@v3 | |
with: | |
fail_ci_if_error: false | |
flags: units | |
integration: | |
runs-on: ubuntu-latest | |
name: I (Ⓐ${{ matrix.ansible }}+py${{ matrix.python }}) | |
strategy: | |
fail-fast: false | |
matrix: | |
ansible: | |
# - stable-2.9 # Only if your collection supports Ansible 2.9 | |
- stable-2.10 | |
- stable-2.11 | |
- stable-2.12 | |
- stable-2.13 | |
- devel | |
python: | |
# - '2.6' | |
# - '2.7' | |
# - '3.5' | |
# - '3.6' | |
# - '3.7' | |
# - '3.8' | |
- '3.9' | |
- '3.10' | |
exclude: | |
# Because ansible-test doesn't support Python 3.9 for Ansible 2.9 | |
# and Python 3.10 is supported in 2.12 or later. | |
- ansible: stable-2.9 | |
python: '3.9' | |
- ansible: stable-2.9 | |
python: '3.10' | |
- ansible: stable-2.10 | |
python: '3.10' | |
- ansible: stable-2.11 | |
python: '3.10' | |
services: | |
postgres: | |
image: postgres:12 | |
env: | |
POSTGRES_DB: alerta | |
POSTGRES_USER: postgres | |
POSTGRES_PASSWORD: postgres | |
ports: | |
# Maps tcp port 5432 on service container to the host | |
- 5432:5432 | |
options: >- | |
--health-cmd pg_isready | |
--health-interval 10s | |
--health-timeout 5s | |
--health-retries 5 | |
alerta: | |
image: alerta/alerta-web | |
ports: | |
- 8080:8080 | |
env: | |
DATABASE_URL: postgres://postgres:postgres@postgres:5432/alerta | |
AUTH_REQUIRED: True | |
CUSTOMER_VIEWS: True | |
ADMIN_USERS: [email protected] | |
ADMIN_PASSWORD: password | |
ADMIN_KEY: demo-key | |
steps: | |
- name: Check out code | |
uses: actions/checkout@v3 | |
with: | |
path: ansible_collections/${{env.NAMESPACE}}/${{env.COLLECTION_NAME}} | |
- name: Set up Python | |
uses: actions/setup-python@v3 | |
with: | |
# it is just required to run that once as "ansible-test integration" in the docker image | |
# will run on all python versions it supports. | |
python-version: ${{ matrix.python }} | |
- name: Install ansible-base (${{ matrix.ansible }}) | |
run: pip install https://github.com/ansible/ansible/archive/${{ matrix.ansible }}.tar.gz --disable-pip-version-check | |
# # OPTIONAL If your integration test requires Python libraries or modules from other collections | |
# # Install them like this | |
# - name: Install collection dependencies | |
# run: ansible-galaxy collection install ansible.netcommon -p . | |
# Run the integration tests | |
- name: Run integration test | |
run: ansible-test integration -v --color --retry-on-error --continue-on-error --requirements --diff --python ${{ matrix.python }} --coverage | |
working-directory: ./ansible_collections/${{env.NAMESPACE}}/${{env.COLLECTION_NAME}} | |
# ansible-test support producing code coverage date | |
- name: Generate coverage report | |
run: ansible-test coverage xml -v --requirements --group-by command --group-by version | |
working-directory: ./ansible_collections/${{env.NAMESPACE}}/${{env.COLLECTION_NAME}} | |
# See the reports at https://codecov.io/gh/GITHUBORG/REPONAME | |
- uses: codecov/codecov-action@v3 | |
with: | |
fail_ci_if_error: false | |
flags: integration |