Skip to content

Commit 8042d7e

Browse files
ci: trigger publish action on tag/release
1 parent 0593a7e commit 8042d7e

File tree

2 files changed

+51
-24
lines changed

2 files changed

+51
-24
lines changed

.github/workflows/publish.yml

Lines changed: 50 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
name: Publish the GUI/CLI Docker Images
22

33
on:
4-
workflow_run:
5-
workflows: ["pytest"]
6-
types:
7-
- completed
4+
release:
5+
types: [published]
6+
push:
7+
tags:
8+
- 'v*.*.*-gui'
9+
- 'v*.*.*-cli'
810

911
env:
1012
REGISTRY: ghcr.io
@@ -13,52 +15,77 @@ env:
1315
jobs:
1416
build-and-push-image:
1517
runs-on: ubuntu-latest
16-
if: github.event.workflow_run.conclusion == 'success'
1718

1819
permissions:
1920
contents: read
2021
packages: write
2122
attestations: write
2223
id-token: write
2324

24-
strategy:
25-
matrix:
26-
include:
27-
- branch: main
28-
target: gui
29-
tag-prefix: gui
30-
- branch: cli
31-
target: base
32-
tag-prefix: cli
33-
3425
steps:
3526
- name: Checkout repository
3627
uses: actions/checkout@v5
3728

29+
- name: Verify version matches release tag
30+
run: |
31+
TAG_VERSION=${GITHUB_REF#refs/tags/v}
32+
PYPROJECT_VERSION=$(grep '^version = ' pyproject.toml | cut -d'"' -f2)
33+
if [ "$TAG_VERSION" != "$PYPROJECT_VERSION" ]; then
34+
echo "Version mismatch! Release tag: v$TAG_VERSION, pyproject.toml: $PYPROJECT_VERSION"
35+
echo "Please update pyproject.toml version to match the release tag."
36+
exit 1
37+
fi
38+
39+
SUFFIX=${GITHUB_REF##*-}
40+
if [ "${{ github.event_name }}" = "release" ]; then
41+
BRANCH="${{ github.event.release.target_commitish }}"
42+
else
43+
BRANCH="${{ github.ref_name }}"
44+
fi
45+
46+
if [ "$SUFFIX" = "gui" ]; then
47+
if [[ "$BRANCH" = "main" || "$BRANCH" == *"gui"* ]]; then
48+
TARGET="gui"
49+
else
50+
echo "GUI tag must target 'main' or a branch containing 'gui', got: $BRANCH"
51+
exit 1
52+
fi
53+
elif [ "$SUFFIX" = "cli" ]; then
54+
if [[ "$BRANCH" == *"cli"* ]]; then
55+
TARGET="base"
56+
else
57+
echo "CLI tag must target a branch containing 'cli', got: $BRANCH"
58+
exit 1
59+
fi
60+
else
61+
echo "Invalid tag suffix: $SUFFIX"
62+
exit 1
63+
fi
64+
echo "TARGET=$TARGET" >> $GITHUB_ENV
65+
echo "Version check passed: $TAG_VERSION"
66+
3867
- name: Log in to the Container registry
39-
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
68+
uses: docker/login-action@v2
4069
with:
4170
registry: ${{ env.REGISTRY }}
4271
username: ${{ github.actor }}
4372
password: ${{ secrets.GITHUB_TOKEN }}
4473

4574
- name: Extract metadata
4675
id: meta
47-
if: github.ref_name == matrix.branch
48-
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
76+
uses: docker/metadata-action@v5
4977
with:
5078
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
5179
tags: |
52-
type=raw,value=${{ matrix.tag-prefix }}-latest
53-
type=sha,prefix=${{ matrix.tag-prefix }}-
80+
type=raw,value=${{ env.TARGET }}-latest
81+
type=ref,event=tag
5482
5583
- name: Build and push image
56-
if: github.ref_name == matrix.branch
57-
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
84+
uses: docker/build-push-action@v4
5885
with:
5986
context: .
6087
file: Dockerfile
61-
target: ${{ matrix.target }}
88+
target: ${{ env.TARGET }}
6289
push: true
6390
tags: ${{ steps.meta.outputs.tags }}
6491
labels: ${{ steps.meta.outputs.labels }}

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[project]
2-
version = "2.1.0"
2+
version = "0.3.0"
33
name = "microtexture"
44
description = "Microtexture analysis and Dream3D pipeline automation"
55
requires-python = ">=3.12"

0 commit comments

Comments
 (0)