Skip to content

v0.3.0-cli

v0.3.0-cli #7

Workflow file for this run

name: Publish the GUI/CLI Docker Images
on:
release:
types: [published]
push:
tags:
- 'v*.*.*-gui'
- 'v*.*.*-cli'
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
build-and-push-image:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
attestations: write
id-token: write
steps:
- name: Checkout repository
uses: actions/checkout@v5
- name: Verify version matches release tag
run: |
TAG_VERSION=${GITHUB_REF#refs/tags/v}
TAG_VERSION=${TAG_VERSION%-*}
PYPROJECT_VERSION=$(grep '^version = ' pyproject.toml | cut -d'"' -f2)
if [ "$TAG_VERSION" != "$PYPROJECT_VERSION" ]; then
echo "Version mismatch! Release tag: v[$TAG_VERSION]-$SUFFIX, pyproject.toml: [$PYPROJECT_VERSION]"
echo "Please update pyproject.toml version to match the release tag."
exit 1
fi
SUFFIX=${GITHUB_REF##*-}
if [ "${{ github.event_name }}" = "release" ]; then
BRANCH="${{ github.event.release.target_commitish }}"
else
BRANCH="${{ github.ref_name }}"
fi
if [ "$SUFFIX" = "gui" ]; then
if [[ "$BRANCH" = "main" || "$BRANCH" == *"gui"* ]]; then
TARGET="gui"
else
echo "GUI tag must target 'main' or a branch containing 'gui', got: $BRANCH"
exit 1
fi
elif [ "$SUFFIX" = "cli" ]; then
if [[ "$BRANCH" == *"cli"* ]]; then
TARGET="base"
else
echo "CLI tag must target a branch containing 'cli', got: $BRANCH"
exit 1
fi
else
echo "Invalid tag suffix: $SUFFIX"
exit 1
fi
echo "TARGET=$TARGET" >> $GITHUB_ENV
echo "Version check passed: $TAG_VERSION"
- name: Log in to the Container registry
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=raw,value=${{ env.TARGET }}-latest
type=ref,event=tag
- name: Build and push image
uses: docker/build-push-action@v4
with:
context: .
file: Dockerfile
target: ${{ env.TARGET }}
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}