-
Notifications
You must be signed in to change notification settings - Fork 93
350 lines (298 loc) · 11.7 KB
/
ci.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
name: CI
on:
merge_group:
workflow_dispatch:
pull_request:
push:
branches:
- main
permissions:
contents: read
issues: write
jobs:
sanity:
name: Sanity
runs-on: ubuntu-20.04
steps:
- name: Harden Runner
uses: step-security/harden-runner@91182cccc01eb5e619899d80e4e971d6181294a7 # v2.10.1
with:
egress-policy: audit
- name: Checkout
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- name: Install Python
uses: actions/setup-python@82c7e631bb3cdc910f68e0081d67478d79c6982d # v5.1.0
with:
python-version: '3.11'
- name: Run pre-commit checks
uses: pre-commit/action@2c7b3805fd2a0fd8c1884dcaebf91fc102a13ecd # v3.0.1
env:
SETUPTOOLS_USE_DISTUTILS: stdlib
- name: Check clowdapp manifest
run: bash .github/scripts/check_clowdapp.sh
smokes-labeler:
name: Smoke Test Label
runs-on: ubuntu-20.04
permissions:
contents: read
issues: write
pull-requests: write
steps:
- name: Harden Runner
uses: step-security/harden-runner@91182cccc01eb5e619899d80e4e971d6181294a7 # v2.10.1
with:
egress-policy: audit
- name: Checkout
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
with:
fetch-depth: 0
- name: get Docker image files
id: docker-files
run: .github/scripts/files_require_smokes.sh >> docker-files.txt
- name: add other required files
id: add-files
run: |
echo .dockerignore >> docker-files.txt;
echo Dockerfile >> docker-files.txt;
echo pr_check.sh >> docker-files.txt;
echo deploy/clowdapp.yaml >> docker-files.txt;
- name: Show Dockerfiles
run: cat docker-files.txt
- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@d6babd6899969df1a11d14c368283ea4436bca78 # v44.5.2
with:
files_from_source_file: docker-files.txt
- name: Set whether to run tests
id: check-files
run: |
if [ ! -z "${{ steps.changed-files.outputs.all_changed_and_modified_files }}" ]; then
echo "RUN_TESTS=true" >> $GITHUB_ENV
fi
- name: Set smokes-required label
if: env.RUN_TESTS == 'true'
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
continue-on-error: true
with:
script: |
github.rest.issues.addLabels({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
labels: [ 'smokes-required' ]
})
const response = await github.rest.issues.listLabelsOnIssue({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
})
const labels = response.data.map(({name}) => name)
if (labels.includes('ok-to-skip-smokes')) {
github.rest.issues.removeLabel({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
name: 'ok-to-skip-smokes'
})
}
- name: Set ok-to-skip-smokes label
if: env.RUN_TESTS != 'true'
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
continue-on-error: true
with:
script: |
github.rest.issues.addLabels({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
labels: [ 'ok-to-skip-smokes' ]
})
const response = await github.rest.issues.listLabelsOnIssue({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
})
const labels = response.data.map(({name}) => name)
if (labels.includes('smokes-required')) {
github.rest.issues.removeLabel({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
name: 'smokes-required'
})
}
changed-files:
name: Detect changed files
runs-on: ubuntu-20.04
outputs:
run_tests: ${{ steps.check-files-or-fork.outputs.run_tests }}
steps:
- name: Harden Runner
uses: step-security/harden-runner@91182cccc01eb5e619899d80e4e971d6181294a7 # v2.10.1
with:
egress-policy: audit
- name: Checkout
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
with:
fetch-depth: 0
- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@d6babd6899969df1a11d14c368283ea4436bca78 # v44.5.2
with:
files: |
db_functions/**
koku/**
.github/postgres/**
.github/scripts/check_migrations.sh
.github/workflows/ci.yml
Pipfile.lock
- name: Check files or fork
id: check-files-or-fork
run: |
if [ "${{ steps.changed-files.outputs.any_modified }}" == "true" ] || [ "${{ github.event.pull_request.head.repo.full_name }}" != "project-koku/koku" ]; then
echo "run_tests=true" >> $GITHUB_OUTPUT
fi
- name: Show changed files
run: |
echo "Changed files:"
for file in ${{ steps.changed-files.outputs.all_changed_and_modified_files }}; do
echo " $file"
done
units:
name: Units - ${{ matrix.python-version }}
needs: changed-files
runs-on: ubuntu-20.04
strategy:
fail-fast: false
max-parallel: 4
matrix:
python-version:
- '3.11'
env:
COMPOSE_FILE: .github/postgres/docker-compose.yaml
steps:
- name: Harden Runner
uses: step-security/harden-runner@91182cccc01eb5e619899d80e4e971d6181294a7 # v2.10.1
with:
egress-policy: audit
- name: Checkout
if: needs.changed-files.outputs.run_tests == 'true'
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
with:
fetch-depth: 0
- name: Display build environment
if: needs.changed-files.outputs.run_tests == 'true'
run: printenv
- name: Start the postgres DB
if: needs.changed-files.outputs.run_tests == 'true'
run: docker compose up -d db
- name: Set up Python ${{ matrix.python-version }}
if: needs.changed-files.outputs.run_tests == 'true'
uses: actions/setup-python@82c7e631bb3cdc910f68e0081d67478d79c6982d # v5.1.0
with:
python-version: ${{ matrix.python-version }}
- name: Install pipenv
if: needs.changed-files.outputs.run_tests == 'true'
run: sudo python3 -m pip install pipenv
- name: Cache dependencies
if: needs.changed-files.outputs.run_tests == 'true'
id: cache-dependencies
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
with:
path: |
~/.cache/pipenv
~/.local/share/virtualenvs
key: ${{ runner.os }}-env-${{ matrix.python-version }}-${{ hashFiles('**/Pipfile.lock') }}-${{ secrets.ACTIONS_CACHE_KEY_UUID }}
- name: Install dependencies
if: needs.changed-files.outputs.run_tests == 'true' && steps.cache-dependencies.outputs.cache-hit != 'true'
run: |
pipenv install --dev --deploy --python ${{ matrix.python-version }}
- name: Check migrations
if: |
needs.changed-files.outputs.run_tests == 'true'
&& !(contains(github.event.pull_request.labels.*.name, 'skip-migration-check'))
run: bash .github/scripts/check_migrations.sh
env:
DATABASE_SERVICE_NAME: POSTGRES_SQL
DATABASE_ENGINE: postgresql
DATABASE_NAME: postgres
DATABASE_USER: postgres
DATABASE_PASSWORD: postgres
POSTGRES_SQL_SERVICE_HOST: localhost
POSTGRES_SQL_SERVICE_PORT: ${{ job.services.postgres.ports[5432] }}
PROMETHEUS_MULTIPROC_DIR: /tmp
- name: Run unit tests
if: needs.changed-files.outputs.run_tests == 'true'
id: unit_tests_run
run: pipenv run coverage run ./koku/manage.py test --noinput --verbosity 2 ./koku/
env:
DATABASE_SERVICE_NAME: POSTGRES_SQL
DATABASE_ENGINE: postgresql
DATABASE_NAME: postgres
DATABASE_USER: postgres
DATABASE_PASSWORD: postgres
POSTGRES_SQL_SERVICE_HOST: localhost
POSTGRES_SQL_SERVICE_PORT: ${{ job.services.postgres.ports[5432] }}
HIVE_DATABASE_PASSWORD: hivedbpw
ACCOUNT_ENHANCED_METRICS: True
PROMETHEUS_MULTIPROC_DIR: /tmp
TRINO_DATE_STEP: 31
MIDDLEWARE_TIME_TO_LIVE: 0
ENHANCED_ORG_ADMIN: True
ENABLE_S3_ARCHIVING: True
- name: Show test status
if: needs.changed-files.outputs.run_tests == 'true'
id: show_test_status
run: echo "Unit tests and migration check were '${{ steps.unit_tests_run.outcome }}'"
- name: Convert coverage report to XML
if: steps.unit_tests_run.outcome == 'success'
run: pipenv run coverage xml
- name: Upload test coverage file
if: steps.unit_tests_run.outcome == 'success'
uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # v4.3.3
with:
name: coverage
path: coverage.xml
overwrite: true
coverage:
name: Coverage
needs: [ changed-files,units ]
runs-on: ubuntu-20.04
permissions:
contents: write
statuses: write
steps:
- name: Harden Runner
uses: step-security/harden-runner@91182cccc01eb5e619899d80e4e971d6181294a7 # v2.10.1
with:
egress-policy: audit
- name: Checkout
# this checkout is required for the coverage report. If we don't do this, then
# the uploaded report is invalid and codecov doesn't know how to process it.
if: needs.changed-files.outputs.run_tests == 'true'
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
with:
fetch-depth: 0
- name: Download coverage result from units
if: needs.changed-files.outputs.run_tests == 'true'
uses: actions/download-artifact@65a9edc5881444af0b9093a5e628f2fe47ea3b2e # v4.1.7
with:
name: coverage
- name: Upload coverage to Codecov
if: needs.changed-files.outputs.run_tests == 'true'
uses: codecov/codecov-action@125fc84a9a348dbcf27191600683ec096ec9021c # v4.4.1
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
with:
file: ./coverage.xml
flags: unittests
name: Python-${{ matrix.python-version}}
fail_ci_if_error: true
plugin: pycoverage # Only run one plugin even though we don't want any to run.
- name: Set Codecov job status on skipped tests
if: needs.changed-files.outputs.run_tests != 'true'
env:
GITHUB_TOKEN: "${{ github.token }}"
run: |
gh api "/repos/project-koku/koku/statuses/${{ github.event.pull_request.head.sha }}" -f description="codecov skipped because unit tests were not required" -f context="codecov/patch" -f state="success"
gh api "/repos/project-koku/koku/statuses/${{ github.event.pull_request.head.sha }}" -f description="codecov skipped because unit tests were not required" -f context="codecov/project" -f state="success"