Skip to content

Commit cb9fa94

Browse files
authored
ci: fix release workflow (#38)
1 parent 067f8b1 commit cb9fa94

File tree

2 files changed

+82
-9
lines changed

2 files changed

+82
-9
lines changed

.github/workflows/docker-publish.yml

Lines changed: 80 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,22 @@
11
name: Publish Docker Image
22

33
on:
4-
release:
5-
types: [published]
4+
# Trigger when Release workflow completes successfully
5+
workflow_run:
6+
workflows:
7+
- Release
8+
types:
9+
- completed
10+
branches:
11+
- main
12+
13+
# Manual trigger for existing tags or re-runs
614
workflow_dispatch:
15+
inputs:
16+
tag:
17+
description: 'Tag to build (e.g., v1.0.0). Uses latest tag if not specified.'
18+
required: false
19+
type: string
720

821
permissions:
922
contents: read
@@ -16,37 +29,96 @@ env:
1629
jobs:
1730
build-and-push:
1831
runs-on: ubuntu-latest
32+
# Only run if:
33+
# 1. Triggered by successful Release workflow, OR
34+
# 2. Manually dispatched
35+
if: |
36+
(github.event.workflow_run.conclusion == 'success') ||
37+
github.event_name == 'workflow_dispatch'
38+
1939
steps:
20-
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
40+
- name: Checkout repository
41+
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
42+
with:
43+
fetch-depth: 0
44+
ref: ${{ github.event.workflow_run.head_sha || github.sha }}
45+
46+
- name: Get tag name
47+
id: get-tag
48+
run: |
49+
# Fetch all tags to ensure we have the latest
50+
git fetch --tags --force
51+
52+
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
53+
# Manual trigger
54+
if [ -n "${{ inputs.tag }}" ]; then
55+
TAG="${{ inputs.tag }}"
56+
else
57+
# No tag specified - use the latest tag
58+
TAG=$(git tag -l 'v*' --sort=-v:refname | head -n1)
59+
if [ -z "$TAG" ]; then
60+
echo "Error: No tag specified and no tags found in repository"
61+
exit 1
62+
fi
63+
echo "No tag specified, using latest tag: $TAG"
64+
fi
65+
else
66+
# Auto trigger from workflow_run
67+
# Find tag pointing to the HEAD commit (the commit that was just released)
68+
TAG=$(git tag --points-at HEAD | grep '^v' | sort -V | tail -n1)
69+
if [ -z "$TAG" ]; then
70+
echo "No tag found on commit ${{ github.event.workflow_run.head_sha }}"
71+
echo "::notice::Skipping Docker build - no release tag found on this commit"
72+
echo "skip=true" >> $GITHUB_OUTPUT
73+
exit 0
74+
fi
75+
fi
76+
77+
echo "tag=$TAG" >> $GITHUB_OUTPUT
78+
echo "skip=false" >> $GITHUB_OUTPUT
79+
echo "Docker image tag: $TAG"
80+
81+
# Extract version without 'v' prefix for semver tags
82+
VERSION="${TAG#v}"
83+
echo "version=$VERSION" >> $GITHUB_OUTPUT
84+
85+
- name: Checkout tag
86+
if: steps.get-tag.outputs.skip != 'true'
87+
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
2188
with:
22-
ref: ${{ github.event.release.tag_name || github.ref }}
89+
ref: ${{ steps.get-tag.outputs.tag }}
2390

2491
- name: Set up QEMU
92+
if: steps.get-tag.outputs.skip != 'true'
2593
uses: docker/setup-qemu-action@c7c53464625b32c7a7e944ae62b3e17d2b600130 # v3.7.0
2694

2795
- name: Set up Docker Buildx
96+
if: steps.get-tag.outputs.skip != 'true'
2897
uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f # v3.12.0
2998

3099
- name: Login to GitHub Container Registry
100+
if: steps.get-tag.outputs.skip != 'true'
31101
uses: docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef # v3.6.0
32102
with:
33103
registry: ${{ env.REGISTRY }}
34104
username: ${{ github.actor }}
35105
password: ${{ secrets.GITHUB_TOKEN }}
36106

37107
- name: Extract metadata
108+
if: steps.get-tag.outputs.skip != 'true'
38109
id: meta
39110
uses: docker/metadata-action@c299e40c65443455700f0fdfc63efafe5b349051 # v5.10.0
40111
with:
41112
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
42113
tags: |
43-
type=semver,pattern={{version}}
44-
type=semver,pattern={{major}}.{{minor}}
45-
type=semver,pattern={{major}}
114+
type=semver,pattern={{version}},value=${{ steps.get-tag.outputs.tag }}
115+
type=semver,pattern={{major}}.{{minor}},value=${{ steps.get-tag.outputs.tag }}
116+
type=semver,pattern={{major}},value=${{ steps.get-tag.outputs.tag }}
46117
type=sha,prefix=
47-
type=raw,value=latest,enable=${{ github.event_name == 'release' }}
118+
type=raw,value=latest,enable=${{ github.event_name != 'workflow_dispatch' }}
48119
49120
- name: Build and push
121+
if: steps.get-tag.outputs.skip != 'true'
50122
uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6.18.0
51123
with:
52124
context: .

.tagpr

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010

1111
# GitHub Release creation method
1212
# true: auto create, draft: create draft, false: do not create
13-
release = draft
13+
# Set to false - GoReleaser handles release creation
14+
release = false
1415

1516
# Labels indicating major version upgrade
1617
majorLabels = ["breaking-change", "major"]

0 commit comments

Comments
 (0)