Skip to content

Commit 7cdc7ef

Browse files
authored
Fix race condition in release process (#4766)
* Close window between release and artifact creation * Use alternate method of falling back * Remove unused env vars
1 parent 4f1d07f commit 7cdc7ef

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Release Guard
2+
on:
3+
release:
4+
types: [created]
5+
6+
permissions:
7+
contents: write
8+
9+
jobs:
10+
unset-latest:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Restore previous release as latest if needed
14+
run: |
15+
LATEST_TAG=$(gh release list --json tagName,isLatest -q '.[] | select(.isLatest) | .tagName')
16+
if [ "$LATEST_TAG" != "${{ github.event.release.tag_name }}" ]; then
17+
echo "Release is not marked as latest (latest is $LATEST_TAG), skipping."
18+
exit 0
19+
fi
20+
21+
echo "Release ${{ github.event.release.tag_name }} is marked as latest, finding previous release..."
22+
23+
# Get the second release in the list (sorted by date, excluding drafts/prereleases by default)
24+
# The first one is the current release, so we want the second one
25+
PREVIOUS_TAG=$(gh release list --exclude-drafts --exclude-pre-releases --json tagName -q '.[1].tagName')
26+
27+
if [ -z "$PREVIOUS_TAG" ]; then
28+
echo "No previous release found, cannot restore. Exiting."
29+
exit 0
30+
fi
31+
32+
echo "Restoring $PREVIOUS_TAG as latest..."
33+
gh release edit "$PREVIOUS_TAG" --latest

.github/workflows/release.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,7 @@ jobs:
5353
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5454
HOMEBREW_TAP_TOKEN: ${{ secrets.HOMEBREW_TAP_TOKEN }}
5555
GORELEASER_KEY: ${{ secrets.GORELEASER_KEY }}
56+
- name: Mark release as latest
57+
run: gh release edit ${{ github.ref_name }} --latest
58+
env:
59+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.goreleaser.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
version: 2
2+
release:
3+
make_latest: false
24
builds:
35
- id: trufflehog-upx
46
binary: trufflehog

0 commit comments

Comments
 (0)