Skip to content

CI - Sanity & Unit #422

CI - Sanity & Unit

CI - Sanity & Unit #422

Workflow file for this run

---
name: CI - Sanity & Unit
on:
# Run CI against all pushes (direct commits, also merged PRs), Pull Requests
push:
pull_request:
# Run CI once per day (at 12:12 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
schedule:
- cron: '12 12 * * *'
env:
NAMESPACE: spot
COLLECTION_NAME: cloud_modules
jobs:
###
# Sanity tests (REQUIRED)
#
# https://docs.ansible.com/ansible/latest/dev_guide/testing_sanity.html
# TODO shibel: uncomment sanity tests once we are ready
# 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.10
# - stable-2.11
# - stable-2.12
#
# 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@v2
# with:
# path: ansible_collections/${{env.NAMESPACE}}/${{env.COLLECTION_NAME}}
#
# - name: Set up Python
# uses: actions/setup-python@v2
# 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.8
#
# # 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
# working-directory: ./ansible_collections/${{env.NAMESPACE}}/${{env.COLLECTION_NAME}}
###
# 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.10
- stable-2.11
- stable-2.12
- devel
steps:
- name: Check out code
uses: actions/checkout@v2
with:
path: ansible_collections/${{env.NAMESPACE}}/${{env.COLLECTION_NAME}}
- name: Set up Python
uses: actions/setup-python@v2
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.10.12
- 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 ansible.netcommon ansible.utils -p .
# TODO shibel: figure out how to put dynamic Python version here without breaking tests
# There doesn't seem to be a way to ignore *own* unit tests for ansible-core < 2.12
# Run the unit tests
- name: Run unit tests (ansible-core < 2.12)
if: ${{matrix.ansible == 'stable-2.9' || matrix.ansible == 'stable-2.10' || matrix.ansible == 'stable-2.11'}}
run: ansible-test units -v --color --docker --coverage --python 3.6
working-directory: ./ansible_collections/${{env.NAMESPACE}}/${{env.COLLECTION_NAME}}
- name: Run unit tests (ansible-core >= 2.12)
if: ${{matrix.ansible != 'stable-2.9' && matrix.ansible != 'stable-2.10' && matrix.ansible != 'stable-2.11'}}
run: ansible-test units -v --color --docker --coverage
working-directory: ./ansible_collections/${{env.NAMESPACE}}/${{env.COLLECTION_NAME}}
###
# Integration tests (RECOMMENDED)
#
# https://docs.ansible.com/ansible/latest/dev_guide/testing_integration.html