Skip to content

Commit 617f62d

Browse files
committed
ci: refactor ci
1 parent 5bceb55 commit 617f62d

File tree

4 files changed

+173
-57
lines changed

4 files changed

+173
-57
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,23 @@ inputs:
3939
description: "Cache destination for Docker build"
4040
required: false
4141
default: ""
42+
setup-qemu:
43+
description: "Whether to set up QEMU for multi-platform builds"
44+
required: false
45+
default: "false"
4246

4347
runs:
4448
using: "composite"
4549
steps:
4650
- name: Checkout repository
4751
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
4852

53+
- name: Set up QEMU
54+
if: inputs.setup-qemu == 'true'
55+
uses: docker/setup-qemu-action@29109295f81e9208d7d86ff1c6c12d2833863392 # v3.6.0
56+
with:
57+
platforms: ${{ inputs.platforms }}
58+
4959
- name: Set up Docker Buildx
5060
uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 # v3.11.1
5161

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
name: "Python Package Build"
2+
description: "Build Python package with uv, test it, and optionally publish"
3+
author: "Elements Interactive"
4+
5+
inputs:
6+
test-package:
7+
description: "Whether to test the package (both library and CLI)"
8+
required: false
9+
default: "true"
10+
library-test-command:
11+
description: "Command to test the library functionality"
12+
required: false
13+
default: "import twyn; twyn.check_dependencies()"
14+
cli-test-command:
15+
description: "CLI command to test"
16+
required: false
17+
default: "twyn --version"
18+
publish:
19+
description: "Whether to publish the package"
20+
required: false
21+
default: "false"
22+
publish-repository:
23+
description: "Repository to publish to (e.g., 'pypi', 'testpypi')"
24+
required: false
25+
default: "pypi"
26+
uv-version:
27+
description: "Version of uv to use"
28+
required: false
29+
default: "latest"
30+
31+
outputs:
32+
wheel-file:
33+
description: "Path to the built wheel file"
34+
value: ${{ steps.build.outputs.wheel-file }}
35+
dist-path:
36+
description: "Path to the dist directory"
37+
value: ${{ steps.build.outputs.dist-path }}
38+
39+
runs:
40+
using: "composite"
41+
steps:
42+
- name: Install uv
43+
uses: astral-sh/setup-uv@b75a909f75acd358c2196fb9a5f1299a9a8868a4 # v6.7.0
44+
with:
45+
version: ${{ inputs.uv-version }}
46+
47+
- name: Build the package
48+
id: build
49+
shell: bash
50+
run: |
51+
echo "Building package with uv..."
52+
uv build
53+
54+
# Set outputs
55+
WHEEL_FILE=$(ls dist/*.whl | head -1)
56+
echo "wheel-file=$WHEEL_FILE" >> $GITHUB_OUTPUT
57+
echo "dist-path=dist" >> $GITHUB_OUTPUT
58+
echo "Built wheel: $WHEEL_FILE"
59+
60+
- name: List built artifacts
61+
shell: bash
62+
run: ls -la dist/
63+
64+
- name: Install the built wheel
65+
shell: bash
66+
run: |
67+
uv venv
68+
# Find the wheel file and install it
69+
WHEEL_FILE=$(ls dist/*.whl | head -1)
70+
echo "Installing wheel: $WHEEL_FILE"
71+
uv pip install "$WHEEL_FILE"
72+
73+
- name: Test package as library
74+
if: inputs.test-package == 'true'
75+
shell: bash
76+
run: |
77+
echo "Testing package as library..."
78+
uv run python -c "${{ inputs.library-test-command }}"
79+
80+
- name: Test package as CLI tool
81+
if: inputs.test-package == 'true'
82+
shell: bash
83+
run: |
84+
echo "Testing package as CLI tool..."
85+
WHEEL_FILE=$(ls dist/*.whl | head -1)
86+
echo "Installing wheel: $WHEEL_FILE with cli extra"
87+
uv pip install "${WHEEL_FILE}[cli]"
88+
# Test that the CLI is available and works
89+
uv run ${{ inputs.cli-test-command }}
90+
91+
- name: Publish package
92+
if: inputs.publish == 'true'
93+
shell: bash
94+
run: |
95+
echo "Publishing package to ${{ inputs.publish-repository }}..."
96+
uv publish --repository ${{ inputs.publish-repository }}
97+
98+
branding:
99+
icon: "package"
100+
color: "blue"

.github/workflows/build-test.yml

Lines changed: 10 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -3,56 +3,32 @@
33
name: Build and Test Package
44

55
on:
6-
push:
7-
branches: ["main"]
86
pull_request:
97
branches: ["main"]
108

119
jobs:
1210
test-build-package:
1311
name: Test package build
1412
runs-on: ubuntu-latest
15-
if: "!startsWith(github.event.head_commit.message, 'bump:')"
13+
permissions:
14+
contents: read
1615

1716
steps:
1817
- name: Check out the repo
1918
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
2019

21-
- name: Install uv
22-
uses: astral-sh/setup-uv@b75a909f75acd358c2196fb9a5f1299a9a8868a4 # v6.7.0
23-
24-
- name: Build the package
25-
run: uv build
26-
27-
- name: List built artifacts
28-
run: ls -la dist/
29-
30-
- name: Install the built wheel
31-
run: |
32-
uv venv
33-
# Find the wheel file and install it
34-
WHEEL_FILE=$(ls dist/*.whl | head -1)
35-
echo "Installing wheel: $WHEEL_FILE"
36-
uv pip install "$WHEEL_FILE"
37-
38-
- name: Test twyn as a library
39-
run: uv run python -c "import twyn; twyn.check_dependencies"
40-
41-
- name: Test twyn as a cli tool
42-
run: |
43-
WHEEL_FILE=$(ls dist/*.whl | head -1)
44-
echo "Installing wheel: `$WHEEL_FILE` with `cli` extra."
45-
uv pip install "${WHEEL_FILE}[cli]"
46-
# Test that the CLI is available and --version works
47-
uv run twyn --version
20+
- name: Test build package
21+
uses: ./.github/actions/python-package-build
22+
with:
23+
test-package: "true"
24+
uv-version: "0.8.22"
4825

4926
should-test-docker-build:
5027
permissions:
5128
contents: read
5229
pull-requests: read
5330
name: Check if should `test_docker_build` run
5431
runs-on: ubuntu-latest
55-
if: "!startsWith(github.event.head_commit.message, 'bump:')"
5632
steps:
5733
- name: Check out the repo
5834
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
@@ -75,7 +51,7 @@ jobs:
7551
needs: [should-test-docker-build]
7652
name: Test Docker build ${{ matrix.arch }}
7753
runs-on: ubuntu-latest
78-
if: (needs.should-test-docker-build.outputs.workflow == 'true' || needs.should-test-docker-build.outputs.docker == 'true') && !startsWith(github.event.head_commit.message, 'bump:')
54+
if: (needs.should-test-docker-build.outputs.workflow == 'true' || needs.should-test-docker-build.outputs.docker == 'true')
7955
permissions:
8056
contents: read
8157
packages: read
@@ -85,6 +61,7 @@ jobs:
8561
- arch: amd64
8662
platform: linux/amd64
8763
image-name: build-amd64
64+
needs-qemu: false
8865
- arch: arm64
8966
platform: linux/arm64
9067
image-name: build-arm64
@@ -100,12 +77,6 @@ jobs:
10077
username: ${{ github.actor }}
10178
password: ${{ secrets.GITHUB_TOKEN }}
10279

103-
- name: Set up QEMU
104-
if: matrix.needs-qemu
105-
uses: docker/setup-qemu-action@29109295f81e9208d7d86ff1c6c12d2833863392 # v3.6.0
106-
with:
107-
platforms: ${{ matrix.platform }}
108-
10980
- name: Build image
11081
uses: ./.github/actions/docker-build
11182
with:
@@ -116,6 +87,7 @@ jobs:
11687
platforms: ${{ matrix.platform }}
11788
cache-from: type=registry,ref=ghcr.io/elementsinteractive/twyn:buildcache-${{ matrix.arch }}
11889
image-name: ${{ matrix.image-name }}
90+
setup-qemu: ${{ matrix.needs-qemu }}
11991

12092
- name: Test
12193
run: |

.github/workflows/publish.yml

Lines changed: 53 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,34 @@ on:
77
tags:
88
- "v*.*.*"
99

10-
permissions:
11-
contents: write
10+
env:
11+
UV_VERSION: "0.8.22"
1212

1313
jobs:
14-
push_to_pypi:
14+
build_and_test_package:
15+
name: Build and test package
1516
runs-on: ubuntu-latest
1617

1718
permissions:
18-
id-token: write
1919
contents: read
2020

2121
steps:
2222
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
23-
- name: Install uv
24-
uses: astral-sh/setup-uv@b75a909f75acd358c2196fb9a5f1299a9a8868a4 # v6.7.0
25-
- name: Publish to pypi
26-
run: |
27-
uv build
28-
uv publish
23+
24+
- name: Build and test package
25+
id: build-test
26+
uses: ./.github/actions/python-package-build
27+
with:
28+
test-package: "true"
29+
publish: "false"
30+
uv-version: ${{ env.UV_VERSION }}
31+
32+
- name: Upload package artifacts
33+
uses: actions/upload-artifact@50769540e7f4bd5e21e526ee35c689e35e0d6874 # v4.4.0
34+
with:
35+
name: python-package-${{ github.sha }}
36+
path: ${{ steps.build-test.outputs.dist-path }}
37+
retention-days: 1
2938

3039
build_and_test_docker:
3140
name: Build and test Docker image (${{ matrix.arch }})
@@ -39,6 +48,7 @@ jobs:
3948
- arch: amd64
4049
platform: linux/amd64
4150
cache-ref: buildcache-amd64
51+
needs-qemu: false
4252
- arch: arm64
4353
platform: linux/arm64
4454
cache-ref: buildcache-arm64
@@ -54,12 +64,6 @@ jobs:
5464
username: ${{ github.actor }}
5565
password: ${{ secrets.GITHUB_TOKEN }}
5666

57-
- name: Set up QEMU
58-
if: matrix.needs-qemu
59-
uses: docker/setup-qemu-action@29109295f81e9208d7d86ff1c6c12d2833863392 # v3.6.0
60-
with:
61-
platforms: ${{ matrix.arch }}
62-
6367
- name: Build Docker image (${{ matrix.arch }})
6468
uses: ./.github/actions/docker-build
6569
with:
@@ -71,15 +75,43 @@ jobs:
7175
image-name: elementsinteractive/twyn
7276
cache-from: type=registry,ref=ghcr.io/elementsinteractive/twyn:${{ matrix.cache-ref }}
7377
cache-to: type=registry,ref=ghcr.io/elementsinteractive/twyn:${{ matrix.cache-ref }},mode=max,compression=zstd,force-compression=true,oci-mediatypes=true
78+
setup-qemu: ${{ matrix.needs-qemu }}
7479

7580
- name: Test Docker image (${{ matrix.arch }})
7681
run: |
7782
docker run --platform ${{ matrix.platform }} --rm elementsinteractive/twyn --version
7883
79-
publish_docker_images:
84+
publish_to_pypi:
85+
name: Publish to PyPI
86+
runs-on: ubuntu-latest
87+
needs: [build_and_test_package, build_and_test_docker]
88+
89+
permissions:
90+
id-token: write
91+
contents: read
92+
93+
steps:
94+
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
95+
96+
- name: Download package artifacts
97+
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
98+
with:
99+
name: python-package-${{ github.sha }}
100+
path: dist
101+
102+
- name: Install uv
103+
uses: astral-sh/setup-uv@b75a909f75acd358c2196fb9a5f1299a9a8868a4 # v6.7.0
104+
with:
105+
version: ${{ env.UV_VERSION }}
106+
107+
- name: Publish package
108+
run: |
109+
uv publish
110+
111+
publish_to_dockerhub:
80112
name: Push Docker images to registries
81113
runs-on: ubuntu-latest
82-
needs: [build_and_test_docker]
114+
needs: [build_and_test_docker, build_and_test_package]
83115
permissions:
84116
contents: read
85117
packages: write
@@ -128,7 +160,9 @@ jobs:
128160
129161
release_notes:
130162
runs-on: ubuntu-latest
131-
needs: [push_to_pypi, publish_docker_images]
163+
needs: [publish_to_pypi, publish_to_dockerhub]
164+
permissions:
165+
contents: write
132166
steps:
133167
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
134168
- name: Release

0 commit comments

Comments
 (0)