Skip to content

Commit 9bb0762

Browse files
committed
Add version tag to builds
1 parent 9ea0744 commit 9bb0762

1 file changed

Lines changed: 15 additions & 8 deletions

File tree

.github/workflows/build.yml

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,12 @@ name: Build and Push to GHCR
99
# successfully.
1010
#
1111
# Triggers:
12-
# - workflow_run: fires after GoFortress completes. The `build-and-push` job only
13-
# runs when GoFortress's conclusion is `success`. This applies to push-to-main,
14-
# tag pushes (v*), and any other branch GoFortress runs on.
12+
# - workflow_run: fires after GoFortress completes on `main` or a `v*` tag push.
13+
# The gate job only proceeds when GoFortress's conclusion is `success` AND the
14+
# upstream run was a `push` event (filtering out PR-triggered GoFortress runs,
15+
# which are handled separately by the pull_request trigger below). For tag
16+
# pushes, the image tag is taken from `workflow_run.head_branch` (e.g. v1.2.3)
17+
# so the published image carries the release version, not just `latest`.
1518
# - pull_request: kept so PRs still build the image (with `push: false`) for
1619
# fast feedback. PR builds do NOT publish, so they don't need the gate.
1720
# - workflow_dispatch: manual run; gated via `needs:` chain on local jobs that
@@ -32,6 +35,7 @@ on:
3235
types: [completed]
3336
branches:
3437
- main
38+
- "v*" # Tag pushes appear here as head_branch (e.g. v1.2.3)
3539
pull_request:
3640
branches:
3741
- main
@@ -55,7 +59,8 @@ jobs:
5559
runs-on: ubuntu-latest
5660
if: >-
5761
github.event_name != 'workflow_run' ||
58-
github.event.workflow_run.conclusion == 'success'
62+
(github.event.workflow_run.conclusion == 'success' &&
63+
github.event.workflow_run.event == 'push')
5964
steps:
6065
- name: Confirm upstream gates
6166
run: |
@@ -84,10 +89,12 @@ jobs:
8489
run: |
8590
# When triggered via workflow_run, github.ref points at the default branch
8691
# of the *triggering* workflow's repo state, not the original push ref.
87-
# Tag-based releases publishing through workflow_run are out of scope here;
88-
# GoFortress's own release job handles tag releases. For workflow_run we
89-
# always tag the image as `latest` plus the commit SHA.
90-
if [[ "$EVENT_NAME" == "push" && "$REF_TYPE" == "tag" ]]; then
92+
# For workflow_run, derive the tag from the upstream run: tag pushes set
93+
# workflow_run.head_branch to the tag name (e.g. v1.2.3); main pushes set
94+
# it to `main`. Direct push/tag and dispatch events fall back to ref.
95+
if [[ "$EVENT_NAME" == "workflow_run" && "$WR_EVENT" == "push" && "$WR_HEAD_BRANCH" =~ ^v[0-9] ]]; then
96+
tag="$WR_HEAD_BRANCH"
97+
elif [[ "$EVENT_NAME" == "push" && "$REF_TYPE" == "tag" ]]; then
9198
tag="$REF_NAME"
9299
else
93100
tag="latest"

0 commit comments

Comments
 (0)