-
Notifications
You must be signed in to change notification settings - Fork 42
131 lines (126 loc) · 6.2 KB
/
ok-to-test-command.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
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/tasks/prepare_env.yml
ansible-playbook tests/integration/targets/prepare_ndb_env/tasks/prepare_env.yml
ansible-playbook tests/integration/targets/prepare_fc_env/tasks/prepare_fc_env.yml
ansible-playbook tests/integration/targets/prepare_foundation_env/tasks/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/tasks/cleanup.yml
ansible-playbook tests/integration/targets/prepare_foundation_env/tasks/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;