This commit is contained in:
Timothy Jaeryang Baek committed 2026-06-06 10:54:27 +01:00
1 parent 209446617b
commit 69d416c909
21 files changed
+877 -191

No files matched your search

+50 -9
View File
@@ -5,6 +5,10 @@ on:
branches: [main]
workflow_dispatch:
concurrency:
group: docker-${{ github.ref }}
cancel-in-progress: false
env:
IMAGE: ghcr.io/${{ github.repository }}
@@ -14,6 +18,7 @@ permissions:
jobs:
detect-version-change:
if: github.ref == 'refs/heads/release'
runs-on: ubuntu-latest
outputs:
version_changed: ${{ steps.check.outputs.changed }}
@@ -58,9 +63,8 @@ jobs:
echo "No version change detected"
fi
build-and-push:
needs: detect-version-change
if: needs.detect-version-change.outputs.version_changed == 'true'
build-and-push-dev:
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
steps:
- name: Checkout
@@ -76,18 +80,55 @@ jobs:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels)
- name: Extract metadata (dev tags, labels)
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.IMAGE }}
tags: |
type=raw,value=latest
type=raw,value=${{ needs.detect-version-change.outputs.version }}
type=semver,pattern={{major}}.{{minor}},value=v${{ needs.detect-version-change.outputs.version }}
type=sha,prefix=
type=raw,value=dev
type=sha,prefix=dev-
- name: Build and push
- name: Build and push dev image
uses: docker/build-push-action@v6
with:
context: .
push: true
platforms: linux/amd64,linux/arm64
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
build-and-push-release:
needs: detect-version-change
if: github.ref == 'refs/heads/release' && needs.detect-version-change.outputs.version_changed == 'true'
runs-on: ubuntu-latest
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: Extract metadata (release tags, labels)
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.IMAGE }}
tags: |
type=raw,value=latest
type=raw,value=${{ needs.detect-version-change.outputs.version }}
type=semver,pattern={{major}}.{{minor}},value=v${{ needs.detect-version-change.outputs.version }}
- name: Build and push release image
uses: docker/build-push-action@v6
with:
context: .
+114
View File
@@ -0,0 +1,114 @@
name: Publish to PyPI
on:
pull_request:
types: [closed]
branches: [release]
permissions:
contents: read
jobs:
detect-version-change:
if: github.event.pull_request.merged == true && github.event.pull_request.head.ref == 'main'
runs-on: ubuntu-latest
outputs:
version_changed: ${{ steps.check.outputs.changed }}
version: ${{ steps.check.outputs.version }}
steps:
- name: Checkout current commit
uses: actions/checkout@v4
with:
fetch-depth: 2 # need parent to diff against
- name: Check for version bump
id: check
run: |
# Extract version from current commit
CURRENT=$(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))
")
# Extract version from previous commit
git show HEAD~1:pyproject.toml > /tmp/prev_pyproject.toml 2>/dev/null || true
if [ -f /tmp/prev_pyproject.toml ]; then
PREVIOUS=$(python3 -c "
import re, pathlib
text = pathlib.Path('/tmp/prev_pyproject.toml').read_text()
m = re.search(r'^version\s*=\s*\"([^\"]+)\"', text, re.M)
print(m.group(1) if m else '')
")
else
PREVIOUS=""
fi
echo "current=$CURRENT"
echo "previous=$PREVIOUS"
if [ "$CURRENT" != "$PREVIOUS" ] && [ -n "$CURRENT" ]; then
echo "changed=true" >> "$GITHUB_OUTPUT"
echo "version=$CURRENT" >> "$GITHUB_OUTPUT"
echo "Version changed: $PREVIOUS -> $CURRENT"
else
echo "changed=false" >> "$GITHUB_OUTPUT"
echo "No version change detected"
fi
build:
needs: detect-version-change
if: needs.detect-version-change.outputs.version_changed == 'true'
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: "22"
cache: npm
cache-dependency-path: cptr/frontend/package-lock.json
- name: Build frontend
working-directory: cptr/frontend
run: |
npm ci
npm run build
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install build tools
run: pip install hatchling build
- name: Build package
run: python -m build
- name: Upload dist artifacts
uses: actions/upload-artifact@v4
with:
name: dist
path: dist/
publish:
needs: [detect-version-change, build]
runs-on: ubuntu-latest
environment: pypi # GitHub environment for deployment protection
permissions:
id-token: write # required for trusted publishing (OIDC)
steps:
- name: Download dist artifacts
uses: actions/download-artifact@v4
with:
name: dist
path: dist/
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
# No API token needed - uses OIDC trusted publishing.
# Configure at: https://pypi.org/manage/project/cptr/settings/publishing/
+104
View File
@@ -0,0 +1,104 @@
# ─────────────────────────────────────────────────────────────────────────────
# Release — Create GitHub release from CHANGELOG, trigger Docker builds
# Runs only when main is merged into the release branch and pyproject.toml
# version changes.
# ─────────────────────────────────────────────────────────────────────────────
name: Release
on:
pull_request:
types: [closed]
branches: [release]
concurrency:
group: release-${{ github.event.pull_request.base.ref || github.ref }}
cancel-in-progress: false
jobs:
# ── Detect version bump in pyproject.toml ─────────────────────────────────
detect-version-change:
if: github.event.pull_request.merged == true && github.event.pull_request.head.ref == 'main'
runs-on: ubuntu-latest
outputs:
version_changed: ${{ steps.check.outputs.changed }}
version: ${{ steps.check.outputs.version }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 2
- name: Check for version bump
id: check
run: |
CURRENT=$(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))
")
git show HEAD~1:pyproject.toml > /tmp/prev_pyproject.toml 2>/dev/null || true
if [ -f /tmp/prev_pyproject.toml ]; then
PREVIOUS=$(python3 -c "
import re, pathlib
text = pathlib.Path('/tmp/prev_pyproject.toml').read_text()
m = re.search(r'^version\s*=\s*\"([^\"]+)\"', text, re.M)
print(m.group(1) if m else '')
")
else
PREVIOUS=""
fi
echo "current=$CURRENT"
echo "previous=$PREVIOUS"
if [ "$CURRENT" != "$PREVIOUS" ] && [ -n "$CURRENT" ]; then
echo "changed=true" >> "$GITHUB_OUTPUT"
echo "version=$CURRENT" >> "$GITHUB_OUTPUT"
echo "Version changed: $PREVIOUS -> $CURRENT"
else
echo "changed=false" >> "$GITHUB_OUTPUT"
echo "No version change detected"
fi
# ── Create release and trigger downstream workflows ──────────────────────
publish:
needs: detect-version-change
if: needs.detect-version-change.outputs.version_changed == 'true'
runs-on: ubuntu-latest
timeout-minutes: 10
permissions:
contents: write
actions: write
steps:
- uses: actions/checkout@v4
- name: Extract release notes from CHANGELOG
run: |
VER="${{ needs.detect-version-change.outputs.version }}"
awk "/^## \[${VER}\]/{found=1; next} /^## \[/{if(found) exit} found{print}" \
CHANGELOG.md > /tmp/release-notes.md
- name: Publish GitHub release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
if gh release view "v${{ needs.detect-version-change.outputs.version }}" &>/dev/null; then
echo "Release v${{ needs.detect-version-change.outputs.version }} already exists — skipping creation"
else
gh release create "v${{ needs.detect-version-change.outputs.version }}" \
--title "v${{ needs.detect-version-change.outputs.version }}" \
--notes-file /tmp/release-notes.md
fi
- name: Trigger Docker build
uses: actions/github-script@v7
with:
script: |
github.rest.actions.createWorkflowDispatch({
owner: context.repo.owner,
repo: context.repo.repo,
workflow_id: 'docker.yml',
ref: 'release',
})