Skip to content

Commit b6d27bc

Browse files
committed
ci: require to test python package and docker build before publishing
1 parent 00090ff commit b6d27bc

File tree

5 files changed

+73
-26
lines changed

5 files changed

+73
-26
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ inputs:
4444
required: false
4545
default: "false"
4646

47+
outputs:
48+
image-tag:
49+
description: "Tag of the built image"
50+
value: ${{ steps.meta.outputs.tags }}
51+
4752
runs:
4853
using: "composite"
4954
steps:
@@ -71,7 +76,7 @@ runs:
7176
type=semver,enable=true,pattern={{major}},prefix=v
7277
type=ref,event=pr,prefix=pr-,enable=true
7378
type=ref,event=branch,branch=main,pattern={{raw}}
74-
type=ref,event=branch,branch=main,pattern={{major}},prefix=v
79+
type=ref,event=branch,branch=main,pattern={{major}}
7580
7681
- name: Build Docker image
7782
uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6.18.0

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ name: Build and Test Docker Image
33
on:
44
pull_request:
55
branches: ["main"]
6-
push:
7-
branches: ["main"]
6+
workflow_call:
87

98
jobs:
109
should-test-docker-build:

.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: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,33 @@ 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+
918
publish_to_pypi:
1019
name: Publish to PyPI
1120
runs-on: ubuntu-latest
12-
21+
needs: [build_and_test_package, build_and_test_docker]
1322
permissions:
1423
id-token: write
15-
contents: read
16-
1724
steps:
1825
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
1926

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

2736
- name: Publish package
2837
run: |
@@ -31,6 +40,7 @@ jobs:
3140
publish_to_dockerhub:
3241
name: Push Docker images to registries
3342
runs-on: ubuntu-latest
43+
needs: [build_and_test_docker, build_and_test_package]
3444
permissions:
3545
contents: read
3646
packages: write

debug_regex.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import re
2+
namespace_pattern = re.compile(r"^(?:[a-z0-9]+(?:[._-][a-z0-9]+)*\/)[a-z0-9]+(?:[._-][a-z0-9]+)*$")
3+
package = "internal-registry.company.com/backend-team/alpine"
4+
print(namespace_pattern.match(package.lower()))

0 commit comments

Comments
 (0)