-
Notifications
You must be signed in to change notification settings - Fork 0
501 lines (467 loc) · 16 KB
/
pipeline.yaml
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
493
494
495
496
497
498
499
500
501
name: Pipeline
on:
push:
branches-ignore:
- gh-pages
tags-ignore:
- docs-*
pull_request:
release:
types: [published]
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.ref_name }}
cancel-in-progress: true
env:
ON_CI: 1
jobs:
concurrency:
name: Show Concurrency Group
runs-on: ubuntu-latest
steps:
- name: Concurrency Group
run: |
echo "$CONCURRENCY_GROUP"
env:
CONCURRENCY_GROUP: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
changes:
name: Get Changed Files
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0 # OR "2" -> To retrieve the preceding commit.
- name: Get changed files in the src folder
id: src-changed
uses: tj-actions/changed-files@v40
with:
files: src/**
- name: List src changes
if: steps.src-changed.outputs.any_changed == 'true'
run: |
echo "One or more files in the src folder has changed."
echo "List all the files that have changed: ${{ steps.src-changed.outputs.all_changed_files }}"
- name: Get changed files in the tests folder
id: tests-changed
uses: tj-actions/changed-files@v40
with:
files: tests/**
- name: List tests changes
if: steps.tests-changed.outputs.any_changed == 'true'
run: |
echo "One or more files in the tests folder has changed."
echo "List all the files that have changed: ${{ steps.tests-changed.outputs.all_changed_files }}"
- name: Get changed files in the root folder
id: root-changed
uses: tj-actions/changed-files@v40
with:
files: |
*.{toml,ini}
tools/**
- name: List root changes
if: steps.root-changed.outputs.any_changed == 'true'
run: |
echo "One or more config files in the root folder has changed."
echo "List all the files that have changed: ${{ steps.root-changed.outputs.all_changed_files }}"
- name: Get changed files in the docs folder
id: docs-changed
uses: tj-actions/changed-files@v40
with:
files: docs/**
- name: List docs changes
if: steps.docs-changed.outputs.any_changed == 'true'
run: |
echo "One or more files in the docs folder has changed."
echo "List all the files that have changed: ${{ steps.docs-changed.outputs.all_changed_files }}"
- name: Get changed files in the workflows folder
id: workflows-changed
uses: tj-actions/changed-files@v40
with:
files: .github/workflows/**
- name: List workflows changes
if: steps.workflows-changed.outputs.any_changed == 'true'
run: |
echo "One or more files in the .github/workflows folder has changed."
echo "List all the files that have changed: ${{ steps.workflows-changed.outputs.all_changed_files }}"
- name: Get changed files in the .github folder
id: tools-changed
uses: tj-actions/changed-files@v40
with:
files: .github/*.{json,properties}
- name: List tools changes
if: steps.tools-changed.outputs.any_changed == 'true'
run: |
echo "One or more tool configurations in the .github folder has changed."
echo "List all the files that have changed: ${{ steps.tools-changed.outputs.all_changed_files }}"
outputs:
src: ${{ steps.src-changed.outputs.any_changed == 'true'}}
tests: ${{ steps.tests-changed.outputs.any_changed == 'true'}}
root: ${{ steps.root-changed.outputs.any_changed == 'true'}}
tools: ${{ steps.tools-changed.outputs.any_changed == 'true'}}
workflows: ${{ steps.workflows-changed.outputs.any_changed == 'true'}}
lint:
name: Lint (${{ github.event_name }})
runs-on: ubuntu-latest
needs:
- changes
if: >
(needs.changes.outputs.src || needs.changes.outputs.tools || needs.changes.outputs.root) ||
(github.event_name == 'pull_request' ) ||
(github.event_name == 'push' && (startsWith(github.ref, 'refs/tags') || contains(github.ref, 'main'))) ||
(github.event_name == 'release')
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install nox
- name: Lint
run: nox -t lint
test:
name: Test Python ${{ matrix.py }} - ${{ matrix.os }} (${{ github.event_name }})
runs-on: ${{ matrix.os }}-latest
needs:
- changes
if: >
(needs.changes.outputs.src || needs.changes.outputs.tests || needs.changes.outputs.root || needs.changes.outputs.workflows) ||
(github.event_name == 'pull_request' ) ||
(github.event_name == 'push' && (startsWith(github.ref, 'refs/tags') || contains(github.ref, 'main'))) ||
(github.event_name == 'release')
strategy:
fail-fast: false
matrix:
os:
- "ubuntu"
- "windows"
- "macos"
py:
- "3.8"
- "3.9"
- "3.10"
- "3.11"
- "3.12"
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.py }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.py }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -U nox "tomli;python_version<'3.11'"
- name: Run Test Suite
run: nox -t test -- unit functional
env:
GITHUB_TOKEN: ${{ github.token}}
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
directory: ./reports/
flags: tests
name: ${{ matrix.py }} - ${{ matrix.os }}
- name: Configure testspace
uses: testspace-com/setup-testspace@v1
with:
domain: ${{ github.repository_owner }}
if: always()
- name: Push result to Testspace server
run: |
testspace reports/*-test.xml
if: always()
sonarcloud:
name: SonarCloud (${{ github.event_name }})
runs-on: ubuntu-latest
needs:
- changes
if: >
(needs.changes.outputs.src || needs.changes.outputs.root || needs.changes.outputs.workflows) ||
(github.event_name == 'pull_request' ) ||
(github.event_name == 'push' && (startsWith(github.ref, 'refs/tags') || contains(github.ref, 'main'))) ||
(github.event_name == 'release')
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: SonarCloud Scan
uses: SonarSource/sonarcloud-github-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
with:
args: >
-Dsonar.projectKey=djpugh_mkdocs_github_changelog
-Dsonar.organization=djpugh
-Dsonar.coverage.exclusions=**/*.*
-Dsonar.sources=src
# No coverage as handled separately
license-scan:
name: Scan Licenses (${{ github.event_name }})
runs-on: ubuntu-latest
needs:
- changes
if: >
(needs.changes.outputs.root || needs.changes.outputs.workflows) ||
(github.event_name == 'pull_request' && contains(github.base_ref, 'main')) ||
(github.event_name == 'push' && (startsWith(github.ref, 'refs/tags') || contains(github.ref, 'main'))) ||
(github.event_name == 'release')
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: compile requirements.txt
run: |
python -m pip install --upgrade pip
pip install pip-tools pipenv
pip-compile -o requirements.txt
cat requirements.txt
- name: Run FOSSA scan and upload build data
uses: fossa-contrib/fossa-action@v3
with:
fossa-api-key: ${{ secrets.FOSSA_API_KEY }}
github-token: ${{ github.token }}
codeql-analyze:
name: CodeQL Analyze (${{ github.event_name }})
runs-on: ubuntu-latest
needs:
- changes
if: >
(needs.changes.outputs.src || needs.changes.outputs.root || needs.changes.outputs.workflows) ||
(github.event_name == 'pull_request' ) ||
(github.event_name == 'push' && (startsWith(github.ref, 'refs/tags') || contains(github.ref, 'main'))) ||
(github.event_name == 'release')
permissions:
actions: read
contents: read
security-events: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: python
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
build:
name: Build Package (${{ github.event_name }})
runs-on: ubuntu-latest
needs:
- changes
if: >
(needs.changes.outputs.src || needs.changes.outputs.root || needs.changes.outputs.workflows) ||
(github.event_name == 'pull_request' && contains(github.base_ref, 'main')) ||
(github.event_name == 'push' && (startsWith(github.ref, 'refs/tags') || contains(github.ref, 'main'))) ||
(github.event_name == 'release')
steps:
- uses: actions/checkout@v4
with:
clean: true
- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install nox
- name: Build mkdocs_github_changelog
run: nox -t build
- name: Store build artifact
uses: actions/upload-artifact@v4
with:
name: build
path: |
dist/*
docs:
name: Build docs (${{ github.event_name }})
needs:
- changes
if: >
(needs.changes.outputs.src || needs.changes.outputs.root || needs.changes.outputs.docs || needs.changes.outputs.workflows) ||
(github.event_name == 'pull_request' && contains(github.base_ref, 'main')) ||
(github.event_name == 'push' && (startsWith(github.ref, 'refs/tags') || contains(github.ref, 'main'))) ||
(github.event_name == 'release')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install nox
- name: Configure Git
run: |
git config user.name github-actions
git config user.email [email protected]
- name: Build docs
id: build_docs
run: nox -t docs
- name: Select Branch
run: git checkout ${{ steps.build_docs.outputs.branch_name}}
- name: Store Docs Artifact
uses: actions/upload-artifact@v4
with:
name: docs
path: |
.
test-build:
name: Test Build Python ${{ matrix.py }} - ${{ matrix.os }} (${{ github.event_name }})
needs:
- build
- test
if: >
(github.event_name == 'pull_request' && contains(github.base_ref, 'main')) ||
(github.event_name == 'push' && (startsWith(github.ref, 'refs/tags') || contains(github.ref, 'main'))) ||
(github.event_name == 'release')
runs-on: ${{ matrix.os }}-latest
strategy:
fail-fast: false
matrix:
os:
- "ubuntu"
- "windows"
- "macos"
py:
- "3.8"
- "3.9"
- "3.10"
- "3.11"
- "3.12"
steps:
- uses: actions/checkout@v4
with:
path: ./repo
- name: Set up Python ${{ matrix.py }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.py }}
- name: Download build
uses: actions/download-artifact@v4
with:
name: build
path: dist
- shell: bash
run: |
pip install $(ls -t dist/*.whl | head -n1)
- shell: bash
name: Install tomli
run: |
pip install tomli
- shell: python
name: Install test dependencies
run: |
import subprocess, tomli
subprocess.check_call(['pip', 'install']+tomli.load(open('./repo/pyproject.toml', 'rb'))['project']['optional-dependencies']['dev-test'])
- shell: bash
run: pytest ./repo/tests/unit
- shell: bash
run: pytest ./repo/tests/functional
env:
GITHUB_TOKEN: ${{ github.token}}
publish-package:
name: Publish Package
runs-on: ubuntu-latest
needs:
- lint
- test
- build
- sonarcloud
- license-scan
- codeql-analyze
- test-build
if: >
(github.event_name == 'push' && startsWith(github.ref, 'refs/tags') && !contains(github.ref, 'dev-')) ||
github.event_name == 'release'
environment:
name: pypi
url: https://pypi.org/p/mkdocs_github_changelog
permissions:
id-token: write
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Download build
uses: actions/download-artifact@v4
with:
name: build
path: dist
- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
publish-docs:
name: Publish Docs
runs-on: ubuntu-latest
needs:
- docs
- publish-package
# Only do this on the tagged build, not the release
if: >
(github.event_name == 'push' &&
startsWith(github.ref, 'refs/tags') && !(contains(github.ref, 'gh-pages') || contains(github.ref, 'docs') || contains(github.ref, 'dev-'))
)
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Get Version
id: get_version
# Cut is not zero indexed
# > cut: fields are numbered from 1
# > Try 'cut --help' for more information.
run: |
tag_name=$(echo ${{github.ref}} | cut -d/ -f2)
echo "tag_name=$tag_name" >> $GITHUB_OUTPUT
major=$(echo $tag_name | cut -d. -f1)
echo "major=$major" >> $GITHUB_OUTPUT
minor=$(echo $tag_name | cut -d. -f2)
echo "minor=$minor" >> $GITHUB_OUTPUT
patch=$(echo $tag_name | cut -d. -f3)
echo "patch=$patch" >> $GITHUB_OUTPUT
- name: Check Tag doesn't exist
id: check_tag
run: |
if git show-ref --tags docs-${{ steps.get_version.outputs.tag_name }} --quiet; then
echo "::set-output name=tag_exists::true"
echo "tag_exists=true" >> $GITHUB_OUTPUT
else
echo "tag_exists=false" >> $GITHUB_OUTPUT
fi
- shell: bash
name: Install tomli
run: |
pip install tomli
- shell: python
name: Install test dependencies
run: |
import subprocess, tomli
subprocess.check_call(['pip', 'install']+tomli.load(open('pyproject.toml', 'rb'))['project']['optional-dependencies']['dev-docs'])
- name: Deploy
run: |
git config user.name github-actions
git config user.email [email protected]
mike deploy -u "${{ steps.get_version.outputs.major }}.${{ steps.get_version.outputs.minor}}" latest --config-file docs/mkdocs.yml -p
mike set-default latest --config-file docs/mkdocs.yml
git checkout gh-pages
git pull origin
git tag docs-${{ steps.get_version.outputs.tag_name }}
git push origin docs-${{ steps.get_version.outputs.tag_name }}