Skip to content

Commit 1881c19

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

File tree

5 files changed

+113
-58
lines changed

5 files changed

+113
-58
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: 7 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,17 @@
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: false
9+
default: ""
810

911
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-
3712
test-docker-build:
38-
needs: [should-test-docker-build]
3913
name: Test Docker build ${{ matrix.arch }}
4014
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)
4215
permissions:
4316
contents: read
4417
packages: read
@@ -78,4 +51,4 @@ jobs:
7851

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

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

Lines changed: 44 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,43 @@ 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+
4165
- name: Test package
4266
run: |
4367
uv venv --python $PYTHON_VERSION
44-
uv pip install "${{ steps.build.outputs.wheel-file }}[${{ matrix.name }}]"
68+
WHEEL_FILE=$(ls dist/*.whl)
69+
uv pip install "$WHEEL_FILE[${{ matrix.name }}]"
4570
uv run ${{ matrix.test-args }}
4671
47-
test-build-package:
72+
test-build-package-no-extras:
4873
name: Test package build no extras
4974
runs-on: ubuntu-latest
75+
needs: build-package
5076
permissions:
5177
contents: read
5278
steps:
5379
- name: Check out the repo
5480
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
5581

56-
- name: Build package
57-
uses: ./.github/actions/python-package-build
58-
id: build
82+
- name: Download package artifact
83+
uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0
5984
with:
60-
uv-version: "0.8.22"
61-
python-version: "$PYTHON_VERSION"
85+
name: python-package-${{ github.sha }}
86+
path: dist/
87+
- name: Install uv
88+
uses: astral-sh/setup-uv@5a095e7a2014a4212f075830d4f7277575a9d098 # v7.3.1
89+
6290
- name: Test package
6391
run: |
6492
uv venv --python $PYTHON_VERSION
65-
uv pip install "${{ steps.build.outputs.wheel-file }}"
93+
WHEEL_FILE=$(ls dist/*.whl)
94+
uv pip install "$WHEEL_FILE"
6695
uv run python -c 'import twyn; twyn.check_dependencies()'

.github/workflows/publish.yml

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,36 @@ on:
44
push:
55
tags:
66
- "v*.*.*"
7+
pull_request:
8+
branches: ["main"]
9+
10+
env:
11+
PYTHON_VERSION: "3.10"
712

813
jobs:
14+
build_and_test_package:
15+
uses: ./.github/workflows/build-test-python.yml
16+
17+
build_and_test_docker:
18+
uses: ./.github/workflows/build-test-docker.yml
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
2331
with:
24-
uv-version: "0.8.22"
25-
python-version: "3.10"
32+
name: python-package-${{ github.sha }}
33+
path: dist
34+
35+
- name: Install uv
36+
uses: astral-sh/setup-uv@eac588ad8def6316056a12d4907a9d4d84ff7a3b # v7.3.0
2637

2738
- name: Publish package
2839
run: |
@@ -31,6 +42,7 @@ jobs:
3142
publish_to_dockerhub:
3243
name: Push Docker images to registries
3344
runs-on: ubuntu-latest
45+
needs: [build_and_test_docker, build_and_test_package]
3446
permissions:
3547
contents: read
3648
packages: write
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 }}"

0 commit comments

Comments
 (0)