|
1 | 1 | # .github/workflows/release.yml |
2 | | -name: release |
| 2 | +name: goreleaser |
3 | 3 |
|
4 | 4 | on: |
5 | 5 | push: |
6 | 6 | # run only against tags |
7 | 7 | tags: |
8 | | - - "v*" |
| 8 | + - "*" |
9 | 9 |
|
10 | 10 | permissions: |
11 | 11 | contents: write |
| 12 | + # packages: write |
| 13 | + # issues: write |
| 14 | + # id-token: write |
12 | 15 |
|
13 | 16 | jobs: |
14 | 17 | goreleaser: |
15 | 18 | runs-on: ubuntu-latest |
16 | | - outputs: |
17 | | - tag: ${{ steps.get_tag.outputs.tag }} |
18 | 19 | steps: |
19 | | - - name: Get tag |
20 | | - id: get_tag |
21 | | - run: echo "tag=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT |
22 | | - |
23 | 20 | - name: Checkout |
24 | 21 | uses: actions/checkout@v4 |
25 | 22 | with: |
26 | 23 | fetch-depth: 0 |
27 | | - |
28 | 24 | - name: Set up Go |
29 | 25 | uses: actions/setup-go@v5 |
30 | 26 | with: |
31 | 27 | go-version: stable |
32 | | - |
| 28 | + # More assembly might be required: Docker logins, GPG, etc. |
| 29 | + # It all depends on your needs. |
33 | 30 | - name: Run GoReleaser |
34 | 31 | uses: goreleaser/goreleaser-action@v6 |
35 | 32 | with: |
| 33 | + # either 'goreleaser' (default) or 'goreleaser-pro' |
36 | 34 | distribution: goreleaser |
| 35 | + # 'latest', 'nightly', or a semver |
37 | 36 | version: "~> v2" |
38 | 37 | args: release --clean |
39 | 38 | env: |
40 | 39 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
41 | | - |
42 | | - verify-and-publish: |
43 | | - needs: goreleaser |
44 | | - runs-on: ubuntu-latest |
45 | | - env: |
46 | | - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
47 | | - TAG: ${{ needs.goreleaser.outputs.tag }} |
48 | | - steps: |
49 | | - - name: Get release info |
50 | | - id: release |
51 | | - run: | |
52 | | - echo "Fetching draft release for tag: $TAG" |
53 | | - RELEASE_ID=$(gh api repos/${{ github.repository }}/releases \ |
54 | | - --jq ".[] | select(.tag_name == \"$TAG\" and .draft == true) | .id") |
55 | | - |
56 | | - if [ -z "$RELEASE_ID" ]; then |
57 | | - echo "ERROR: No draft release found for tag $TAG" |
58 | | - exit 1 |
59 | | - fi |
60 | | - |
61 | | - echo "Found draft release ID: $RELEASE_ID" |
62 | | - echo "release_id=$RELEASE_ID" >> $GITHUB_OUTPUT |
63 | | -
|
64 | | - - name: Verify asset count |
65 | | - run: | |
66 | | - echo "Verifying assets for release ID: ${{ steps.release.outputs.release_id }}" |
67 | | - |
68 | | - ASSETS=$(gh api repos/${{ github.repository }}/releases/${{ steps.release.outputs.release_id }}/assets) |
69 | | - ASSET_COUNT=$(echo "$ASSETS" | jq length) |
70 | | - |
71 | | - echo "Found $ASSET_COUNT assets" |
72 | | - echo "$ASSETS" | jq -r '.[].name' |
73 | | - |
74 | | - # Expect: hostlink_Linux_x86_64.tar.gz, hostlink_Linux_arm64.tar.gz, checksums.txt |
75 | | - if [ "$ASSET_COUNT" -lt 3 ]; then |
76 | | - echo "ERROR: Expected at least 3 assets, found $ASSET_COUNT" |
77 | | - exit 1 |
78 | | - fi |
79 | | - |
80 | | - # Verify required assets exist |
81 | | - for asset in "hostlink_Linux_x86_64.tar.gz" "hostlink_Linux_arm64.tar.gz" "checksums.txt"; do |
82 | | - if ! echo "$ASSETS" | jq -e ".[] | select(.name == \"$asset\")" > /dev/null; then |
83 | | - echo "ERROR: Missing required asset: $asset" |
84 | | - exit 1 |
85 | | - fi |
86 | | - done |
87 | | - |
88 | | - echo "All required assets present" |
89 | | -
|
90 | | - - name: Download assets |
91 | | - run: | |
92 | | - mkdir -p assets |
93 | | - cd assets |
94 | | - |
95 | | - RELEASE_ID="${{ steps.release.outputs.release_id }}" |
96 | | - ASSETS=$(gh api repos/${{ github.repository }}/releases/$RELEASE_ID/assets) |
97 | | - |
98 | | - for asset in "hostlink_Linux_x86_64.tar.gz" "hostlink_Linux_arm64.tar.gz" "checksums.txt"; do |
99 | | - echo "Downloading $asset..." |
100 | | - ASSET_ID=$(echo "$ASSETS" | jq -r ".[] | select(.name == \"$asset\") | .id") |
101 | | - gh api repos/${{ github.repository }}/releases/assets/$ASSET_ID \ |
102 | | - -H "Accept: application/octet-stream" > "$asset" |
103 | | - echo "Downloaded $asset ($(stat -c%s "$asset") bytes)" |
104 | | - done |
105 | | -
|
106 | | - - name: Validate gzip files |
107 | | - run: | |
108 | | - cd assets |
109 | | - |
110 | | - for tarball in hostlink_Linux_x86_64.tar.gz hostlink_Linux_arm64.tar.gz; do |
111 | | - echo "Validating $tarball..." |
112 | | - |
113 | | - # Check gzip magic bytes (1f8b) |
114 | | - MAGIC=$(xxd -p -l 2 "$tarball") |
115 | | - if [ "$MAGIC" != "1f8b" ]; then |
116 | | - echo "ERROR: $tarball is not a valid gzip file (magic: $MAGIC)" |
117 | | - exit 1 |
118 | | - fi |
119 | | - |
120 | | - # Verify it can be listed |
121 | | - if ! tar -tzf "$tarball" > /dev/null 2>&1; then |
122 | | - echo "ERROR: $tarball cannot be read by tar" |
123 | | - exit 1 |
124 | | - fi |
125 | | - |
126 | | - echo "$tarball is valid" |
127 | | - done |
128 | | -
|
129 | | - - name: Verify checksums |
130 | | - run: | |
131 | | - cd assets |
132 | | - echo "Verifying SHA256 checksums..." |
133 | | - |
134 | | - # checksums.txt format: <hash> <filename> |
135 | | - sha256sum -c checksums.txt |
136 | | - |
137 | | - echo "All checksums verified" |
138 | | -
|
139 | | - - name: Test binary execution |
140 | | - run: | |
141 | | - cd assets |
142 | | - echo "Testing x86_64 binary..." |
143 | | - |
144 | | - mkdir -p test |
145 | | - tar -xzf hostlink_Linux_x86_64.tar.gz -C test |
146 | | - |
147 | | - # Run version check |
148 | | - if ! ./test/hostlink --version; then |
149 | | - echo "ERROR: hostlink --version failed" |
150 | | - exit 1 |
151 | | - fi |
152 | | - |
153 | | - echo "Binary execution test passed" |
154 | | -
|
155 | | - - name: Publish release |
156 | | - run: | |
157 | | - RELEASE_ID="${{ steps.release.outputs.release_id }}" |
158 | | - |
159 | | - # Retry logic with exponential backoff |
160 | | - MAX_RETRIES=3 |
161 | | - DELAYS=(5 15 45) |
162 | | - |
163 | | - for i in $(seq 0 $((MAX_RETRIES - 1))); do |
164 | | - echo "Attempt $((i + 1)) of $MAX_RETRIES: Publishing release..." |
165 | | - |
166 | | - if gh api repos/${{ github.repository }}/releases/$RELEASE_ID \ |
167 | | - -X PATCH -f draft=false; then |
168 | | - echo "Release published successfully!" |
169 | | - exit 0 |
170 | | - fi |
171 | | - |
172 | | - if [ $i -lt $((MAX_RETRIES - 1)) ]; then |
173 | | - DELAY=${DELAYS[$i]} |
174 | | - echo "Publish failed, retrying in ${DELAY}s..." |
175 | | - sleep $DELAY |
176 | | - fi |
177 | | - done |
178 | | - |
179 | | - echo "ERROR: Failed to publish release after $MAX_RETRIES attempts" |
180 | | - exit 1 |
| 40 | + # Your GoReleaser Pro key, if you are using the 'goreleaser-pro' distribution |
| 41 | + # GORELEASER_KEY: ${{ secrets.GORELEASER_KEY }} |
0 commit comments