-
Notifications
You must be signed in to change notification settings - Fork 0
391 lines (341 loc) · 14.1 KB
/
validate.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
---
name: Validation Pipeline
on:
# Enable workflow as callable from another workflow
workflow_call:
inputs:
python-versions-linux:
description: 'Python versions to test on Linux (JSON array)'
required: true
type: string
python-versions-windows:
description: 'Python versions to test on Windows (JSON array)'
required: true
type: string
files-changed:
description: 'Boolean string result for if any files have changed'
type: string
required: false
default: 'false'
build-files-changed:
description: 'Boolean string result for if build files have changed'
type: string
required: false
default: 'false'
ci-files-changed:
description: 'Boolean string result for if CI files have changed'
type: string
required: false
default: 'false'
doc-files-changed:
description: 'Boolean string result for if documentation files have changed'
type: string
required: false
default: 'false'
src-files-changed:
description: 'Boolean string result for if source files have changed'
type: string
required: false
default: 'false'
test-files-changed:
description: 'Boolean string result for if test files have changed'
type: string
required: false
default: 'false'
outputs:
new-release-detected:
description: Boolean string result for if new release is available
value: ${{ jobs.build.outputs.new-release-detected }}
distribution-artifacts:
description: Artifact Download name for the distribution artifacts
value: ${{ jobs.build.outputs.distribution-artifacts }}
# secrets: none required ATT
# set default Token permissions = none
permissions: {}
env:
LOWEST_PYTHON_VERSION: '3.8'
COMMON_PYTHON_VERSION: '3.11'
jobs:
build:
name: Build
runs-on: ubuntu-latest
if: ${{ inputs.build-files-changed == 'true' || inputs.src-files-changed == 'true' || inputs.test-files-changed == 'true' || inputs.ci-files-changed == 'true' }}
steps:
- name: Setup | Checkout Repository at workflow sha
uses: actions/[email protected]
with:
ref: ${{ github.sha }}
fetch-depth: 0
- name: Setup | Force correct release branch on workflow sha
run: |
git checkout -B ${{ github.ref_name }}
- name: Setup | Install Python ${{ env.COMMON_PYTHON_VERSION }}
uses: actions/setup-python@v5
with:
python-version: ${{ env.COMMON_PYTHON_VERSION }}
cache: 'pip'
- name: Setup | Install dependencies
run: |
python -m pip install --upgrade pip setuptools wheel
pip install -e .[build]
- name: Build | Create the distribution artifacts
id: build
run: |
if new_version="$(semantic-release --strict version --print)"; then
printf '%s\n' "::notice::Next version will be '$new_version'"
printf '%s\n' "new_release_detected=true" >> $GITHUB_OUTPUT
semantic-release version --changelog --no-commit --no-tag
else
printf '%s\n' "new_release_detected=false" >> $GITHUB_OUTPUT
python -m build .
fi
printf '%s\n' "dist_dir=dist/*" >> $GITHUB_OUTPUT
printf '%s\n' "artifacts_name=dist" >> $GITHUB_OUTPUT
- name: Upload | Distribution Artifacts
uses: actions/upload-artifact@v4
with:
name: ${{ steps.build.outputs.artifacts_name }}
path: ${{ steps.build.outputs.dist_dir }}
if-no-files-found: error
retention-days: 2
outputs:
new-release-detected: ${{ steps.build.outputs.new_release_detected }}
distribution-artifacts: ${{ steps.build.outputs.artifacts_name }}
unit-test:
name: Unit Tests
if: ${{ inputs.src-files-changed == 'true' || inputs.test-files-changed == 'true' || inputs.ci-files-changed == 'true' }}
runs-on: ubuntu-latest
steps:
- name: Setup | Checkout Repository
uses: actions/[email protected]
with:
ref: ${{ github.sha }}
fetch-depth: 1
- name: Setup | Install Python ${{ env.LOWEST_PYTHON_VERSION }}
uses: actions/setup-python@v5
with:
python-version: ${{ env.LOWEST_PYTHON_VERSION }}
cache: 'pip'
- name: Setup | Install dependencies
run: |
python -m pip install --upgrade pip setuptools wheel
pip install -e .[test]
pip install pytest-github-actions-annotate-failures
- name: Test | Run pytest -m unit --comprehensive
id: tests
run: |
pytest \
-vv \
-nauto \
-m unit \
--comprehensive \
--cov=semantic_release \
--cov-context=test \
--cov-report=term-missing \
--cov-fail-under=60 \
--junit-xml=tests/reports/pytest-results.xml
- name: Report | Upload Test Results
uses: mikepenz/[email protected]
if: ${{ always() && steps.tests.outcome != 'skipped' }}
with:
report_paths: ./tests/reports/*.xml
annotate_only: true
test-linux:
name: Python ${{ matrix.python-version }} on ${{ matrix.os }} E2E tests
runs-on: ${{ matrix.os }}
needs:
- build
- unit-test
if: ${{ inputs.src-files-changed == 'true' || inputs.test-files-changed == 'true' || inputs.ci-files-changed == 'true' }}
strategy:
matrix:
python-version: ${{ fromJson(inputs.python-versions-linux) }}
os:
- ubuntu-latest
steps:
- name: Setup | Checkout Repository
uses: actions/[email protected]
with:
ref: ${{ github.sha }}
fetch-depth: 1
- name: Setup | Install Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'
- name: Setup | Download Distribution Artifacts
uses: actions/download-artifact@v4
with:
name: ${{ needs.build.outputs.distribution-artifacts }}
path: ./dist
- name: Setup | Install dependencies
id: install
# To ensure we are testing our installed package (not the src code), we must
# uninstall the editable install (symlink) first then install the distribution artifact.
# Lastly, we ask python to give us the installation location of our distribution artifact
# so that we can use it in the pytest command for coverage
run: |
python -m pip install --upgrade pip setuptools wheel
pip install -e .[test]
pip install pytest-github-actions-annotate-failures
pip uninstall -y python-semantic-release
pip install dist/python_semantic_release-*.whl
python -c 'import pathlib, semantic_release; print(f"PKG_INSTALLED_DIR={pathlib.Path(semantic_release.__file__).resolve().parent}")' >> $GITHUB_OUTPUT
- name: Test | Run pytest -m e2e --comprehensive
id: tests
run: |
pytest \
-vv \
-nauto \
-m e2e \
--comprehensive \
--cov=${{ steps.install.outputs.PKG_INSTALLED_DIR }} \
--cov-context=test \
--cov-report=term-missing \
--cov-fail-under=70 \
--junit-xml=tests/reports/pytest-results.xml
- name: Report | Upload Cached Repos on Failure
uses: actions/upload-artifact@v4
if: ${{ failure() && steps.tests.outcome == 'failure' }}
with:
name: ${{ format('cached-repos-{0}-{1}', matrix.os, matrix.python-version) }}
path: .pytest_cache/d/psr-*
include-hidden-files: true
if-no-files-found: error
retention-days: 1
- name: Report | Upload Tested Repos on Failure
uses: actions/upload-artifact@v4
if: ${{ failure() && steps.tests.outcome == 'failure' }}
with:
name: ${{ format('tested-repos-{0}-{1}', matrix.os, matrix.python-version) }}
path: /tmp/pytest-of-runner/pytest-current/*
include-hidden-files: true
if-no-files-found: error
retention-days: 1
- name: Report | Upload Test Results
uses: mikepenz/[email protected]
if: ${{ always() && steps.tests.outcome != 'skipped' }}
with:
report_paths: ./tests/reports/*.xml
annotate_only: true
test-windows:
name: Python ${{ matrix.python-version }} on ${{ matrix.os }} E2E tests
runs-on: ${{ matrix.os }}
needs:
- build
- unit-test
if: ${{ inputs.src-files-changed == 'true' || inputs.test-files-changed == 'true' || inputs.ci-files-changed == 'true' }}
strategy:
matrix:
python-version: ${{ fromJson(inputs.python-versions-windows) }}
os: [windows-latest]
steps:
- name: Setup | Checkout Repository
uses: actions/[email protected]
with:
ref: ${{ github.sha }}
fetch-depth: 1
- name: Setup | Install Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'
- name: Setup | Download Distribution Artifacts
uses: actions/download-artifact@v4
with:
name: ${{ needs.build.outputs.distribution-artifacts }}
path: dist
- name: Setup | Install dependencies
id: install
# To ensure we are testing our installed package (not the src code), we must
# uninstall the editable install (symlink) first then install the distribution artifact.
# Lastly, we ask python to give us the installation location of our distribution artifact
# so that we can use it in the pytest command for coverage
shell: pwsh
run: |
$ErrorActionPreference = 'stop'
python -m pip install --upgrade pip setuptools wheel
pip install -e .[test]
pip install pytest-github-actions-annotate-failures
pip uninstall -y python-semantic-release
$psrWheelFile = Get-ChildItem dist\python_semantic_release-*.whl -File | Select-Object -Index 0
pip install "$psrWheelFile"
python -c 'import pathlib, semantic_release; print(f"PKG_INSTALLED_DIR={pathlib.Path(semantic_release.__file__).resolve().parent}")' | Tee-Object -Variable cmdOutput
echo $cmdOutput >> $env:GITHUB_OUTPUT
- name: Test | Run pytest -m e2e
id: tests
shell: pwsh
# env:
# Required for GitPython to work on Windows because of getpass.getuser()
# USERNAME: "runneradmin"
# Because GHA is currently broken on Windows to pass these varables, we do it manually
run: |
$env:USERNAME = "runneradmin"
pytest `
-vv `
-nauto `
-m e2e `
`--cov=${{ steps.install.outputs.PKG_INSTALLED_DIR }} `
`--cov-context=test `
`--cov-report=term-missing `
`--junit-xml=tests/reports/pytest-results.xml
- name: Report | Upload Cached Repos on Failure
uses: actions/upload-artifact@v4
if: ${{ failure() && steps.tests.outcome == 'failure' }}
with:
name: ${{ format('cached-repos-{0}-{1}', matrix.os, matrix.python-version) }}
path: .pytest_cache/d/psr-*
include-hidden-files: true
if-no-files-found: error
retention-days: 1
- name: Report | Upload Tested Repos on Failure
uses: actions/upload-artifact@v4
if: ${{ failure() && steps.tests.outcome == 'failure' }}
with:
name: ${{ format('tested-repos-{0}-{1}', matrix.os, matrix.python-version) }}
path: /tmp/pytest-of-runner/pytest-current/*
include-hidden-files: true
if-no-files-found: error
retention-days: 1
- name: Report | Upload Test Results
uses: mikepenz/[email protected]
if: ${{ always() && steps.tests.outcome != 'skipped' }}
with:
report_paths: ./tests/reports/*.xml
annotate_only: true
lint:
name: Lint
if: ${{ inputs.files-changed == 'true' }}
runs-on: ubuntu-latest
steps:
- name: Setup | Checkout Repository
uses: actions/[email protected]
with:
ref: ${{ github.sha }}
fetch-depth: 1
- name: Setup | Install Python ${{ env.COMMON_PYTHON_VERSION }}
uses: actions/setup-python@v5
with:
python-version: ${{ env.COMMON_PYTHON_VERSION }}
cache: 'pip'
- name: Setup | Install dependencies
run: |
python -m pip install --upgrade pip setuptools wheel
pip install -e .[dev,mypy]
- name: Lint | Ruff Evaluation
id: lint
run: |
ruff check \
--config pyproject.toml \
--output-format=full \
--exit-non-zero-on-fix
- name: Type-Check | MyPy Evaluation
id: type-check
if: ${{ always() && steps.lint.outcome != 'skipped' }}
run: |
mypy --ignore-missing-imports src/
- name: Format-Check | Ruff Evaluation
id: format-check
if: ${{ always() && steps.type-check.outcome != 'skipped' }}
run: |
ruff format --check --config pyproject.toml