Skip to content

Commit cc34776

Browse files
fix(release): prevent silent failures in version check and asset upload
- check-version: guard HEAD^ with git rev-parse so first commits in a repo don't crash the step - build: set fail-fast: false so one OS failing doesn't cancel the others mid-flight; simplify condition to version_changed since force already flows into that output - release: gate explicitly on version_changed - release: abort if VERSION is empty instead of silently creating a bad tag - release: abort if no artifacts were found instead of "succeeding" with an empty release - release: fix asset upload using "$f#$dir" instead of the invalid --name flag, which was the actual cause of assets not landing - release: track per-file upload failures and exit 1 if any upload fails, instead of silently succeeding
1 parent 7094272 commit cc34776

1 file changed

Lines changed: 36 additions & 11 deletions

File tree

.github/workflows/release.yml

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ jobs:
2323
- uses: actions/checkout@v4
2424
with:
2525
fetch-depth: 2
26-
26+
2727
- name: Check if version changed
2828
id: check
2929
run: |
3030
if [ "${{ github.event_name }}" = "workflow_dispatch" ] && [ "${{ inputs.force }}" = "true" ]; then
3131
echo "changed=true" >> $GITHUB_OUTPUT
32-
elif git diff HEAD^ HEAD -- Cargo.toml | grep -q '^[+-]version = '; then
32+
elif git rev-parse HEAD^ >/dev/null 2>&1 && git diff HEAD^ HEAD -- Cargo.toml | grep -q '^[+-]version = '; then
3333
echo "changed=true" >> $GITHUB_OUTPUT
3434
else
3535
echo "changed=false" >> $GITHUB_OUTPUT
@@ -44,8 +44,9 @@ jobs:
4444
4545
build:
4646
needs: check-version
47-
if: needs.check-version.outputs.version_changed == 'true' || (github.event_name == 'workflow_dispatch' && inputs.force)
47+
if: needs.check-version.outputs.version_changed == 'true'
4848
strategy:
49+
fail-fast: false
4950
matrix:
5051
include:
5152
- os: ubuntu-latest
@@ -71,18 +72,18 @@ jobs:
7172
with:
7273
targets: ${{ matrix.target }}
7374
- uses: Swatinem/rust-cache@v2
74-
75+
7576
- name: Install musl-tools
7677
if: matrix.os == 'ubuntu-latest'
7778
run: sudo apt-get install -y musl-tools
78-
79+
7980
- name: Build
8081
run: cargo build --release --target ${{ matrix.target }}
81-
82+
8283
- name: Strip binary
8384
if: matrix.os != 'windows-latest'
8485
run: strip target/${{ matrix.target }}/release/${{ matrix.artifact_name }}
85-
86+
8687
- name: Upload artifact
8788
uses: actions/upload-artifact@v4
8889
with:
@@ -91,12 +92,13 @@ jobs:
9192

9293
release:
9394
needs: [check-version, build]
95+
if: needs.check-version.outputs.version_changed == 'true'
9496
runs-on: ubuntu-latest
9597
permissions:
9698
contents: write
9799
steps:
98100
- uses: actions/checkout@v4
99-
101+
100102
- name: Download artifacts
101103
uses: actions/download-artifact@v4
102104
with:
@@ -106,21 +108,44 @@ jobs:
106108
env:
107109
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
108110
run: |
111+
set -e
109112
VERSION="${{ needs.check-version.outputs.version }}"
113+
if [ -z "$VERSION" ]; then
114+
echo "No version resolved — aborting"
115+
exit 1
116+
fi
117+
110118
if gh release view "v$VERSION" &>/dev/null; then
111119
echo "Release v$VERSION already exists — skipping"
112120
exit 0
113121
fi
122+
114123
gh release create "v$VERSION" --title "v$VERSION" --generate-notes
124+
115125
shopt -s nullglob
116126
ASSETS=(artifacts/*/*)
117127
echo "Found ${#ASSETS[@]} artifacts:"
118128
for f in "${ASSETS[@]}"; do
119129
echo " - $f"
120130
done
131+
132+
if [ "${#ASSETS[@]}" -eq 0 ]; then
133+
echo "No artifacts found to upload — failing"
134+
exit 1
135+
fi
136+
137+
FAILED=0
121138
for f in "${ASSETS[@]}"; do
122139
dir=$(basename "$(dirname "$f")")
123-
name="$dir"
124-
echo "Uploading $f as $name..."
125-
gh release upload "v$VERSION" "$f" --name "$name" --clobber || echo "Failed to upload $f"
140+
echo "Uploading $f as $dir..."
141+
if ! gh release upload "v$VERSION" "$f#$dir" --clobber; then
142+
echo "Failed to upload $f"
143+
FAILED=1
144+
fi
126145
done
146+
147+
if [ "$FAILED" -eq 1 ]; then
148+
echo "One or more uploads failed"
149+
exit 1
150+
fi
151+

0 commit comments

Comments
 (0)