Skip to content

Commit 55975f1

Browse files
committed
fix(release): skip publish when release assets already exist
Avoid duplicate tag push failures from GoReleaser 409 conflicts when homebrew/scoop were already updated by a prior successful run.
1 parent cfd9aa4 commit 55975f1

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

.github/workflows/release.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ on:
1111
required: true
1212
type: string
1313

14+
concurrency:
15+
group: release-${{ github.workflow }}-${{ github.event_name == 'workflow_dispatch' && inputs.tag || github.ref }}
16+
cancel-in-progress: false
17+
1418
permissions:
1519
contents: write
1620

@@ -23,6 +27,34 @@ jobs:
2327
fetch-depth: 0
2428
ref: ${{ github.event_name == 'workflow_dispatch' && format('refs/tags/{0}', inputs.tag) || github.ref }}
2529

30+
31+
- name: Resolve release tag
32+
id: tag
33+
run: |
34+
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
35+
echo "name=${{ inputs.tag }}" >> "$GITHUB_OUTPUT"
36+
else
37+
echo "name=${GITHUB_REF#refs/tags/}" >> "$GITHUB_OUTPUT"
38+
fi
39+
40+
- name: Check if release already published
41+
id: published
42+
env:
43+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
44+
run: |
45+
COUNT=$(gh release view "${{ steps.tag.outputs.name }}" \
46+
--json assets -q '.assets | length' 2>/dev/null || echo 0)
47+
echo "asset_count=$COUNT" >> "$GITHUB_OUTPUT"
48+
if [ "$COUNT" -ge 6 ]; then
49+
echo "skip=true" >> "$GITHUB_OUTPUT"
50+
else
51+
echo "skip=false" >> "$GITHUB_OUTPUT"
52+
fi
53+
54+
- name: Release already published
55+
if: steps.published.outputs.skip == 'true'
56+
run: |
57+
echo "Release ${{ steps.tag.outputs.name }} already has ${{ steps.published.outputs.asset_count }} assets — skipping publish"
2658
- name: Checkout cimis-tsdb dependency
2759
uses: actions/checkout@v7
2860
with:
@@ -31,6 +63,7 @@ jobs:
3163
token: ${{ secrets.GH_PAT }}
3264

3365
- name: Set up Go
66+
if: steps.published.outputs.skip != 'true'
3467
uses: actions/setup-go@v6
3568
with:
3669
go-version-file: 'go.mod'
@@ -45,6 +78,7 @@ jobs:
4578
GOPRIVATE: github.com/dl-alexandre/*
4679

4780
- name: Run GoReleaser
81+
if: steps.published.outputs.skip != 'true'
4882
uses: goreleaser/goreleaser-action@v7
4983
with:
5084
distribution: goreleaser

0 commit comments

Comments
 (0)