Debian Codegraph @

ansible_collections/community/hashi_vault/.github/workflows/ansible-test.yml

raw
1 name: CI
2 on:
3 # Run CI against all pushes (direct commits, also merged PRs), Pull Requests
4 push:
5 branches-ignore:
6 - 'dependabot/**'
7 paths-ignore:
8 - 'docs/**'
9 - '.github/workflows/_shared-*'
10 - '.github/workflows/docs*.yml'
11 - '.github/actions/docs/**'
12 pull_request:
13 paths-ignore:
14 - 'docs/**'
15 - '.github/workflows/_shared-*'
16 - '.github/workflows/docs*.yml'
17 - '.github/actions/docs/**'
18 schedule:
19 - cron: '0 14 * * *'
20 env:
21 NAMESPACE: community
22 COLLECTION_NAME: hashi_vault
23 ANSIBLE_FORCE_COLOR: true
24 ANSIBLE_COLLECTIONS_PATH: ${{ github.workspace }}
25
26 jobs:
27
28 ###
29 # Sanity tests (REQUIRED)
30 # https://docs.ansible.com/ansible/latest/dev_guide/testing_sanity.html
31
32 sanity:
33 name: Sanity (Ⓐ${{ matrix.ansible }})
34 runs-on: ${{ matrix.runner }}
35 strategy:
36 fail-fast: false
37 matrix:
38 runner:
39 - ubuntu-latest
40 test_container:
41 - default
42 ansible:
43 - stable-2.20
44 - devel
45 steps:
46
47 # ansible-test requires the collection to be in a directory in the form
48 # .../ansible_collections/${{env.NAMESPACE}}/${{env.COLLECTION_NAME}}/
49 - name: Initialize env vars
50 uses: briantist/ezenv@v1
51 with:
52 env: |
53 COLLECTION_PATH=ansible_collections/${NAMESPACE}/${COLLECTION_NAME}
54 TEST_INVOCATION="sanity --docker ${{ matrix.test_container }} -v --color ${{ github.event_name != 'schedule' && '--coverage' || '' }}"
55
56 - name: Check out code
57 uses: actions/checkout@v5
58 with:
59 show-progress: false
60 path: ${{ env.COLLECTION_PATH }}
61
62 - name: Link to .github # easier access to local actions
63 run: ln -s "${COLLECTION_PATH}/.github" .github
64
65 - name: Set up Python
66 uses: actions/setup-python@v6
67 with:
68 # it is just required to run that once as "ansible-test sanity" in the docker image
69 # will run on all python versions it supports.
70 python-version: '3.13'
71
72 # Install the head of the given branch (devel, stable-2.14)
73 - name: Install ansible-core (${{ matrix.ansible }})
74 run: pip install https://github.com/ansible/ansible/archive/${{ matrix.ansible }}.tar.gz --disable-pip-version-check
75
76 - name: Pull Ansible test images
77 timeout-minutes: 5
78 continue-on-error: true
79 uses: ./.github/actions/pull-ansible-test-images
80 with:
81 working-directory: ${{ env.COLLECTION_PATH }}
82 ansible-test-invocation: ${{ env.TEST_INVOCATION }}
83
84 # run ansible-test sanity inside of Docker.
85 # The docker container has all the pinned dependencies that are required
86 # and all python versions ansible supports.
87 - name: Run sanity tests
88 run: ansible-test ${{ env.TEST_INVOCATION }}
89 working-directory: ${{ env.COLLECTION_PATH }}
90
91 - name: Generate coverage report
92 if: ${{ github.event_name != 'schedule' }}
93 run: ansible-test coverage xml -v --requirements --group-by command --group-by environment --group-by target
94 working-directory: ${{ env.COLLECTION_PATH }}
95
96 - name: Upload ${{ github.job }} coverage reports
97 if: ${{ github.event_name != 'schedule' }}
98 uses: actions/upload-artifact@v4
99 with:
100 name: coverage=${{ github.job }}=ansible_${{ matrix.ansible }}=data
101 path: ${{ env.COLLECTION_PATH }}/tests/output/reports/
102 if-no-files-found: error
103 retention-days: 1
104
105
106 units:
107 runs-on: ${{ matrix.runner }}
108 name: Units (Ⓐ${{ matrix.ansible }})
109 strategy:
110 fail-fast: false
111 matrix:
112 runner:
113 - ubuntu-latest
114 test_container:
115 - default
116 ansible:
117 - stable-2.17
118 - stable-2.18
119 - stable-2.19
120 - stable-2.20
121 - devel
122
123 steps:
124 - name: Initialize env vars
125 uses: briantist/ezenv@v1
126 with:
127 env: |
128 COLLECTION_PATH=ansible_collections/${NAMESPACE}/${COLLECTION_NAME}
129 TEST_INVOCATION="units --color --docker ${{ matrix.test_container }} ${{ github.event_name != 'schedule' && '--coverage' || '' }}"
130
131 - name: Check out code
132 uses: actions/checkout@v5
133 with:
134 show-progress: false
135 path: ${{ env.COLLECTION_PATH }}
136
137 - name: Link to .github # easier access to local actions
138 run: ln -s "${COLLECTION_PATH}/.github" .github
139
140 - name: Set up Python
141 uses: actions/setup-python@v6
142 with:
143 # it is just required to run that once as "ansible-test units" in the docker image
144 # will run on all python versions it supports.
145 python-version: '3.12'
146
147 - name: Install ansible-core (${{ matrix.ansible }})
148 run: pip install https://github.com/ansible/ansible/archive/${{ matrix.ansible }}.tar.gz --disable-pip-version-check
149
150 - name: Pull Ansible test images
151 timeout-minutes: 5
152 continue-on-error: true
153 uses: ./.github/actions/pull-ansible-test-images
154 with:
155 working-directory: ${{ env.COLLECTION_PATH }}
156 ansible-test-invocation: ${{ env.TEST_INVOCATION }}
157
158 # Run the unit tests
159 - name: Run unit test
160 run: ansible-test ${{ env.TEST_INVOCATION }}
161 working-directory: ${{ env.COLLECTION_PATH }}
162
163 - name: Generate coverage report
164 if: ${{ github.event_name != 'schedule' }}
165 run: ansible-test coverage xml -v --requirements --group-by command --group-by environment --group-by target
166 working-directory: ${{ env.COLLECTION_PATH }}
167
168 - name: Upload ${{ github.job }} coverage reports
169 if: ${{ github.event_name != 'schedule' }}
170 uses: actions/upload-artifact@v4
171 with:
172 name: coverage=${{ github.job }}=ansible_${{ matrix.ansible }}=data
173 path: ${{ env.COLLECTION_PATH }}/tests/output/reports/
174 if-no-files-found: error
175 retention-days: 1
176
177 ###
178 # Integration tests (RECOMMENDED)
179 #
180 # https://docs.ansible.com/ansible/latest/dev_guide/testing_integration.html
181
182 integration:
183 runs-on: ${{ matrix.runner }}
184 name: I (Ⓐ${{ matrix.ansible }}+py${{ matrix.python }}+V[-${{ matrix.vault_minus }}])
185 strategy:
186 fail-fast: false
187 matrix:
188 runner:
189 - ubuntu-latest
190 test_container:
191 - default
192 vault_minus:
193 - 0
194 - 1
195 ansible:
196 - stable-2.17
197 - stable-2.18
198 - stable-2.19
199 - stable-2.20
200 - devel
201 python:
202 - '3.8'
203 - '3.9'
204 - '3.10'
205 - '3.11'
206 - '3.12'
207 - '3.13'
208 exclude:
209 # https://docs.ansible.com/ansible/devel/installation_guide/intro_installation.html#control-node-requirements
210 # https://docs.ansible.com/ansible/devel/reference_appendices/release_and_maintenance.html#ansible-core-support-matrix
211 - ansible: 'devel'
212 python: '3.8'
213 - ansible: 'devel'
214 python: '3.9'
215 - ansible: 'stable-2.20'
216 python: '3.8'
217 - ansible: 'stable-2.20'
218 python: '3.9'
219 - ansible: 'stable-2.19'
220 python: '3.8'
221 - ansible: 'stable-2.19'
222 python: '3.9'
223 - ansible: 'stable-2.18'
224 python: '3.8'
225 - ansible: 'stable-2.18'
226 python: '3.9'
227 - ansible: 'stable-2.17'
228 python: '3.13'
229 - ansible: 'stable-2.17'
230 python: '3.8'
231 - ansible: 'stable-2.17'
232 python: '3.9'
233
234 steps:
235 - name: Initialize env vars
236 uses: briantist/ezenv@v1
237 with:
238 env: |
239 COLLECTION_PATH=ansible_collections/${NAMESPACE}/${COLLECTION_NAME}
240 COLLECTION_INTEGRATION_PATH=${COLLECTION_PATH}/tests/integration
241 COLLECTION_INTEGRATION_TARGETS=${COLLECTION_INTEGRATION_PATH}/targets
242 TEST_INVOCATION="integration -v --color --retry-on-error --continue-on-error --python ${{ matrix.python }} --docker ${{ matrix.test_container }} ${{ github.event_name != 'schedule' && '--coverage' || '' }} --docker-network hashi_vault_default"
243
244 - name: Check out code
245 uses: actions/checkout@v5
246 with:
247 show-progress: false
248 path: ${{ env.COLLECTION_PATH }}
249
250 - name: Link to .github # easier access to local actions
251 run: ln -s "${COLLECTION_PATH}/.github" .github
252
253 - name: Set up Python
254 uses: actions/setup-python@v6
255 with:
256 python-version: '3.12'
257
258 - name: Get Vault versions
259 id: vault_versions
260 uses: ./.github/actions/docker-image-versions
261 with:
262 image: hashicorp/vault
263 num_major_versions: 1
264 num_minor_versions: 2
265 num_micro_versions: 1
266
267 - name: Install ansible-core (${{ matrix.ansible }})
268 run: pip install https://github.com/ansible/ansible/archive/${{ matrix.ansible }}.tar.gz --disable-pip-version-check
269
270 - name: Install community.postgresql
271 uses: ./.github/actions/collection-via-git
272 with:
273 collection: community.postgresql
274
275 - name: Pull Ansible test images
276 timeout-minutes: 5
277 continue-on-error: true
278 uses: ./.github/actions/pull-ansible-test-images
279 with:
280 working-directory: ${{ env.COLLECTION_PATH }}
281 ansible-test-invocation: ${{ env.TEST_INVOCATION }}
282
283 - name: Set Vault Version
284 uses: briantist/ezenv@v1
285 with:
286 env: VAULT_VERSION=${{ fromJSON(steps.vault_versions.outputs.versions)[matrix.vault_minus] }}
287
288 - name: Prepare docker dependencies (Vault ${{ env.VAULT_VERSION }})
289 run: ./setup.sh -e vault_version=${VAULT_VERSION}
290 working-directory: ${{ env.COLLECTION_INTEGRATION_TARGETS }}/setup_localenv_gha
291
292 - name: Run integration test (Vault ${{ env.VAULT_VERSION }})
293 run: ansible-test ${{ env.TEST_INVOCATION }}
294 working-directory: ${{ env.COLLECTION_PATH }}
295
296 # ansible-test support producing code coverage data
297 - name: Generate coverage report
298 if: ${{ github.event_name != 'schedule' }}
299 run: ansible-test coverage xml -v --requirements --group-by command --group-by environment --group-by target
300 working-directory: ${{ env.COLLECTION_PATH }}
301
302 - name: Upload ${{ github.job }} coverage reports
303 if: ${{ github.event_name != 'schedule' }}
304 uses: actions/upload-artifact@v4
305 with:
306 name: coverage=${{ github.job }}=ansible_${{ matrix.ansible }}=${{ matrix.python }}=vault_minus_${{ matrix.vault_minus }}=data
307 path: ${{ env.COLLECTION_PATH }}/tests/output/reports/
308 if-no-files-found: error
309 retention-days: 1
310
311 local_test_invocation:
312 runs-on: ${{ matrix.runner }}
313 name: LI - ${{ matrix.runner }} (Ⓐ${{ matrix.ansible }}+py${{ matrix.python }})
314 strategy:
315 fail-fast: false
316 matrix:
317 ansible:
318 - stable-2.20
319 - devel
320 delete_canaries:
321 - true
322 - false
323 python:
324 - '3.13'
325 runner:
326 - ubuntu-latest
327 test_container:
328 - default
329 exclude:
330 - ansible: devel
331 delete_canaries: false
332 - ansible: stable-2.20
333 delete_canaries: true
334
335 steps:
336 - name: Initialize env vars
337 uses: briantist/ezenv@v1
338 with:
339 env: |
340 COLLECTION_PATH=ansible_collections/${NAMESPACE}/${COLLECTION_NAME}
341 COLLECTION_INTEGRATION_PATH=${COLLECTION_PATH}/tests/integration
342 COLLECTION_INTEGRATION_TARGETS=${COLLECTION_INTEGRATION_PATH}/targets
343 DOCKER_TEST_INVOCATION="integration -v --color --retry-on-error --continue-on-error --controller docker:${{ matrix.test_container }},python=${{ matrix.python }} ${{ github.event_name != 'schedule' && '--coverage' || '' }}"
344
345 - name: Check out code
346 uses: actions/checkout@v5
347 with:
348 show-progress: false
349 path: ${{ env.COLLECTION_PATH }}
350
351 - name: Link to .github # easier access to local actions
352 run: ln -s "${COLLECTION_PATH}/.github" .github
353
354 - name: Set up Python
355 uses: actions/setup-python@v6
356 with:
357 python-version: ${{ matrix.python }}
358
359 - name: Install ansible-core (${{ matrix.ansible }})
360 run: pip install https://github.com/ansible/ansible/archive/${{ matrix.ansible }}.tar.gz --disable-pip-version-check
361
362 - name: Install community.crypto
363 uses: ./.github/actions/collection-via-git
364 with:
365 collection: community.crypto
366
367 - name: Install community.docker
368 uses: ./.github/actions/collection-via-git
369 with:
370 collection: community.docker
371
372 - name: Install community.postgresql
373 uses: ./.github/actions/collection-via-git
374 with:
375 collection: community.postgresql
376
377 - name: Pull Ansible test images
378 timeout-minutes: 5
379 continue-on-error: true
380 uses: ./.github/actions/pull-ansible-test-images
381 with:
382 working-directory: ${{ env.COLLECTION_PATH }}
383 ansible-test-invocation: ${{ env.DOCKER_TEST_INVOCATION }}
384
385 - name: localenv_docker - setup
386 run: |
387 pwd
388 ./setup.sh
389 working-directory: ${{ env.COLLECTION_INTEGRATION_TARGETS }}/setup_localenv_docker
390
391 - name: localenv_docker - Run integration test (in docker)
392 run: |
393 ansible-test ${{ env.DOCKER_TEST_INVOCATION }} --docker-network hashi_vault_default
394 working-directory: ${{ env.COLLECTION_PATH }}
395
396 #TODO add capability in the Ansible side once vault_list and vault_delete exist
397 - name: Delete Vault's cubbyhole contents (ensure test setup is idempotent)
398 if: matrix.delete_canaries
399 working-directory: ${{ env.COLLECTION_PATH }}
400 env:
401 VAULT_TOKEN: 47542cbc-6bf8-4fba-8eda-02e0a0d29a0a
402 VAULT_ADDR: http://vault:8200
403 run: |
404 echo 'vault list cubbyhole \
405 | tail -n +3 \
406 | xargs -I{} -n 1 vault delete cubbyhole/{}' \
407 | docker run --rm --network hashi_vault_default -e VAULT_TOKEN -e VAULT_ADDR -i hashicorp/vault sh
408
409 - name: Run integration again (ensure tests do not break against still-running containers)
410 working-directory: ${{ env.COLLECTION_PATH }}
411 run: |
412 ansible-test ${{ env.DOCKER_TEST_INVOCATION }} --docker-network hashi_vault_default
413
414 # ansible-test support producing code coverage data
415 - name: Generate coverage report
416 if: ${{ github.event_name != 'schedule' }}
417 run: ansible-test coverage xml -v --requirements --group-by command --group-by environment --group-by target
418 working-directory: ${{ env.COLLECTION_PATH }}
419
420 - name: Upload ${{ github.job }} coverage reports
421 if: ${{ github.event_name != 'schedule' }}
422 uses: actions/upload-artifact@v4
423 with:
424 name: coverage=${{ github.job }}=${{ matrix.runner }}=ansible_${{ matrix.ansible }}=${{ matrix.python }}=data
425 path: ${{ env.COLLECTION_PATH }}/tests/output/reports/
426 if-no-files-found: error
427 retention-days: 1
428
429 upload-coverage:
430 needs:
431 - sanity
432 - units
433 - integration
434 - local_test_invocation
435 # don't upload coverage on scheduled runs
436 # https://github.com/ansible-collections/community.hashi_vault/issues/180
437 if: ${{ github.event_name != 'schedule' }}
438 name: Upload Codecov reports
439 runs-on: ubuntu-latest
440 steps:
441 - name: Check out code
442 uses: actions/checkout@v5
443 with:
444 show-progress: false
445
446 - name: Download artifacts
447 uses: actions/download-artifact@v5
448 with:
449 path: ./cov
450
451 # See the reports at https://codecov.io/gh/ansible-collections/community.hashi_vault
452 - name: Upload coverage reports to Codecov
453 uses: ./.github/actions/ansible-codecov
454 env:
455 GH_TOKEN: ${{ github.token }}
456 with:
457 directory: ./cov
458 directory-flag-pattern: =ansible_{ansible-%}=