Skip to content

Commit a7a72da

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

File tree

5 files changed

+110
-55
lines changed

5 files changed

+110
-55
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: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
name: Build and Test Docker Image
22

33
on:
4-
pull_request:
5-
branches: ["main"]
6-
push:
7-
branches: ["main"]
4+
# pull_request:
5+
# branches: ["main"]
6+
workflow_call:
7+
inputs:
8+
config:
9+
type: string
810

911
jobs:
1012
should-test-docker-build:

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

Lines changed: 49 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,42 @@
33
name: Build and Test Python Package
44

55
on:
6-
pull_request:
7-
branches: ["main"]
8-
push:
9-
branches: ["main"]
6+
# pull_request:
7+
# branches: ["main"]
8+
workflow_call:
9+
inputs:
10+
config:
11+
type: string
1012

1113
env:
1214
PYTHON_VERSION: "3.10"
1315

1416
jobs:
17+
build-package:
18+
name: Build Package
19+
runs-on: ubuntu-latest
20+
steps:
21+
- name: Check out the repo
22+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
23+
24+
- name: Build package
25+
uses: ./.github/actions/python-package-build
26+
id: build
27+
with:
28+
uv-version: "0.8.22"
29+
python-version: "$PYTHON_VERSION"
30+
31+
- name: Upload package artifact
32+
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0
33+
with:
34+
name: python-package-${{ github.sha }}
35+
path: dist/
36+
retention-days: 1
37+
1538
test-build-package-extras:
1639
name: Test package build ${{ matrix.name}}
1740
runs-on: ubuntu-latest
41+
needs: build-package
1842
permissions:
1943
contents: read
2044
strategy:
@@ -32,35 +56,43 @@ jobs:
3256
- name: Check out the repo
3357
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
3458

35-
- name: Build package
36-
uses: ./.github/actions/python-package-build
37-
id: build
59+
- name: Download package artifact
60+
uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0
3861
with:
39-
uv-version: "0.8.22"
40-
python-version: "$PYTHON_VERSION"
62+
name: python-package-${{ github.sha }}
63+
path: dist/
64+
65+
- name: Install uv
66+
uses: astral-sh/setup-uv@5a095e7a2014a4212f075830d4f7277575a9d098 # v7.3.1
67+
4168
- name: Test package
4269
run: |
4370
uv venv --python $PYTHON_VERSION
44-
uv pip install "${{ steps.build.outputs.wheel-file }}[${{ matrix.name }}]"
71+
WHEEL_FILE=$(ls dist/*.whl)
72+
uv pip install "$WHEEL_FILE[${{ matrix.name }}]"
4573
uv run ${{ matrix.test-args }}
4674
47-
test-build-package:
75+
test-build-package-no-extras:
4876
name: Test package build no extras
4977
runs-on: ubuntu-latest
78+
needs: build-package
5079
permissions:
5180
contents: read
5281
steps:
5382
- name: Check out the repo
5483
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
5584

56-
- name: Build package
57-
uses: ./.github/actions/python-package-build
58-
id: build
85+
- name: Download package artifact
86+
uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0
5987
with:
60-
uv-version: "0.8.22"
61-
python-version: "$PYTHON_VERSION"
88+
name: python-package-${{ github.sha }}
89+
path: dist/
90+
- name: Install uv
91+
uses: astral-sh/setup-uv@5a095e7a2014a4212f075830d4f7277575a9d098 # v7.3.1
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/publish.yml

Lines changed: 45 additions & 33 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
@@ -51,33 +63,33 @@ jobs:
5163
username: ${{ github.actor }}
5264
password: ${{ secrets.GITHUB_TOKEN }}
5365

54-
- name: Push Docker images
55-
uses: ./.github/actions/docker-build
56-
with:
57-
push: "true"
58-
platforms: linux/amd64,linux/arm64
59-
dockerfile: ./Dockerfile
60-
context: .
61-
image-name: elementsinteractive/twyn
62-
cache-from: |
63-
type=registry,ref=ghcr.io/elementsinteractive/twyn:buildcache-amd64
64-
type=registry,ref=ghcr.io/elementsinteractive/twyn:buildcache-arm64
65-
66-
- name: Delete old cache entries
67-
env:
68-
GH_TOKEN: ${{ github.token }}
69-
run: |
70-
# Get all versions of the container package
71-
versions=$(gh api "orgs/elementsinteractive/packages/container/twyn/versions" --paginate)
66+
# - name: Push Docker images
67+
# uses: ./.github/actions/docker-build
68+
# with:
69+
# push: "true"
70+
# platforms: linux/amd64,linux/arm64
71+
# dockerfile: ./Dockerfile
72+
# context: .
73+
# image-name: elementsinteractive/twyn
74+
# cache-from: |
75+
# type=registry,ref=ghcr.io/elementsinteractive/twyn:buildcache-amd64
76+
# type=registry,ref=ghcr.io/elementsinteractive/twyn:buildcache-arm64
77+
78+
# - name: Delete old cache entries
79+
# env:
80+
# GH_TOKEN: ${{ github.token }}
81+
# run: |
82+
# # Get all versions of the container package
83+
# versions=$(gh api "orgs/elementsinteractive/packages/container/twyn/versions" --paginate)
7284

73-
# Extract version IDs that do NOT have any buildcache-* tags (buildcache-amd64, buildcache-arm64, etc.)
74-
ids_to_delete=$(echo "$versions" | jq -r '.[] | select(.metadata.container.tags | map(test("^buildcache-")) | any | not) | .id')
85+
# # Extract version IDs that do NOT have any buildcache-* tags (buildcache-amd64, buildcache-arm64, etc.)
86+
# ids_to_delete=$(echo "$versions" | jq -r '.[] | select(.metadata.container.tags | map(test("^buildcache-")) | any | not) | .id')
7587

76-
# Delete them
77-
for id in $ids_to_delete; do
78-
echo "Deleting old cache version ID: $id"
79-
gh api -X DELETE "orgs/elementsinteractive/packages/container/twyn/versions/$id"
80-
done
88+
# # Delete them
89+
# for id in $ids_to_delete; do
90+
# echo "Deleting old cache version ID: $id"
91+
# gh api -X DELETE "orgs/elementsinteractive/packages/container/twyn/versions/$id"
92+
# done
8193

8294
release_notes:
8395
runs-on: ubuntu-latest

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)