-
Notifications
You must be signed in to change notification settings - Fork 62
492 lines (435 loc) · 16.9 KB
/
ansible-test.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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
name: CI
on:
# Run CI against all pushes (direct commits, also merged PRs), Pull Requests
push:
branches-ignore:
- 'dependabot/**'
paths-ignore:
- 'docs/**'
- '.github/workflows/_shared-*'
- '.github/workflows/docs*.yml'
- '.github/actions/docs/**'
pull_request:
paths-ignore:
- 'docs/**'
- '.github/workflows/_shared-*'
- '.github/workflows/docs*.yml'
- '.github/actions/docs/**'
schedule:
- cron: '0 14 * * *'
env:
NAMESPACE: community
COLLECTION_NAME: hashi_vault
ANSIBLE_FORCE_COLOR: true
ANSIBLE_COLLECTIONS_PATH: ${{ github.workspace }}
jobs:
###
# Sanity tests (REQUIRED)
# https://docs.ansible.com/ansible/latest/dev_guide/testing_sanity.html
sanity:
name: Sanity (Ⓐ${{ matrix.ansible }})
runs-on: ${{ matrix.runner }}
strategy:
fail-fast: false
matrix:
runner:
- ubuntu-latest
test_container:
- default
ansible:
- stable-2.14
- stable-2.15
- stable-2.16
- stable-2.17
- stable-2.18
- devel
steps:
# ansible-test requires the collection to be in a directory in the form
# .../ansible_collections/${{env.NAMESPACE}}/${{env.COLLECTION_NAME}}/
- name: Initialize env vars
uses: briantist/ezenv@v1
with:
env: |
COLLECTION_PATH=ansible_collections/${NAMESPACE}/${COLLECTION_NAME}
TEST_INVOCATION="sanity --docker ${{ matrix.test_container }} -v --color ${{ github.event_name != 'schedule' && '--coverage' || '' }}"
- name: Check out code
uses: actions/checkout@v4
with:
show-progress: false
path: ${{ env.COLLECTION_PATH }}
- name: Link to .github # easier access to local actions
run: ln -s "${COLLECTION_PATH}/.github" .github
- name: Set up Python
uses: actions/setup-python@v5
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.11'
# Install the head of the given branch (devel, stable-2.14)
- name: Install ansible-core (${{ matrix.ansible }})
run: pip install https://github.com/ansible/ansible/archive/${{ matrix.ansible }}.tar.gz --disable-pip-version-check
- name: Pull Ansible test images
timeout-minutes: 5
continue-on-error: true
uses: ./.github/actions/pull-ansible-test-images
with:
working-directory: ${{ env.COLLECTION_PATH }}
ansible-test-invocation: ${{ env.TEST_INVOCATION }}
# 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 ${{ env.TEST_INVOCATION }}
working-directory: ${{ env.COLLECTION_PATH }}
- name: Generate coverage report
if: ${{ github.event_name != 'schedule' }}
run: ansible-test coverage xml -v --requirements --group-by command --group-by environment --group-by target
working-directory: ${{ env.COLLECTION_PATH }}
- name: Upload ${{ github.job }} coverage reports
if: ${{ github.event_name != 'schedule' }}
uses: actions/upload-artifact@v4
with:
name: coverage=${{ github.job }}=ansible_${{ matrix.ansible }}=data
path: ${{ env.COLLECTION_PATH }}/tests/output/reports/
if-no-files-found: error
retention-days: 1
units:
runs-on: ${{ matrix.runner }}
name: Units (Ⓐ${{ matrix.ansible }})
strategy:
fail-fast: false
matrix:
runner:
- ubuntu-latest
test_container:
- default
ansible:
- stable-2.14
- stable-2.15
- stable-2.16
- stable-2.17
- stable-2.18
- devel
steps:
- name: Initialize env vars
uses: briantist/ezenv@v1
with:
env: |
COLLECTION_PATH=ansible_collections/${NAMESPACE}/${COLLECTION_NAME}
TEST_INVOCATION="units --color --docker ${{ matrix.test_container }} ${{ github.event_name != 'schedule' && '--coverage' || '' }}"
- name: Check out code
uses: actions/checkout@v4
with:
show-progress: false
path: ${{ env.COLLECTION_PATH }}
- name: Link to .github # easier access to local actions
run: ln -s "${COLLECTION_PATH}/.github" .github
- name: Set up Python
uses: actions/setup-python@v5
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.11'
- name: Install ansible-core (${{ matrix.ansible }})
run: pip install https://github.com/ansible/ansible/archive/${{ matrix.ansible }}.tar.gz --disable-pip-version-check
- name: Pull Ansible test images
timeout-minutes: 5
continue-on-error: true
uses: ./.github/actions/pull-ansible-test-images
with:
working-directory: ${{ env.COLLECTION_PATH }}
ansible-test-invocation: ${{ env.TEST_INVOCATION }}
# Run the unit tests
- name: Run unit test
run: ansible-test ${{ env.TEST_INVOCATION }}
working-directory: ${{ env.COLLECTION_PATH }}
- name: Generate coverage report
if: ${{ github.event_name != 'schedule' }}
run: ansible-test coverage xml -v --requirements --group-by command --group-by environment --group-by target
working-directory: ${{ env.COLLECTION_PATH }}
- name: Upload ${{ github.job }} coverage reports
if: ${{ github.event_name != 'schedule' }}
uses: actions/upload-artifact@v4
with:
name: coverage=${{ github.job }}=ansible_${{ matrix.ansible }}=data
path: ${{ env.COLLECTION_PATH }}/tests/output/reports/
if-no-files-found: error
retention-days: 1
###
# Integration tests (RECOMMENDED)
#
# https://docs.ansible.com/ansible/latest/dev_guide/testing_integration.html
integration:
runs-on: ${{ matrix.runner }}
name: I (Ⓐ${{ matrix.ansible }}+py${{ matrix.python }}+V[-${{ matrix.vault_minus }}])
strategy:
fail-fast: false
matrix:
runner:
- ubuntu-latest
test_container:
- default
vault_minus:
- 0
- 1
ansible:
- stable-2.14
- stable-2.15
- stable-2.16
- stable-2.17
- stable-2.18
- devel
python:
- '3.6'
- '3.7'
- '3.8'
- '3.9'
- '3.10'
- '3.11'
- '3.12'
- '3.13'
exclude:
# https://docs.ansible.com/ansible/devel/installation_guide/intro_installation.html#control-node-requirements
# https://docs.ansible.com/ansible/devel/reference_appendices/release_and_maintenance.html#ansible-core-support-matrix
- ansible: 'devel'
python: '3.6'
- ansible: 'devel'
python: '3.7'
- ansible: 'devel'
python: '3.8'
- ansible: 'devel'
python: '3.9'
- ansible: 'stable-2.18'
python: '3.6'
- ansible: 'stable-2.18'
python: '3.7'
- ansible: 'stable-2.18'
python: '3.8'
- ansible: 'stable-2.18'
python: '3.9'
- ansible: 'stable-2.17'
python: '3.13'
- ansible: 'stable-2.17'
python: '3.6'
- ansible: 'stable-2.17'
python: '3.7'
- ansible: 'stable-2.17'
python: '3.8'
- ansible: 'stable-2.17'
python: '3.9'
- ansible: 'stable-2.16'
python: '3.13'
- ansible: 'stable-2.16'
python: '3.6'
- ansible: 'stable-2.16'
python: '3.7'
- ansible: 'stable-2.16'
python: '3.8'
- ansible: 'stable-2.16'
python: '3.9'
- ansible: 'stable-2.15'
python: '3.13'
- ansible: 'stable-2.15'
python: '3.6'
- ansible: 'stable-2.15'
python: '3.7'
- ansible: 'stable-2.15'
python: '3.12'
- ansible: 'stable-2.15'
python: '3.8'
- ansible: 'stable-2.14'
python: '3.13'
- ansible: 'stable-2.14'
python: '3.12'
steps:
- name: Initialize env vars
uses: briantist/ezenv@v1
with:
env: |
COLLECTION_PATH=ansible_collections/${NAMESPACE}/${COLLECTION_NAME}
COLLECTION_INTEGRATION_PATH=${COLLECTION_PATH}/tests/integration
COLLECTION_INTEGRATION_TARGETS=${COLLECTION_INTEGRATION_PATH}/targets
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"
- name: Check out code
uses: actions/checkout@v4
with:
show-progress: false
path: ${{ env.COLLECTION_PATH }}
- name: Link to .github # easier access to local actions
run: ln -s "${COLLECTION_PATH}/.github" .github
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Get Vault versions
id: vault_versions
uses: ./.github/actions/docker-image-versions
with:
image: hashicorp/vault
num_major_versions: 1
num_minor_versions: 2
num_micro_versions: 1
- name: Install ansible-core (${{ matrix.ansible }})
run: pip install https://github.com/ansible/ansible/archive/${{ matrix.ansible }}.tar.gz --disable-pip-version-check
- name: Install community.postgresql
uses: ./.github/actions/collection-via-git
with:
collection: community.postgresql
- name: Pull Ansible test images
timeout-minutes: 5
continue-on-error: true
uses: ./.github/actions/pull-ansible-test-images
with:
working-directory: ${{ env.COLLECTION_PATH }}
ansible-test-invocation: ${{ env.TEST_INVOCATION }}
- name: Set Vault Version
uses: briantist/ezenv@v1
with:
env: VAULT_VERSION=${{ fromJSON(steps.vault_versions.outputs.versions)[matrix.vault_minus] }}
- name: Prepare docker dependencies (Vault ${{ env.VAULT_VERSION }})
run: ./setup.sh -e vault_version=${VAULT_VERSION}
working-directory: ${{ env.COLLECTION_INTEGRATION_TARGETS }}/setup_localenv_gha
- name: Run integration test (Vault ${{ env.VAULT_VERSION }})
run: ansible-test ${{ env.TEST_INVOCATION }}
working-directory: ${{ env.COLLECTION_PATH }}
# ansible-test support producing code coverage data
- name: Generate coverage report
if: ${{ github.event_name != 'schedule' }}
run: ansible-test coverage xml -v --requirements --group-by command --group-by environment --group-by target
working-directory: ${{ env.COLLECTION_PATH }}
- name: Upload ${{ github.job }} coverage reports
if: ${{ github.event_name != 'schedule' }}
uses: actions/upload-artifact@v4
with:
name: coverage=${{ github.job }}=ansible_${{ matrix.ansible }}=${{ matrix.python }}=vault_minus_${{ matrix.vault_minus }}=data
path: ${{ env.COLLECTION_PATH }}/tests/output/reports/
if-no-files-found: error
retention-days: 1
local_test_invocation:
runs-on: ${{ matrix.runner }}
name: LI - ${{ matrix.runner }} (Ⓐ${{ matrix.ansible }}+py${{ matrix.python }})
strategy:
fail-fast: false
matrix:
ansible:
- stable-2.18
- devel
delete_canaries:
- true
- false
python:
- '3.12'
runner:
- ubuntu-latest
test_container:
- default
exclude:
- ansible: devel
delete_canaries: false
- ansible: stable-2.18
delete_canaries: true
steps:
- name: Initialize env vars
uses: briantist/ezenv@v1
with:
env: |
COLLECTION_PATH=ansible_collections/${NAMESPACE}/${COLLECTION_NAME}
COLLECTION_INTEGRATION_PATH=${COLLECTION_PATH}/tests/integration
COLLECTION_INTEGRATION_TARGETS=${COLLECTION_INTEGRATION_PATH}/targets
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' || '' }}"
- name: Check out code
uses: actions/checkout@v4
with:
show-progress: false
path: ${{ env.COLLECTION_PATH }}
- name: Link to .github # easier access to local actions
run: ln -s "${COLLECTION_PATH}/.github" .github
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python }}
- name: Install ansible-core (${{ matrix.ansible }})
run: pip install https://github.com/ansible/ansible/archive/${{ matrix.ansible }}.tar.gz --disable-pip-version-check
- name: Install community.crypto
uses: ./.github/actions/collection-via-git
with:
collection: community.crypto
- name: Install community.docker
uses: ./.github/actions/collection-via-git
with:
collection: community.docker
- name: Install community.postgresql
uses: ./.github/actions/collection-via-git
with:
collection: community.postgresql
- name: Pull Ansible test images
timeout-minutes: 5
continue-on-error: true
uses: ./.github/actions/pull-ansible-test-images
with:
working-directory: ${{ env.COLLECTION_PATH }}
ansible-test-invocation: ${{ env.DOCKER_TEST_INVOCATION }}
- name: localenv_docker - setup
run: |
pwd
./setup.sh
working-directory: ${{ env.COLLECTION_INTEGRATION_TARGETS }}/setup_localenv_docker
- name: localenv_docker - Run integration test (in docker)
run: |
ansible-test ${{ env.DOCKER_TEST_INVOCATION }} --docker-network hashi_vault_default
working-directory: ${{ env.COLLECTION_PATH }}
#TODO add capability in the Ansible side once vault_list and vault_delete exist
- name: Delete Vault's cubbyhole contents (ensure test setup is idempotent)
if: matrix.delete_canaries
working-directory: ${{ env.COLLECTION_PATH }}
env:
VAULT_TOKEN: 47542cbc-6bf8-4fba-8eda-02e0a0d29a0a
VAULT_ADDR: http://vault:8200
run: |
echo 'vault list cubbyhole \
| tail -n +3 \
| xargs -I{} -n 1 vault delete cubbyhole/{}' \
| docker run --rm --network hashi_vault_default -e VAULT_TOKEN -e VAULT_ADDR -i hashicorp/vault sh
- name: Run integration again (ensure tests do not break against still-running containers)
working-directory: ${{ env.COLLECTION_PATH }}
run: |
ansible-test ${{ env.DOCKER_TEST_INVOCATION }} --docker-network hashi_vault_default
# ansible-test support producing code coverage data
- name: Generate coverage report
if: ${{ github.event_name != 'schedule' }}
run: ansible-test coverage xml -v --requirements --group-by command --group-by environment --group-by target
working-directory: ${{ env.COLLECTION_PATH }}
- name: Upload ${{ github.job }} coverage reports
if: ${{ github.event_name != 'schedule' }}
uses: actions/upload-artifact@v4
with:
name: coverage=${{ github.job }}=${{ matrix.runner }}=ansible_${{ matrix.ansible }}=${{ matrix.python }}=data
path: ${{ env.COLLECTION_PATH }}/tests/output/reports/
if-no-files-found: error
retention-days: 1
upload-coverage:
needs:
- sanity
- units
- integration
- local_test_invocation
# don't upload coverage on scheduled runs
# https://github.com/ansible-collections/community.hashi_vault/issues/180
if: ${{ github.event_name != 'schedule' }}
name: Upload Codecov reports
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v4
with:
show-progress: false
- name: Download artifacts
uses: actions/download-artifact@v4
with:
path: ./cov
# See the reports at https://codecov.io/gh/ansible-collections/community.hashi_vault
- name: Upload coverage reports to Codecov
uses: ./.github/actions/ansible-codecov
with:
directory: ./cov
directory-flag-pattern: =ansible_{ansible-%}=