-
Notifications
You must be signed in to change notification settings - Fork 257
82 lines (72 loc) · 2.44 KB
/
Copy pathrelease-binaries.yml
File metadata and controls
82 lines (72 loc) · 2.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
name: Build Release Binaries
on:
release:
types: [published, prereleased]
workflow_dispatch:
inputs:
tag:
description: "Tag to release (e.g., v2.0.0)"
required: false
permissions:
contents: write
packages: write
jobs:
goreleaser:
name: Build Cross-Platform Binaries
runs-on: ubuntu-latest
steps:
- name: Determine tag
id: tag
run: |
if [ "${{ github.event_name }}" = "release" ]; then
echo "tag=${{ github.event.release.tag_name }}" >> $GITHUB_OUTPUT
elif [ -n "${{ inputs.tag }}" ]; then
echo "tag=${{ inputs.tag }}" >> $GITHUB_OUTPUT
else
echo "tag=${{ github.ref_name }}" >> $GITHUB_OUTPUT
fi
- name: Check if binaries already exist
id: check_assets
run: |
ASSET_COUNT=$(gh api \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
/repos/${{ github.repository }}/releases/tags/${{ steps.tag.outputs.tag }} \
--jq '.assets | length' 2>/dev/null || echo "0")
echo "asset_count=$ASSET_COUNT" >> $GITHUB_OUTPUT
if [ "$ASSET_COUNT" -gt 0 ]; then
echo "::notice::Release already has $ASSET_COUNT asset(s). Skipping build."
echo "skip_build=true" >> $GITHUB_OUTPUT
else
echo "::notice::No assets found. Proceeding with build."
echo "skip_build=false" >> $GITHUB_OUTPUT
fi
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Checkout
if: steps.check_assets.outputs.skip_build == 'false'
uses: actions/checkout@v5
with:
fetch-depth: 0
ref: ${{ steps.tag.outputs.tag }}
- name: Set up Go
if: steps.check_assets.outputs.skip_build == 'false'
uses: actions/setup-go@v5
with:
go-version: stable
- name: Run GoReleaser
if: steps.check_assets.outputs.skip_build == 'false'
uses: goreleaser/goreleaser-action@v6
with:
distribution: goreleaser
version: latest
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Upload release artifacts
if: steps.check_assets.outputs.skip_build == 'false'
uses: actions/upload-artifact@v4
with:
name: release-artifacts
path: dist/*
retention-days: 7