Skip to content

Commit 62c9bcd

Browse files
Build binaries on prerelease/release (#519)
1 parent 7f6abc5 commit 62c9bcd

1 file changed

Lines changed: 39 additions & 2 deletions

File tree

.github/workflows/release-binaries.yml

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ name: Build Release Binaries
22

33
on:
44
release:
5-
types: [published]
5+
types: [published, prereleased]
66
workflow_dispatch:
77
inputs:
88
tag:
9-
description: 'Tag to release (e.g., v2.0.0)'
9+
description: "Tag to release (e.g., v2.0.0)"
1010
required: false
1111

1212
permissions:
@@ -18,17 +18,53 @@ jobs:
1818
name: Build Cross-Platform Binaries
1919
runs-on: ubuntu-latest
2020
steps:
21+
- name: Determine tag
22+
id: tag
23+
run: |
24+
if [ "${{ github.event_name }}" = "release" ]; then
25+
echo "tag=${{ github.event.release.tag_name }}" >> $GITHUB_OUTPUT
26+
elif [ -n "${{ inputs.tag }}" ]; then
27+
echo "tag=${{ inputs.tag }}" >> $GITHUB_OUTPUT
28+
else
29+
echo "tag=${{ github.ref_name }}" >> $GITHUB_OUTPUT
30+
fi
31+
32+
- name: Check if binaries already exist
33+
id: check_assets
34+
run: |
35+
ASSET_COUNT=$(gh api \
36+
-H "Accept: application/vnd.github+json" \
37+
-H "X-GitHub-Api-Version: 2022-11-28" \
38+
/repos/${{ github.repository }}/releases/tags/${{ steps.tag.outputs.tag }} \
39+
--jq '.assets | length' 2>/dev/null || echo "0")
40+
41+
echo "asset_count=$ASSET_COUNT" >> $GITHUB_OUTPUT
42+
43+
if [ "$ASSET_COUNT" -gt 0 ]; then
44+
echo "::notice::Release already has $ASSET_COUNT asset(s). Skipping build."
45+
echo "skip_build=true" >> $GITHUB_OUTPUT
46+
else
47+
echo "::notice::No assets found. Proceeding with build."
48+
echo "skip_build=false" >> $GITHUB_OUTPUT
49+
fi
50+
env:
51+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
52+
2153
- name: Checkout
54+
if: steps.check_assets.outputs.skip_build == 'false'
2255
uses: actions/checkout@v5
2356
with:
2457
fetch-depth: 0
58+
ref: ${{ steps.tag.outputs.tag }}
2559

2660
- name: Set up Go
61+
if: steps.check_assets.outputs.skip_build == 'false'
2762
uses: actions/setup-go@v5
2863
with:
2964
go-version: stable
3065

3166
- name: Run GoReleaser
67+
if: steps.check_assets.outputs.skip_build == 'false'
3268
uses: goreleaser/goreleaser-action@v6
3369
with:
3470
distribution: goreleaser
@@ -38,6 +74,7 @@ jobs:
3874
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3975

4076
- name: Upload release artifacts
77+
if: steps.check_assets.outputs.skip_build == 'false'
4178
uses: actions/upload-artifact@v4
4279
with:
4380
name: release-artifacts

0 commit comments

Comments
 (0)