-
Notifications
You must be signed in to change notification settings - Fork 92
290 lines (252 loc) · 9.3 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
name: CI
on:
merge_group:
workflow_dispatch:
pull_request:
push:
branches:
- main
jobs:
sanity:
name: Sanity
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/[email protected]
- name: Install Python
uses: actions/[email protected]
with:
python-version: '3.11'
- name: Run pre-commit checks
uses: pre-commit/[email protected]
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
steps:
- name: Checkout
uses: actions/[email protected]
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/[email protected]
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: Setting smokes-required label
if: env.RUN_TESTS == 'true'
uses: actions/[email protected]
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' ]
})
github.rest.issues.removeLabel({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
name: 'ok-to-skip-smokes'
})
- name: Remove smokes-required label
if: env.RUN_TESTS != 'true'
uses: actions/[email protected]
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' ]
})
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: Checkout
uses: actions/[email protected]
with:
fetch-depth: 0
- name: Get changed files
id: changed-files
uses: tj-actions/[email protected]
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: Checkout
if: needs.changed-files.outputs.run_tests == 'true'
uses: actions/[email protected]
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/[email protected]
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/[email protected]
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 --ignore-pipfile --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/[email protected]
with:
name: coverage
path: coverage.xml
overwrite: true
coverage:
name: Coverage
needs: [changed-files,units]
runs-on: ubuntu-20.04
steps:
- 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/[email protected]
with:
fetch-depth: 0
- name: Download coverage result from units
if: needs.changed-files.outputs.run_tests == 'true'
uses: actions/[email protected]
with:
name: coverage
- name: Upload coverage to Codecov
if: needs.changed-files.outputs.run_tests == 'true'
uses: codecov/[email protected]
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"