Blog for Recovery Points under Data Protection #1959
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: Integration Test cases | |
on: | |
pull_request: | |
repository_dispatch: | |
types: [ok-to-test-command] | |
jobs: | |
integration_test_cases: | |
timeout-minutes: 600 | |
runs-on: self-hosted | |
strategy: | |
max-parallel: 1 | |
matrix: | |
python-version: ["3.9"] | |
if: github.event_name == 'repository_dispatch' | |
steps: | |
- run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event." | |
- uses: actions/checkout@v2 | |
with: | |
ref: refs/pull/${{ github.event.client_payload.pull_request.number }}/merge | |
- name: Set up Python ${{ matrix.python-version }} | |
uses: actions/setup-python@v2 | |
with: | |
python-version: ${{ matrix.python-version }} | |
- name: Install dependencies | |
run: | | |
pip install -r tests/integration/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 Integration test cases | |
run: | | |
cd /home/${USER}/.ansible/collections/ansible_collections/${{ env.NAMESPACE }}/${{ env.COLLECTION_NAME }} | |
export NUTANIX_HOST=${{ secrets.PC_IP }} | |
export NUTANIX_PASSWORD=${{ secrets.PC_PASSWORD }} | |
export NUTANIX_USERNAME=${{ secrets.PC_USERNAME }} | |
export NUTANIX_DR_SITE=${{ secrets.NUTANIX_DR_SITE }} | |
export NDB_HOST=${{ secrets.NDB_HOST }} | |
export NDB_PASSWORD=${{ secrets.NDB_PASSWORD }} | |
export NDB_USERNAME=${{ secrets.NDB_USERNAME }} | |
args="${{ github.event.client_payload.slash_command.args.all }}" | |
flag="" | |
if [ "$args" = "allow-disabled" ] | |
then | |
flag="--allow-disabled" | |
fi | |
echo '${{ secrets.FOUNDATION_CONFIG }}' > tests/integration/targets/prepare_foundation_env/vars/main.yml | |
echo '${{ secrets.FC_CONFIG }}' > tests/integration/targets/prepare_fc_env/vars/main.yml | |
echo '${{ secrets.PC_CONFIG }}' > tests/integration/targets/prepare_env/vars/main.yml | |
echo '${{ secrets.NDB_CONFIG }}' > tests/integration/targets/prepare_ndb_env/vars/main.yml | |
ansible-playbook tests/integration/targets/prepare_env/playbooks/prepare_env.yml | |
ansible-playbook tests/integration/targets/prepare_ndb_env/playbooks/prepare_env.yml | |
ansible-playbook tests/integration/targets/prepare_fc_env/playbooks/prepare_fc_env.yml | |
ansible-playbook tests/integration/targets/prepare_foundation_env/playbooks/prepare_foundation_env.yml | |
ansible-test integration --continue-on-error --python ${{ matrix.python-version }} --coverage $flag | |
ansible-test coverage report > coverage.txt | |
ansible-playbook tests/integration/targets/prepare_env/playbooks/cleanup.yml | |
ansible-playbook tests/integration/targets/prepare_foundation_env/playbooks/cleanup.yml | |
- name: Code Coverage Check | |
if: ${{ always() }} | |
run: | | |
cd /home/${USER}/.ansible/collections/ansible_collections/${{ env.NAMESPACE }}/${{ env.COLLECTION_NAME }} | |
ansible-test coverage html | |
sshpass -p '${{ secrets.FILER_PASSWORD }}' scp -r tests/output ${{ secrets.FILER_LOCATION }} | |
echo "Code coverage: Checking if code coverage is above threshold..." | |
export COVERAGE_THRESHOLD=70 | |
echo "Threshold: $COVERAGE_THRESHOLD %" | |
totalCoverage=`grep TOTAL coverage.txt | awk '{print $6}' | sed 's/%//'` | |
echo "TOTAL_COVERAGE=${totalCoverage}" >> $GITHUB_ENV | |
echo "Current integration test coverage : $totalCoverage %" | |
if (( $(echo "$totalCoverage $COVERAGE_THRESHOLD" | awk '{print ($1 > $2)}') )); then | |
echo "Coverage passed" | |
else | |
echo "Current integration test coverage is below threshold. Please add more integration tests or adjust threshold to a lower value." | |
echo "Coverage check failed" | |
exit 1 | |
fi | |
- run: echo "🍏 This job's status is ${{ job.status }}." | |
# Update the comment back | |
- name: Update comment | |
uses: peter-evans/create-or-update-comment@v1 | |
if: ${{ always() }} | |
with: | |
comment-id: ${{ github.event.client_payload.github.payload.comment.id }} | |
body: | | |
>Integration test run status is : ${{ job.status }} | |
>Converage is : ${{ env.TOTAL_COVERAGE }} % | |
>Job link https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }} | |
reaction-type: hooray | |
# Update check run for Integration Test | |
- uses: actions/github-script@v5 | |
id: update-check-run | |
if: ${{ always() }} | |
env: | |
number: ${{ github.event.client_payload.pull_request.number }} | |
job: ${{ github.job }} | |
# Conveniently, job.status maps to https://developer.github.com/v3/checks/runs/#update-a-check-run | |
conclusion: ${{ job.status }} | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
script: | | |
const { data: pull } = await github.rest.pulls.get({ | |
...context.repo, | |
pull_number: process.env.number | |
}); | |
const ref = pull.head.sha; | |
const { data: checks } = await github.rest.checks.listForRef({ | |
...context.repo, | |
ref | |
}); | |
const check = checks.check_runs.filter(c => c.name === process.env.job); | |
if (check.length == 0) { | |
return "Check is not present, ignoring this step." | |
} | |
const { data: result } = await github.rest.checks.update({ | |
...context.repo, | |
check_run_id: check[0].id, | |
status: 'completed', | |
conclusion: process.env.conclusion | |
}); | |
return result; |