Skip to content

refac

refac #31

Workflow file for this run

name: Docker (GHCR)
on:
push:
branches: [main, release]
workflow_dispatch:
concurrency:
group: docker-${{ github.ref }}
cancel-in-progress: true
env:
IMAGE: ghcr.io/${{ github.repository }}
permissions:
contents: read
packages: write
jobs:
# ── Read version from pyproject.toml (release builds only) ─────────────────
read-version:
if: github.ref == 'refs/heads/release'
runs-on: ubuntu-latest
outputs:
version: ${{ steps.pkg.outputs.version }}
steps:
- uses: actions/checkout@v4
- name: Read version
id: pkg
run: |
VERSION=$(python3 -c "
import re, pathlib
text = pathlib.Path('pyproject.toml').read_text()
m = re.search(r'^version\s*=\s*\"([^\"]+)\"', text, re.M)
print(m.group(1))
")
echo "version=$VERSION" >> $GITHUB_OUTPUT
# ── Dev builds (main branch) ──────────────────────────────────────────────
build-dev:
if: github.ref == 'refs/heads/main'
strategy:
fail-fast: false
matrix:
include:
- platform: linux/amd64
runner: ubuntu-latest
arch: amd64
- platform: linux/arm64
runner: ubuntu-24.04-arm
arch: arm64
runs-on: ${{ matrix.runner }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push ${{ matrix.platform }} dev image by digest
id: build
uses: docker/build-push-action@v6
with:
context: .
platforms: ${{ matrix.platform }}
outputs: type=image,name=${{ env.IMAGE }},push-by-digest=true,name-canonical=true,push=true
cache-from: type=gha,scope=dev-${{ matrix.arch }}
cache-to: type=gha,mode=max,scope=dev-${{ matrix.arch }}
- name: Export digest
run: |
mkdir -p /tmp/digests
digest="${{ steps.build.outputs.digest }}"
touch "/tmp/digests/${digest#sha256:}"
- name: Upload digest
uses: actions/upload-artifact@v4
with:
name: digests-dev-${{ matrix.arch }}
path: /tmp/digests/*
if-no-files-found: error
retention-days: 1
merge-dev:
if: github.ref == 'refs/heads/main'
needs: build-dev
runs-on: ubuntu-latest
steps:
- name: Download digests
uses: actions/download-artifact@v4
with:
path: /tmp/digests
pattern: digests-dev-*
merge-multiple: true
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Create dev multi-arch manifest
working-directory: /tmp/digests
run: |
SHORT_SHA="${GITHUB_SHA::7}"
docker buildx imagetools create \
-t "${{ env.IMAGE }}:dev" \
-t "${{ env.IMAGE }}:dev-${SHORT_SHA}" \
$(printf '${{ env.IMAGE }}@sha256:%s ' *)
# ── Release builds (release branch) ───────────────────────────────────────
build-release:
needs: read-version
if: github.ref == 'refs/heads/release'
strategy:
fail-fast: false
matrix:
include:
- platform: linux/amd64
runner: ubuntu-latest
arch: amd64
- platform: linux/arm64
runner: ubuntu-24.04-arm
arch: arm64
runs-on: ${{ matrix.runner }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push ${{ matrix.platform }} release image by digest
id: build
uses: docker/build-push-action@v6
with:
context: .
platforms: ${{ matrix.platform }}
outputs: type=image,name=${{ env.IMAGE }},push-by-digest=true,name-canonical=true,push=true
cache-from: type=gha,scope=release-${{ matrix.arch }}
cache-to: type=gha,mode=max,scope=release-${{ matrix.arch }}
- name: Export digest
run: |
mkdir -p /tmp/digests
digest="${{ steps.build.outputs.digest }}"
touch "/tmp/digests/${digest#sha256:}"
- name: Upload digest
uses: actions/upload-artifact@v4
with:
name: digests-release-${{ matrix.arch }}
path: /tmp/digests/*
if-no-files-found: error
retention-days: 1
merge-release:
needs: [read-version, build-release]
if: github.ref == 'refs/heads/release'
runs-on: ubuntu-latest
steps:
- name: Download digests
uses: actions/download-artifact@v4
with:
path: /tmp/digests
pattern: digests-release-*
merge-multiple: true
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Create release multi-arch manifest
working-directory: /tmp/digests
run: |
VERSION="${{ needs.read-version.outputs.version }}"
MAJOR_MINOR="${VERSION%.*}"
docker buildx imagetools create \
-t "${{ env.IMAGE }}:latest" \
-t "${{ env.IMAGE }}:${VERSION}" \
-t "${{ env.IMAGE }}:${MAJOR_MINOR}" \
$(printf '${{ env.IMAGE }}@sha256:%s ' *)