Skip to content

Commit 073e960

Browse files
authored
ci: refactor ci (#353)
1 parent 5bceb55 commit 073e960

File tree

6 files changed

+239
-141
lines changed

6 files changed

+239
-141
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: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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: "false"
10+
cli-test-command:
11+
description: "CLI command to test"
12+
required: false
13+
default: ""
14+
publish:
15+
description: "Whether to publish the package"
16+
required: false
17+
default: "false"
18+
uv-version:
19+
description: "Version of uv to use"
20+
required: false
21+
default: "latest"
22+
23+
outputs:
24+
wheel-file:
25+
description: "Path to the built wheel file"
26+
value: ${{ steps.build.outputs.wheel-file }}
27+
dist-path:
28+
description: "Path to the dist directory"
29+
value: ${{ steps.build.outputs.dist-path }}
30+
31+
runs:
32+
using: "composite"
33+
steps:
34+
- name: Install uv
35+
uses: astral-sh/setup-uv@b75a909f75acd358c2196fb9a5f1299a9a8868a4 # v6.7.0
36+
with:
37+
version: ${{ inputs.uv-version }}
38+
39+
- name: Build the package
40+
id: build
41+
shell: bash
42+
run: |
43+
uv build
44+
45+
# Set outputs
46+
WHEEL_FILE=$(ls dist/*.whl | head -1)
47+
echo "wheel-file=$WHEEL_FILE" >> $GITHUB_OUTPUT
48+
echo "dist-path=dist" >> $GITHUB_OUTPUT
49+
echo "Built wheel: $WHEEL_FILE"
50+
51+
- name: Install the built wheel
52+
shell: bash
53+
run: |
54+
uv venv
55+
uv pip install "${{ steps.build.outputs.wheel-file }}"
56+
57+
- name: Test package as CLI tool
58+
if: inputs.test-package == 'true'
59+
shell: bash
60+
run: |
61+
uv pip install "${{ steps.build.outputs.wheel-file }}[cli]"
62+
uv run ${{ inputs.cli-test-command }}
63+
64+
- name: Publish package
65+
if: inputs.publish == 'true'
66+
shell: bash
67+
run: |
68+
uv publish
69+
70+
branding:
71+
icon: "package"
72+
color: "blue"
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
name: Build and Test Docker Image
2+
3+
on:
4+
pull_request:
5+
branches: ["main"]
6+
workflow_dispatch:
7+
8+
jobs:
9+
should-test-docker-build:
10+
permissions:
11+
contents: read
12+
pull-requests: read
13+
name: Check if should `test_docker_build` run
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Check out the repo
17+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
18+
19+
- name: Check if Dockerfile changed
20+
uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 # v3.0.2
21+
id: docker-changes
22+
with:
23+
filters: |
24+
docker:
25+
- 'Dockerfile'
26+
- '.dockerignore'
27+
workflow:
28+
- ./.github/actions/docker-build/action.yml
29+
outputs:
30+
docker: ${{ steps.docker-changes.outputs.docker }}
31+
workflow: ${{ steps.docker-changes.outputs.workflow }}
32+
33+
test-docker-build:
34+
needs: [should-test-docker-build]
35+
name: Test Docker build ${{ matrix.arch }}
36+
runs-on: ubuntu-latest
37+
if: (needs.should-test-docker-build.outputs.workflow == 'true' || needs.should-test-docker-build.outputs.docker == 'true')
38+
permissions:
39+
contents: read
40+
packages: read
41+
strategy:
42+
matrix:
43+
include:
44+
- arch: amd64
45+
platform: linux/amd64
46+
image-name: build-amd64
47+
needs-qemu: false
48+
- arch: arm64
49+
platform: linux/arm64
50+
image-name: build-arm64
51+
needs-qemu: true
52+
steps:
53+
- name: Check out the repo
54+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
55+
56+
- name: Log in to GitHub Container Registry
57+
uses: docker/login-action@184bdaa0721073962dff0199f1fb9940f07167d1 # v3.5.0
58+
with:
59+
registry: ghcr.io
60+
username: ${{ github.actor }}
61+
password: ${{ secrets.GITHUB_TOKEN }}
62+
63+
- name: Build image
64+
uses: ./.github/actions/docker-build
65+
with:
66+
context: .
67+
file: ./Dockerfile
68+
push: false
69+
load: true
70+
platforms: ${{ matrix.platform }}
71+
cache-from: type=registry,ref=ghcr.io/elementsinteractive/twyn:buildcache-${{ matrix.arch }}
72+
image-name: ${{ matrix.image-name }}
73+
setup-qemu: ${{ matrix.needs-qemu }}
74+
75+
- name: Test
76+
run: |
77+
docker run --platform ${{ matrix.platform }} --rm ${{ matrix.image-name }}:pr-${{ github.event.pull_request.number }} --version
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# This workflow builds the package, installs it, and tests basic functionality
2+
3+
name: Build and Test Python Package
4+
5+
on:
6+
pull_request:
7+
branches: ["main"]
8+
workflow_dispatch:
9+
10+
jobs:
11+
test-build-package:
12+
name: Test package build
13+
runs-on: ubuntu-latest
14+
permissions:
15+
contents: read
16+
17+
steps:
18+
- name: Check out the repo
19+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
20+
21+
- name: Test build package
22+
uses: ./.github/actions/python-package-build
23+
with:
24+
test-package: "true"
25+
uv-version: "0.8.22"
26+
cli-test-command: "twyn --version"

.github/workflows/build-test.yml

Lines changed: 0 additions & 122 deletions
This file was deleted.

0 commit comments

Comments
 (0)