Skip to content

Commit 919d796

Browse files
committed
ci: test --version after build
1 parent f1438fb commit 919d796

File tree

5 files changed

+153
-20
lines changed

5 files changed

+153
-20
lines changed

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
11
# Action that wraps together all the necessary actions to build an image and publish it.
22
# It does not include login actions.
33
# This is a convenience, so that we know that everything related to the build lies in this file,
4-
# and if it gets updated we can automatically run our `test-docker-build` from `build-test.yml.`
4+
# and if it gets updated we can automatically run our `test-docker-build` from `build-test.yml.`,
5+
# so there is no confusion about which is the job that was updated, if there are many in the same workflow file.
56

67
name: "Docker Build"
78
description: "Builds Docker images with optional caching and multi-platform support"
89

910
inputs:
10-
push-image:
11+
push:
1112
description: "Whether to push the built image"
1213
required: false
1314
default: "false"
15+
load:
16+
description: "Whether to load the built image"
17+
required: false
18+
default: "false"
1419
platforms:
1520
description: "Target platforms for the build"
1621
required: false
@@ -55,9 +60,10 @@ runs:
5560
with:
5661
context: ${{ inputs.context }}
5762
file: ${{ inputs.dockerfile }}
58-
push: ${{ inputs['push-image'] }}
63+
push: ${{ inputs.push }}
5964
platforms: ${{ inputs.platforms }}
6065
tags: ${{ steps.meta.outputs.tags }}
6166
labels: ${{ steps.meta.outputs.labels }}
6267
cache-from: ${{ inputs['cache-from'] }}
6368
cache-to: ${{ inputs['cache-to'] }}
69+
load: ${{ inputs.load }}

.github/workflows/build-test.yml

Lines changed: 51 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ on:
77
branches: ["main"]
88
pull_request:
99
branches: ["main"]
10-
10+
1111
jobs:
1212
test-build-package:
1313
name: Test package build
@@ -34,7 +34,7 @@ jobs:
3434
WHEEL_FILE=$(ls dist/*.whl | head -1)
3535
echo "Installing wheel: $WHEEL_FILE"
3636
uv pip install "$WHEEL_FILE"
37-
37+
3838
- name: Test twyn as a library
3939
run: uv run python -c "import twyn; twyn.check_dependencies"
4040

@@ -71,9 +71,9 @@ jobs:
7171
docker: ${{ steps.docker-changes.outputs.docker }}
7272
workflow: ${{ steps.docker-changes.outputs.workflow }}
7373

74-
test-docker-build:
74+
test-docker-build-arm64:
7575
needs: [should-test-docker-build]
76-
name: Test Docker build
76+
name: Test Docker build ARM64
7777
runs-on: ubuntu-latest
7878
if: (needs.should-test-docker-build.outputs.workflow == 'true' || needs.should-test-docker-build.outputs.docker == 'true') && !startsWith(github.event.head_commit.message, 'bump:')
7979
permissions:
@@ -96,6 +96,51 @@ jobs:
9696
context: .
9797
file: ./Dockerfile
9898
push: false
99-
platforms: linux/amd64,linux/arm64
99+
load: true
100+
platforms: linux/arm64
100101
cache-from: type=registry,ref=ghcr.io/elementsinteractive/twyn:buildcache
101-
102+
image-name: build-arm64
103+
104+
- name: Set up QEMU
105+
uses: docker/setup-qemu-action@v3
106+
with:
107+
platforms: arm64
108+
109+
- name: Test
110+
run: |
111+
docker run --platform linux/arm64 --rm build-arm64:pr-${{ github.event.pull_request.number }} --version
112+
113+
test-docker-build-amd64:
114+
needs: [should-test-docker-build]
115+
name: Test Docker build AMD64
116+
runs-on: ubuntu-latest
117+
if: (needs.should-test-docker-build.outputs.workflow == 'true' || needs.should-test-docker-build.outputs.docker == 'true') && !startsWith(github.event.head_commit.message, 'bump:')
118+
permissions:
119+
contents: read
120+
packages: read
121+
steps:
122+
- name: Check out the repo
123+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
124+
125+
- name: Log in to GitHub Container Registry
126+
uses: docker/login-action@184bdaa0721073962dff0199f1fb9940f07167d1 # v3.5.0
127+
with:
128+
registry: ghcr.io
129+
username: ${{ github.actor }}
130+
password: ${{ secrets.GITHUB_TOKEN }}
131+
132+
- name: Build image
133+
uses: ./.github/actions/docker-build
134+
with:
135+
context: .
136+
file: ./Dockerfile
137+
push: false
138+
load: true
139+
platforms: linux/amd64
140+
cache-from: type=registry,ref=ghcr.io/elementsinteractive/twyn:buildcache
141+
image-name: build-amd64
142+
143+
- name: Test
144+
run: |
145+
docker images
146+
docker run --platform linux/amd64 --rm build-amd64:pr-${{ github.event.pull_request.number }} --version

.github/workflows/publish.yml

Lines changed: 90 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,79 @@ jobs:
2727
uv build
2828
uv publish
2929
30-
push_to_docker_hub:
31-
name: Push Docker image to Docker Hub
30+
build_and_test_docker_amd64:
31+
name: Build and test Docker image (AMD64)
3232
runs-on: ubuntu-latest
33+
permissions:
34+
contents: read
35+
packages: write
36+
steps:
37+
- name: Check out the repo
38+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
39+
40+
- name: Log in to GitHub Container Registry
41+
uses: docker/login-action@184bdaa0721073962dff0199f1fb9940f07167d1 # v3.5.0
42+
with:
43+
registry: ghcr.io
44+
username: ${{ github.actor }}
45+
password: ${{ secrets.GITHUB_TOKEN }}
46+
47+
- name: Build Docker image (AMD64)
48+
uses: ./.github/actions/docker-build
49+
with:
50+
push: "false"
51+
platforms: linux/amd64
52+
dockerfile: ./Dockerfile
53+
context: .
54+
image-name: elementsinteractive/twyn
55+
cache-from: type=registry,ref=ghcr.io/elementsinteractive/twyn:buildcache-amd64
56+
cache-to: type=registry,ref=ghcr.io/elementsinteractive/twyn:buildcache-amd64,mode=max,compression=zstd,force-compression=true,oci-mediatypes=true
57+
58+
- name: Test Docker image (AMD64)
59+
run: |
60+
docker run --platform linux/amd64 --rm elementsinteractive/twyn:test-amd64 --version
61+
62+
build_and_test_docker_arm64:
63+
name: Build and test Docker image (ARM64)
64+
runs-on: ubuntu-latest
65+
permissions:
66+
contents: read
67+
packages: write
68+
steps:
69+
- name: Check out the repo
70+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
71+
72+
- name: Log in to GitHub Container Registry
73+
uses: docker/login-action@184bdaa0721073962dff0199f1fb9940f07167d1 # v3.5.0
74+
with:
75+
registry: ghcr.io
76+
username: ${{ github.actor }}
77+
password: ${{ secrets.GITHUB_TOKEN }}
78+
79+
- name: Build Docker image (ARM64)
80+
uses: ./.github/actions/docker-build
81+
with:
82+
push: "false"
83+
platforms: linux/arm64
84+
dockerfile: ./Dockerfile
85+
context: .
86+
image-name: elementsinteractive/twyn
87+
cache-from: type=registry,ref=ghcr.io/elementsinteractive/twyn:buildcache-arm64
88+
cache-to: type=registry,ref=ghcr.io/elementsinteractive/twyn:buildcache-arm64,mode=max,compression=zstd,force-compression=true,oci-mediatypes=true
89+
90+
- name: Set up QEMU
91+
uses: docker/setup-qemu-action@v3
92+
with:
93+
platforms: arm64
94+
95+
- name: Test Docker image (ARM64)
96+
run: |
97+
docker run --platform linux/arm64 --rm elementsinteractive/twyn:test-arm64 --version
98+
99+
publish_docker_images:
100+
name: Push Docker images to registries
101+
runs-on: ubuntu-latest
102+
needs: [build_and_test_docker_amd64, build_and_test_docker_arm64]
33103
permissions:
34104
contents: read
35105
packages: write
@@ -50,16 +120,25 @@ jobs:
50120
username: ${{ github.actor }}
51121
password: ${{ secrets.GITHUB_TOKEN }}
52122

53-
- name: Build and push Docker image
123+
- name: Push Docker image (AMD64)
54124
uses: ./.github/actions/docker-build
55125
with:
56-
push-image: "true"
57-
platforms: linux/amd64,linux/arm64
126+
push: "true"
127+
platforms: linux/amd64
58128
dockerfile: ./Dockerfile
59129
context: .
60130
image-name: elementsinteractive/twyn
61-
cache-from: type=registry,ref=ghcr.io/elementsinteractive/twyn:buildcache
62-
cache-to: type=registry,ref=ghcr.io/elementsinteractive/twyn:buildcache,mode=max,compression=zstd,force-compression=true,oci-mediatypes=true
131+
cache-from: type=registry,ref=ghcr.io/elementsinteractive/twyn:buildcache-amd64
132+
133+
- name: Push Docker image (ARM64)
134+
uses: ./.github/actions/docker-build
135+
with:
136+
push: "true"
137+
platforms: linux/arm64
138+
dockerfile: ./Dockerfile
139+
context: .
140+
image-name: elementsinteractive/twyn
141+
cache-from: type=registry,ref=ghcr.io/elementsinteractive/twyn:buildcache-arm64
63142

64143
- name: Delete old cache entries
65144
env:
@@ -68,17 +147,18 @@ jobs:
68147
# Get all versions of the container package
69148
versions=$(gh api "orgs/elementsinteractive/packages/container/twyn/versions" --paginate)
70149
71-
# Extract version IDs that do NOT have the 'buildcache' tag
72-
ids_to_delete=$(echo "$versions" | jq -r '.[] | select(.metadata.container.tags | index("buildcache") | not) | .id')
150+
# Extract version IDs that do NOT have any buildcache-* tags (buildcache-amd64, buildcache-arm64, etc.)
151+
ids_to_delete=$(echo "$versions" | jq -r '.[] | select(.metadata.container.tags | map(test("^buildcache-")) | any | not) | .id')
73152
74153
# Delete them
75154
for id in $ids_to_delete; do
76155
echo "Deleting old cache version ID: $id"
77156
gh api -X DELETE "orgs/elementsinteractive/packages/container/twyn/versions/$id"
78157
done
158+
79159
release_notes:
80160
runs-on: ubuntu-latest
81-
needs: [push_to_pypi, push_to_docker_hub]
161+
needs: [push_to_pypi, publish_docker_images]
82162
steps:
83163
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
84164
- name: Release

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ RUN ${BIN_PATH}/python -m ensurepip
4444
COPY uv.lock pyproject.toml ./
4545

4646
# Install dependencies using uv (only dependencies, not the project itself)
47-
RUN uv sync --inexact --frozen --all-extras --no-install-project --compile-bytecode
47+
RUN uv sync --inexact --frozen --all-extras --no-install-project --compile-bytecode
4848

4949
# --------------- `final` stage ---------------
5050
FROM base AS final

pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ download = [
6262
]
6363
local = ["ipdb<1.0.0,>=0.13.9", "commitizen<5.0,>=2.38", "pdbpp<1.0.0,>=0.11.6"]
6464

65+
[tool.uv]
66+
default-groups = []
6567

6668
[build-system]
6769
requires = ["hatchling"]

0 commit comments

Comments
 (0)