Skip to content

Commit 6489b6c

Browse files
committed
ci: refactor ci
1 parent 5bceb55 commit 6489b6c

File tree

6 files changed

+265
-141
lines changed

6 files changed

+265
-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: 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"
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: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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"

.github/workflows/build-test.yml

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

0 commit comments

Comments
 (0)