Skip to content

Commit d2d8f2b

Browse files
authored
Refactor build and test CI/CD jobs into reusable workflows (#1345)
1 parent b786c2a commit d2d8f2b

File tree

3 files changed

+115
-63
lines changed

3 files changed

+115
-63
lines changed

.github/workflows/ci-cd.yml

Lines changed: 10 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -24,35 +24,9 @@ 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 }}
5630
strategy:
5731
matrix:
5832
python-version:
@@ -76,43 +50,16 @@ jobs:
7650
python-version: 3.11
7751
os: ubuntu-24.04
7852
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 }}
53+
uses: ./.github/workflows/reusable-test.yml
54+
with:
55+
python-version: ${{ matrix.python-version }}
56+
os: ${{ matrix.os }}
57+
continue-on-error: ${{ matrix.experimental }}
58+
enable-cache: ${{ github.ref_type == 'tag' && 'false' || 'auto' }}
59+
upload-coverage: ${{ matrix.upload-coverage }}
60+
secrets:
10761
# 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)
62+
codecov-token: ${{ matrix.upload-coverage && secrets.CODECOV_TOKEN || '' }}
11663

11764
zizmor:
11865
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: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
---
2+
name: Reusable test
3+
4+
permissions: {}
5+
6+
on:
7+
workflow_call:
8+
inputs:
9+
python-version:
10+
type: string
11+
required: true
12+
os:
13+
type: string
14+
required: true
15+
continue-on-error:
16+
type: boolean
17+
enable-cache:
18+
type: string
19+
required: true
20+
upload-coverage:
21+
type: boolean
22+
secrets:
23+
codecov-token:
24+
required: false
25+
26+
env:
27+
FORCE_COLOR: 1
28+
29+
jobs:
30+
test:
31+
name: Test Python ${{ inputs.python-version }} on ${{ inputs.os }}
32+
runs-on: ${{ inputs.os }}
33+
continue-on-error: ${{ inputs.continue-on-error }}
34+
env:
35+
UV_FROZEN: 1
36+
timeout-minutes: 5
37+
38+
steps:
39+
- name: Checkout
40+
uses: actions/checkout@v4
41+
with:
42+
persist-credentials: false
43+
submodules: true
44+
- name: Install uv
45+
# yamllint disable-line rule:line-length
46+
uses: astral-sh/setup-uv@c7f87aa956e4c323abf06d5dec078e358f6b4d04 # v6.0.0
47+
with:
48+
python-version: ${{ inputs.python-version }}
49+
enable-cache: ${{ inputs.enable-cache }}
50+
- name: Run pre-commit hooks
51+
run: |
52+
uv run make pre-commit
53+
- name: Run unittests
54+
env:
55+
COLOR: 'yes'
56+
run: |
57+
uv run make mototest
58+
- name: Upload coverage to Codecov
59+
if: ${{ inputs.upload-coverage }}
60+
# yamllint disable-line rule:line-length
61+
uses: codecov/codecov-action@ad3126e916f78f00edff4ed0317cf185271ccc2d # v5.4.2
62+
with:
63+
token: ${{ secrets.codecov-token }} # not required for public repos
64+
files: ./coverage.xml
65+
flags: unittests # optional
66+
name: codecov-umbrella # optional
67+
fail_ci_if_error: true # optional (default = false)
68+
verbose: true # optional (default = false)

0 commit comments

Comments
 (0)