Skip to content

Release/1.9.3

Release/1.9.3 #1252

Workflow file for this run

---
name: Run compile and tests
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
sanity1:
name: Sanity tests with ansible-core==2.15.0
runs-on: ubuntu-20.04
strategy:
matrix:
python-version: ["3.9"]
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Setup Docker
uses: docker-practice/actions-setup-docker@master
- name: Install ansible
run: |
pip install -r requirements.txt
- name: Build and install the collection
run: |
NAMESPACE=$(cat galaxy.yml | shyaml get-value namespace)
COLLECTION_NAME=$(cat galaxy.yml | shyaml get-value name)
VERSION=$(cat galaxy.yml | shyaml get-value version)
echo "NAMESPACE=${NAMESPACE}" >> $GITHUB_ENV
echo "COLLECTION_NAME=${COLLECTION_NAME}" >> $GITHUB_ENV
ansible-galaxy collection build --force
ansible-galaxy collection install ${NAMESPACE}-${COLLECTION_NAME}-${VERSION}.tar.gz --force
- name: Run tests
run: |
cd /home/${USER}/.ansible/collections/ansible_collections/${{ env.NAMESPACE }}/${{ env.COLLECTION_NAME }}
ansible-test sanity --docker default --python ${{ matrix.python-version }} -v
unit_testing:
runs-on: ubuntu-20.04
strategy:
matrix:
python-version: ["3.9"]
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Setup Docker
uses: docker-practice/actions-setup-docker@master
- name: Install ansible
run: |
pip install -r requirements.txt
- name: Build and install the collection
run: |
NAMESPACE=$(cat galaxy.yml | shyaml get-value namespace)
COLLECTION_NAME=$(cat galaxy.yml | shyaml get-value name)
VERSION=$(cat galaxy.yml | shyaml get-value version)
echo "NAMESPACE=${NAMESPACE}" >> $GITHUB_ENV
echo "COLLECTION_NAME=${COLLECTION_NAME}" >> $GITHUB_ENV
ansible-galaxy collection build --force
ansible-galaxy collection install ${NAMESPACE}-${COLLECTION_NAME}-${VERSION}.tar.gz --force
- name: Run tests
run: |
cd /home/${USER}/.ansible/collections/ansible_collections/${{ env.NAMESPACE }}/${{ env.COLLECTION_NAME }}
ansible-test units --docker default --python ${{ matrix.python-version }} --coverage -v
ansible-test coverage report --include */plugins/* --omit */utils.py,_fetch_url* > coverage.txt
- name: Code Coverage Check
run: |
cd /home/${USER}/.ansible/collections/ansible_collections/${{ env.NAMESPACE }}/${{ env.COLLECTION_NAME }}
echo "Code coverage: Checking if code coverage is above threshold..."
export TESTCOV_THRESHOLD=55
echo "Threshold: $TESTCOV_THRESHOLD %"
totalCoverage=`grep TOTAL coverage.txt | awk '{print $6}' | sed 's/%//'`
echo "TOTAL_COVERAGE=${totalCoverage}" >> $GITHUB_ENV
echo "Current test coverage : $totalCoverage %"
if (( $(echo "$totalCoverage $TESTCOV_THRESHOLD" | awk '{print ($1 > $2)}') )); then
echo "Coverage passed"
else
echo "Current test coverage is below threshold. Please add more unit tests or adjust threshold to a lower value."
echo "Coverage check failed"
exit 1
fi