Skip to content

Commit a88967c

Browse files
committed
ci: require to test python package and docker build before publishing
1 parent bfd69f3 commit a88967c

File tree

9 files changed

+127
-59
lines changed

9 files changed

+127
-59
lines changed

.github/actions/docker-build/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ runs:
7171
type=semver,enable=true,pattern={{major}},prefix=v
7272
type=ref,event=pr,prefix=pr-,enable=true
7373
type=ref,event=branch,branch=main,pattern={{raw}}
74-
type=ref,event=branch,branch=main,pattern={{major}},prefix=v
74+
type=ref,event=branch,branch=main,pattern={{major}}
7575
7676
- name: Build Docker image
7777
uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6.18.0
Lines changed: 6 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,16 @@
11
name: Build and Test Docker Image
22

33
on:
4-
pull_request:
5-
branches: ["main"]
6-
push:
7-
branches: ["main"]
4+
workflow_call:
5+
inputs:
6+
image-tag:
7+
type: string
8+
required: true
89

910
jobs:
10-
should-test-docker-build:
11-
permissions:
12-
contents: read
13-
pull-requests: read
14-
name: Check if should `test_docker_build` run
15-
runs-on: ubuntu-latest
16-
steps:
17-
- name: Check out the repo
18-
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
19-
with:
20-
persist-credentials: false
21-
22-
- name: Check if Dockerfile changed
23-
uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 # v3.0.2
24-
id: docker-changes
25-
with:
26-
filters: |
27-
docker:
28-
- 'Dockerfile'
29-
- '.dockerignore'
30-
workflow:
31-
- ./.github/actions/docker-build/action.yml
32-
- ./.github/workflows/build-test-docker.yml
33-
outputs:
34-
docker: ${{ steps.docker-changes.outputs.docker }}
35-
workflow: ${{ steps.docker-changes.outputs.workflow }}
36-
3711
test-docker-build:
38-
needs: [should-test-docker-build]
3912
name: Test Docker build ${{ matrix.arch }}
4013
runs-on: ubuntu-latest
41-
if: (needs.should-test-docker-build.outputs.workflow == 'true' || needs.should-test-docker-build.outputs.docker == 'true') || (github.ref_name == github.event.repository.default_branch)
4214
permissions:
4315
contents: read
4416
packages: read
@@ -78,4 +50,4 @@ jobs:
7850

7951
- name: Test
8052
run: |
81-
docker run --platform ${{ matrix.platform }} --rm ${{ matrix.image-name }}:pr-${{ github.event.pull_request.number }} --version
53+
docker run --platform ${{ matrix.platform }} --rm ${{ matrix.image-name }}:${{ inputs.image-tag }} --version

.github/workflows/build-test-python.yml

Lines changed: 47 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,37 @@ name: Build and Test Python Package
55
on:
66
pull_request:
77
branches: ["main"]
8-
push:
9-
branches: ["main"]
8+
workflow_call:
109

1110
env:
1211
PYTHON_VERSION: "3.10"
1312

1413
jobs:
14+
build-package:
15+
name: Build Package
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: Check out the repo
19+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
20+
21+
- name: Build package
22+
uses: ./.github/actions/python-package-build
23+
id: build
24+
with:
25+
uv-version: "0.8.22"
26+
python-version: "$PYTHON_VERSION"
27+
28+
- name: Upload package artifact
29+
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0
30+
with:
31+
name: python-package-${{ github.sha }}
32+
path: dist/
33+
retention-days: 1
34+
1535
test-build-package-extras:
1636
name: Test package build ${{ matrix.name}}
1737
runs-on: ubuntu-latest
38+
needs: build-package
1839
permissions:
1940
contents: read
2041
strategy:
@@ -32,35 +53,46 @@ jobs:
3253
- name: Check out the repo
3354
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
3455

35-
- name: Build package
36-
uses: ./.github/actions/python-package-build
37-
id: build
56+
- name: Download package artifact
57+
uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0
3858
with:
39-
uv-version: "0.8.22"
40-
python-version: "$PYTHON_VERSION"
59+
name: python-package-${{ github.sha }}
60+
path: dist/
61+
62+
- name: Install uv
63+
uses: astral-sh/setup-uv@5a095e7a2014a4212f075830d4f7277575a9d098 # v7.3.1
64+
with:
65+
version: "0.8.22"
4166
- name: Test package
4267
run: |
4368
uv venv --python $PYTHON_VERSION
44-
uv pip install "${{ steps.build.outputs.wheel-file }}[${{ matrix.name }}]"
69+
WHEEL_FILE=$(ls dist/*.whl)
70+
uv pip install "$WHEEL_FILE[${{ matrix.name }}]"
4571
uv run ${{ matrix.test-args }}
4672
47-
test-build-package:
73+
test-build-package-no-extras:
4874
name: Test package build no extras
4975
runs-on: ubuntu-latest
76+
needs: build-package
5077
permissions:
5178
contents: read
5279
steps:
5380
- name: Check out the repo
5481
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
5582

56-
- name: Build package
57-
uses: ./.github/actions/python-package-build
58-
id: build
83+
- name: Download package artifact
84+
uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0
5985
with:
60-
uv-version: "0.8.22"
61-
python-version: "$PYTHON_VERSION"
86+
name: python-package-${{ github.sha }}
87+
path: dist/
88+
- name: Install uv
89+
uses: astral-sh/setup-uv@5a095e7a2014a4212f075830d4f7277575a9d098 # v7.3.1
90+
with:
91+
version: "0.8.22"
92+
6293
- name: Test package
6394
run: |
6495
uv venv --python $PYTHON_VERSION
65-
uv pip install "${{ steps.build.outputs.wheel-file }}"
96+
WHEEL_FILE=$(ls dist/*.whl)
97+
uv pip install "$WHEEL_FILE"
6698
uv run python -c 'import twyn; twyn.check_dependencies()'

.github/workflows/lint.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ jobs:
1717

1818
- name: Install uv
1919
uses: astral-sh/setup-uv@5a095e7a2014a4212f075830d4f7277575a9d098 # v7.3.1
20-
20+
with:
21+
version: "0.8.22"
2122
- name: Install the project
2223
run: uv sync --locked --group dev --python 3.10
2324

.github/workflows/publish.yml

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,37 @@ on:
55
tags:
66
- "v*.*.*"
77

8+
env:
9+
PYTHON_VERSION: "3.10"
10+
811
jobs:
12+
build_and_test_package:
13+
uses: ./.github/workflows/build-test-python.yml
14+
15+
build_and_test_docker:
16+
uses: ./.github/workflows/build-test-docker.yml
17+
with:
18+
image-tag: latest
19+
920
publish_to_pypi:
1021
name: Publish to PyPI
1122
runs-on: ubuntu-latest
12-
23+
needs: [build_and_test_package, build_and_test_docker]
1324
permissions:
1425
id-token: write
15-
contents: read
16-
1726
steps:
1827
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
1928

20-
- name: Build package
21-
uses: ./.github/actions/python-package-build
22-
id: build
29+
- name: Download package artifacts
30+
uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0
31+
with:
32+
name: python-package-${{ github.sha }}
33+
path: dist
34+
35+
- name: Install uv
36+
uses: astral-sh/setup-uv@eac588ad8def6316056a12d4907a9d4d84ff7a3b # v7.3.0
2337
with:
24-
uv-version: "0.8.22"
25-
python-version: "3.10"
38+
version: "0.8.22"
2639

2740
- name: Publish package
2841
run: |
@@ -31,6 +44,7 @@ jobs:
3144
publish_to_dockerhub:
3245
name: Push Docker images to registries
3346
runs-on: ubuntu-latest
47+
needs: [build_and_test_docker, build_and_test_package]
3448
permissions:
3549
contents: read
3650
packages: write

.github/workflows/security.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ jobs:
3939

4040
- name: Install uv
4141
uses: astral-sh/setup-uv@5a095e7a2014a4212f075830d4f7277575a9d098 # v7.3.1
42+
with:
43+
version: "0.8.22"
4244

4345
- name: Install the project
4446
run: uv sync --locked --extra cli

.github/workflows/test.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ jobs:
2121

2222
- name: Install uv
2323
uses: astral-sh/setup-uv@5a095e7a2014a4212f075830d4f7277575a9d098 # v7.3.1
24+
with:
25+
version: "0.8.22"
2426

2527
- name: Install the dependencies
2628
run: uv sync --locked --group dev --all-extras --python ${{ matrix.python-version }}
@@ -36,6 +38,8 @@ jobs:
3638

3739
- name: Install uv
3840
uses: astral-sh/setup-uv@5a095e7a2014a4212f075830d4f7277575a9d098 # v7.3.1
41+
with:
42+
version: "0.8.22"
3943

4044
- name: Install the dependencies
4145
run: uv sync --locked --group download --group dev --python 3.14
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: Build and Test Docker Image
2+
3+
on:
4+
pull_request:
5+
branches: ["main"]
6+
7+
jobs:
8+
should-test-docker-build:
9+
permissions:
10+
contents: read
11+
pull-requests: read
12+
name: Check if `test_docker_build` should run
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Check out the repo
16+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
17+
with:
18+
persist-credentials: false
19+
20+
- name: Check if Dockerfile or docker-build action have changed
21+
uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 # v3.0.2
22+
id: docker-changes
23+
with:
24+
filters: |
25+
docker:
26+
- 'Dockerfile'
27+
- '.dockerignore'
28+
workflow:
29+
- ./.github/actions/docker-build/action.yml
30+
- ./.github/workflows/build-test-docker.yml
31+
outputs:
32+
docker: ${{ steps.docker-changes.outputs.docker }}
33+
workflow: ${{ steps.docker-changes.outputs.workflow }}
34+
35+
trigger-test-docker-build:
36+
needs: [should-test-docker-build]
37+
name: Trigger test Docker build
38+
if: (needs.should-test-docker-build.outputs.workflow == 'true' || needs.should-test-docker-build.outputs.docker == 'true')
39+
uses: ./.github/workflows/build-test-docker.yml
40+
with:
41+
image-tag: "pr-${{ github.event.pull_request.number }}"

.github/workflows/weekly_download.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ jobs:
2727
ref: ${{ github.head_ref }}
2828
- name: Install uv
2929
uses: astral-sh/setup-uv@5a095e7a2014a4212f075830d4f7277575a9d098 # v7.3.1
30+
with:
31+
version: "0.8.22"
3032

3133
- name: Install the project
3234
run: uv sync --locked --only-group download --python 3.14

0 commit comments

Comments
 (0)