Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .github/actions/docker-build/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,23 @@ inputs:
description: "Cache destination for Docker build"
required: false
default: ""
setup-qemu:
description: "Whether to set up QEMU for multi-platform builds"
required: false
default: "false"

runs:
using: "composite"
steps:
- name: Checkout repository
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0

- name: Set up QEMU
if: inputs.setup-qemu == 'true'
uses: docker/setup-qemu-action@29109295f81e9208d7d86ff1c6c12d2833863392 # v3.6.0
with:
platforms: ${{ inputs.platforms }}

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 # v3.11.1

Expand Down
72 changes: 72 additions & 0 deletions .github/actions/python-package-build/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: "Python Package Build"
description: "Build Python package with uv, test it, and optionally publish"
author: "Elements Interactive"

inputs:
test-package:
description: "Whether to test the package (both library and CLI)"
required: false
default: "false"
cli-test-command:
description: "CLI command to test"
required: false
default: ""
publish:
description: "Whether to publish the package"
required: false
default: "false"
uv-version:
description: "Version of uv to use"
required: false
default: "latest"

outputs:
wheel-file:
description: "Path to the built wheel file"
value: ${{ steps.build.outputs.wheel-file }}
dist-path:
description: "Path to the dist directory"
value: ${{ steps.build.outputs.dist-path }}

runs:
using: "composite"
steps:
- name: Install uv
uses: astral-sh/setup-uv@b75a909f75acd358c2196fb9a5f1299a9a8868a4 # v6.7.0
with:
version: ${{ inputs.uv-version }}

- name: Build the package
id: build
shell: bash
run: |
uv build

# Set outputs
WHEEL_FILE=$(ls dist/*.whl | head -1)
echo "wheel-file=$WHEEL_FILE" >> $GITHUB_OUTPUT
echo "dist-path=dist" >> $GITHUB_OUTPUT
echo "Built wheel: $WHEEL_FILE"

- name: Install the built wheel
shell: bash
run: |
uv venv
uv pip install "${{ steps.build.outputs.wheel-file }}"

- name: Test package as CLI tool
if: inputs.test-package == 'true'
shell: bash
run: |
uv pip install "${{ steps.build.outputs.wheel-file }}[cli]"
uv run ${{ inputs.cli-test-command }}

- name: Publish package
if: inputs.publish == 'true'
shell: bash
run: |
uv publish

branding:
icon: "package"
color: "blue"
77 changes: 77 additions & 0 deletions .github/workflows/build-test-docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
name: Build and Test Docker Image

on:
pull_request:
branches: ["main"]
workflow_dispatch:

jobs:
should-test-docker-build:
permissions:
contents: read
pull-requests: read
name: Check if should `test_docker_build` run
runs-on: ubuntu-latest
steps:
- name: Check out the repo
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0

- name: Check if Dockerfile changed
uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 # v3.0.2
id: docker-changes
with:
filters: |
docker:
- 'Dockerfile'
- '.dockerignore'
workflow:
- ./.github/actions/docker-build/action.yml
outputs:
docker: ${{ steps.docker-changes.outputs.docker }}
workflow: ${{ steps.docker-changes.outputs.workflow }}

test-docker-build:
needs: [should-test-docker-build]
name: Test Docker build ${{ matrix.arch }}
runs-on: ubuntu-latest
if: (needs.should-test-docker-build.outputs.workflow == 'true' || needs.should-test-docker-build.outputs.docker == 'true')
permissions:
contents: read
packages: read
strategy:
matrix:
include:
- arch: amd64
platform: linux/amd64
image-name: build-amd64
needs-qemu: false
- arch: arm64
platform: linux/arm64
image-name: build-arm64
needs-qemu: true
steps:
- name: Check out the repo
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0

- name: Log in to GitHub Container Registry
uses: docker/login-action@184bdaa0721073962dff0199f1fb9940f07167d1 # v3.5.0
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build image
uses: ./.github/actions/docker-build
with:
context: .
file: ./Dockerfile
push: false
load: true
platforms: ${{ matrix.platform }}
cache-from: type=registry,ref=ghcr.io/elementsinteractive/twyn:buildcache-${{ matrix.arch }}
image-name: ${{ matrix.image-name }}
setup-qemu: ${{ matrix.needs-qemu }}

- name: Test
run: |
docker run --platform ${{ matrix.platform }} --rm ${{ matrix.image-name }}:pr-${{ github.event.pull_request.number }} --version
26 changes: 26 additions & 0 deletions .github/workflows/build-test-python.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# This workflow builds the package, installs it, and tests basic functionality

name: Build and Test Python Package

on:
pull_request:
branches: ["main"]
workflow_dispatch:

jobs:
test-build-package:
name: Test package build
runs-on: ubuntu-latest
permissions:
contents: read

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

- name: Test build package
uses: ./.github/actions/python-package-build
with:
test-package: "true"
uv-version: "0.8.22"
cli-test-command: "twyn --version"
122 changes: 0 additions & 122 deletions .github/workflows/build-test.yml

This file was deleted.

Loading
Loading