Skip to content

Commit bad8f50

Browse files
committed
Refactor build and test CI/CD jobs into reusable workflows
1 parent ffb765e commit bad8f50

File tree

3 files changed

+115
-87
lines changed

3 files changed

+115
-87
lines changed

.github/workflows/ci-cd.yml

Lines changed: 2 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -24,95 +24,10 @@ env:
2424

2525
jobs:
2626
build:
27-
name: Build distribution 📦
28-
runs-on: ubuntu-24.04
29-
timeout-minutes: 5
30-
31-
steps:
32-
- uses: actions/checkout@v4
33-
with:
34-
persist-credentials: false
35-
- name: Install uv
36-
# yamllint disable-line rule:line-length
37-
uses: astral-sh/setup-uv@c7f87aa956e4c323abf06d5dec078e358f6b4d04 # v6.0.0
38-
with:
39-
# yamllint disable-line rule:line-length
40-
enable-cache: | # zizmor: ignore[cache-poisoning] cache is disabled when publishing to prevent poisoning
41-
${{ github.ref_type == 'tag' && 'false' || 'auto' }}
42-
- name: Build distribution 📦
43-
run: uv build
44-
- name: Check distribution 📦
45-
run: uvx twine check --strict dist/*
46-
- name: Upload distribution 📦
47-
uses: actions/upload-artifact@v4
48-
with:
49-
name: python-package-distributions
50-
path: dist/
27+
uses: ./.github/workflows/reusable-build.yml
5128

5229
test:
53-
name: Test Python ${{ matrix.python-version }} on ${{ matrix.os }}
54-
runs-on: ${{ matrix.os }}
55-
continue-on-error: ${{ matrix.experimental }}
56-
strategy:
57-
matrix:
58-
python-version:
59-
- 3.8
60-
- 3.9
61-
- >-
62-
3.10
63-
- 3.11
64-
- 3.12
65-
- 3.13
66-
os:
67-
- ubuntu-24.04
68-
- ubuntu-24.04-arm
69-
include:
70-
- experimental: false
71-
- experimental: true # no reliable moto release available
72-
python-version: 3.8
73-
os: ubuntu-24.04-arm
74-
- upload-coverage: false
75-
- upload-coverage: true
76-
python-version: 3.11
77-
os: ubuntu-24.04
78-
fail-fast: false
79-
env:
80-
UV_FROZEN: 1
81-
timeout-minutes: 5
82-
83-
steps:
84-
- name: Checkout
85-
uses: actions/checkout@v4
86-
with:
87-
persist-credentials: false
88-
submodules: true
89-
- name: Install uv
90-
# yamllint disable-line rule:line-length
91-
uses: astral-sh/setup-uv@c7f87aa956e4c323abf06d5dec078e358f6b4d04 # v6.0.0
92-
with:
93-
python-version: ${{ matrix.python-version }}
94-
# yamllint disable-line rule:line-length
95-
enable-cache: | # zizmor: ignore[cache-poisoning] cache is disabled when publishing to prevent poisoning
96-
${{ github.ref_type == 'tag' && 'false' || 'auto' }}
97-
- name: Run pre-commit hooks
98-
run: |
99-
uv run make pre-commit
100-
- name: Run unittests
101-
env:
102-
COLOR: 'yes'
103-
run: |
104-
uv run make mototest
105-
- name: Upload coverage to Codecov
106-
if: ${{ matrix.upload-coverage }}
107-
# yamllint disable-line rule:line-length
108-
uses: codecov/codecov-action@ad3126e916f78f00edff4ed0317cf185271ccc2d # v5.4.2
109-
with:
110-
token: ${{ secrets.CODECOV_TOKEN }} # not required for public repos
111-
files: ./coverage.xml
112-
flags: unittests # optional
113-
name: codecov-umbrella # optional
114-
fail_ci_if_error: true # optional (default = false)
115-
verbose: true # optional (default = false)
30+
uses: ./.github/workflows/reusable-test.yml
11631

11732
zizmor:
11833
uses: ./.github/workflows/reusable-zizmor.yml

.github/workflows/reusable-build.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
---
2+
name: Reusable build
3+
4+
permissions: {}
5+
6+
on:
7+
workflow_call:
8+
9+
env:
10+
FORCE_COLOR: 1
11+
12+
jobs:
13+
build:
14+
name: Build distribution 📦
15+
runs-on: ubuntu-24.04
16+
timeout-minutes: 5
17+
18+
steps:
19+
- uses: actions/checkout@v4
20+
with:
21+
persist-credentials: false
22+
- name: Install uv
23+
# yamllint disable-line rule:line-length
24+
uses: astral-sh/setup-uv@c7f87aa956e4c323abf06d5dec078e358f6b4d04 # v6.0.0
25+
with:
26+
# yamllint disable-line rule:line-length
27+
enable-cache: | # zizmor: ignore[cache-poisoning] cache is disabled when publishing to prevent poisoning
28+
${{ github.ref_type == 'tag' && 'false' || 'auto' }}
29+
- name: Build distribution 📦
30+
run: uv build
31+
- name: Check distribution 📦
32+
run: uvx twine check --strict dist/*
33+
- name: Upload distribution 📦
34+
uses: actions/upload-artifact@v4
35+
with:
36+
name: python-package-distributions
37+
path: dist/

.github/workflows/reusable-test.yml

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
---
2+
name: Reusable test
3+
4+
permissions: {}
5+
6+
on:
7+
workflow_call:
8+
9+
env:
10+
FORCE_COLOR: 1
11+
12+
jobs:
13+
test:
14+
name: Test Python ${{ matrix.python-version }} on ${{ matrix.os }}
15+
runs-on: ${{ matrix.os }}
16+
continue-on-error: ${{ matrix.experimental }}
17+
strategy:
18+
matrix:
19+
python-version:
20+
- 3.8
21+
- 3.9
22+
- >-
23+
3.10
24+
- 3.11
25+
- 3.12
26+
- 3.13
27+
os:
28+
- ubuntu-24.04
29+
- ubuntu-24.04-arm
30+
include:
31+
- experimental: false
32+
- experimental: true # no reliable moto release available
33+
python-version: 3.8
34+
os: ubuntu-24.04-arm
35+
- upload-coverage: false
36+
- upload-coverage: true
37+
python-version: 3.11
38+
os: ubuntu-24.04
39+
fail-fast: false
40+
env:
41+
UV_FROZEN: 1
42+
timeout-minutes: 5
43+
44+
steps:
45+
- name: Checkout
46+
uses: actions/checkout@v4
47+
with:
48+
persist-credentials: false
49+
submodules: true
50+
- name: Install uv
51+
# yamllint disable-line rule:line-length
52+
uses: astral-sh/setup-uv@c7f87aa956e4c323abf06d5dec078e358f6b4d04 # v6.0.0
53+
with:
54+
python-version: ${{ matrix.python-version }}
55+
# yamllint disable-line rule:line-length
56+
enable-cache: | # zizmor: ignore[cache-poisoning] cache is disabled when publishing to prevent poisoning
57+
${{ github.ref_type == 'tag' && 'false' || 'auto' }}
58+
- name: Run pre-commit hooks
59+
run: |
60+
uv run make pre-commit
61+
- name: Run unittests
62+
env:
63+
COLOR: 'yes'
64+
run: |
65+
uv run make mototest
66+
- name: Upload coverage to Codecov
67+
if: ${{ matrix.upload-coverage }}
68+
# yamllint disable-line rule:line-length
69+
uses: codecov/codecov-action@ad3126e916f78f00edff4ed0317cf185271ccc2d # v5.4.2
70+
with:
71+
token: ${{ secrets.CODECOV_TOKEN }} # not required for public repos
72+
files: ./coverage.xml
73+
flags: unittests # optional
74+
name: codecov-umbrella # optional
75+
fail_ci_if_error: true # optional (default = false)
76+
verbose: true # optional (default = false)

0 commit comments

Comments
 (0)