-
Notifications
You must be signed in to change notification settings - Fork 73
208 lines (176 loc) · 7.02 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
name: CI
on:
pull_request:
schedule:
- cron: "0 3 * * *"
env:
mongodb_version_file: "./tests/integration/targets/setup_mongodb/defaults/main.yml"
jobs:
sanity:
runs-on: ubuntu-20.04
defaults:
run:
working-directory: ansible_collections/community/mongodb
strategy:
matrix:
versions:
- python_version: "3.10"
ansible_version: "stable-2.15"
- python_version: "3.10"
ansible_version: "stable-2.16"
- python_version: "3.11"
ansible_version: "devel"
steps:
- name: Check out code
uses: actions/checkout@v4
with:
path: ansible_collections/community/mongodb
- name: Set up Python ${{ matrix.versions.python_version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.versions.python_version }}
- name: Install ansible-base (${{ matrix.versions.ansible_version }})
uses: nick-invision/retry@v3
with:
timeout_minutes: 3
max_attempts: 3
command: pip install https://github.com/ansible/ansible/archive/${{ matrix.versions.ansible_version }}.tar.gz --disable-pip-version-check
- name: Run sanity tests
run: ansible-test sanity --docker -v --color --python ${{ matrix.versions.python_version }} --exclude docs/* --exclude tests/ansible-operator/
units:
runs-on: ubuntu-20.04
defaults:
run:
working-directory: ansible_collections/community/mongodb
strategy:
matrix:
versions:
- python_version: "3.10"
ansible_version: "stable-2.15"
- python_version: "3.10"
ansible_version: "stable-2.16"
- python_version: "3.11"
ansible_version: "devel"
steps:
- name: Check out code
uses: actions/checkout@v4
with:
path: ansible_collections/community/mongodb
- name: Set up Python ${{ matrix.versions.python_version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.versions.python_version }}
- name: Install ansible-base (${{ matrix.versions.ansible_version }})
uses: nick-invision/retry@v3
with:
timeout_minutes: 3
max_attempts: 3
command: pip install https://github.com/ansible/ansible/archive/${{ matrix.versions.ansible_version }}.tar.gz --disable-pip-version-check
- name: Install mongodb
uses: nick-invision/retry@v3
with:
timeout_minutes: 3
max_attempts: 3
command: sudo apt-get install -y mongodb-org
- name: Install dateutil
uses: nick-invision/retry@v3
with:
timeout_minutes: 3
max_attempts: 3
command: pip install python-dateutil
- name: Install python libs
uses: nick-invision/retry@v3
with:
timeout_minutes: 3
max_attempts: 3
command: pip install mtools==1.7.2 pymongo psutil coverage pytest pytest-forked pytest-xdist pytest-mock
- name: Start a replicaset with mtools (3 nodes, starting from port 27017, auth enabled, rs name = replset)
run: mlaunch --replicaset --auth
working-directory: /home/runner/work/
- name: Launch a single instance (no auth)
run: mlaunch --single --port 27999
- name: Run unit tests
run: ansible-test units -v --color --python ${{ matrix.versions.python_version }} --coverage
- name: Generate coverage report.
run: ansible-test coverage xml -v --requirements --group-by command --group-by version
- uses: codecov/codecov-action@v3
with:
fail_ci_if_error: false
- name: Clean up mlaunch replicaset
run: mtools stop --auth-user user --auth-password password || true
integration_matrix:
runs-on: ubuntu-20.04
defaults:
run:
working-directory: ansible_collections/community/mongodb
outputs:
matrix: ${{ steps.json-list.outputs.modules-to-test }}
steps:
- name: Check out code
uses: actions/checkout@v4
with:
path: ansible_collections/community/mongodb
- name: Generate module list
run: |
find tests/integration/targets -type d -maxdepth 1 -not -name 'setup*' -not -name 'master_tasks' | cut -d '/' -f4 | sort | awk NF | jq -sRc 'split("\n") | map(select(length > 0))' > int_test_modules.json
- name: Set output variable
id: json-list
run: |
output=$(cat int_test_modules.json)
echo "modules-to-test=$output" >> $GITHUB_OUTPUT
echo "$output"
integration:
needs: integration_matrix
runs-on: ubuntu-20.04
defaults:
run:
working-directory: ansible_collections/community/mongodb
strategy:
matrix:
mongodb_version:
- "6.0"
- "7.0"
mongodb_module: ${{ fromJson(needs.integration_matrix.outputs.matrix) }}
versions:
- python_version: "3.10"
ansible_version: "stable-2.15"
docker_image: "ubuntu2204"
- python_version: "3.10"
ansible_version: "stable-2.16"
docker_image: "ubuntu2204"
- python_version: "3.11"
ansible_version: "devel"
docker_image: "ubuntu2204"
steps:
- name: Check out code
uses: actions/checkout@v4
with:
path: ansible_collections/community/mongodb
- name: Set up Python ${{ matrix.versions.python_version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.versions.python_version }}
- name: Install ansible-base (${{ matrix.versions.ansible_version }})
uses: nick-invision/retry@v3
with:
timeout_minutes: 3
max_attempts: 3
command: pip install https://github.com/ansible/ansible/archive/${{ matrix.versions.ansible_version }}.tar.gz --disable-pip-version-check
- name: Install community.general
uses: nick-invision/retry@v3
with:
timeout_minutes: 3
max_attempts: 3
command: ansible-galaxy collection install 'community.general' -p ansible_collections/
- name: Install community.crypto
uses: nick-invision/retry@v3
with:
timeout_minutes: 3
max_attempts: 3
command: ansible-galaxy collection install community.crypto -p ansible_collections/
- name: Ensure MongoDB version is set to ${{ matrix.mongodb_version }}
run: "sed -i 's/^mongodb_version:.*/mongodb_version: \"${{ matrix.mongodb_version }}\"/g' ${{ env.mongodb_version_file }}"
- name: Run integration tests on Python ${{ matrix.versions.python_version }} | ${{ matrix.versions.docker_image }} | ${{ matrix.versions.ansible_version }} | ${{ matrix.mongodb_version }}
run: ansible-test integration --docker ${{ matrix.versions.docker_image }} -v --color --retry-on-error --python 3.10 --continue-on-error --diff --coverage ${{ matrix.mongodb_module }}
- name: Upload Coverage data
run: tests/coverage.sh