Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions packages/ui/scripts/collect-release-artifacts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
#
# Run from the repo root. Usage: collect-release-artifacts.sh <version>
set -euo pipefail
shopt -s nullglob globstar

version="${1:?usage: collect-release-artifacts.sh <version>}"

# macOS GitHub runners ship bash 3.2, which lacks `globstar`. Use `find` instead
# of `**` so artifact discovery works regardless of the bash version.
out="packages/ui/out/make"
dmgs=("$out"/**/*.dmg)
zips=("$out"/**/*.zip)
if [ "${#dmgs[@]}" -eq 0 ] || [ "${#zips[@]}" -eq 0 ]; then
src_dmg="$(find "$out" -type f -name '*.dmg' | head -n1)"
src_zip="$(find "$out" -type f -name '*.zip' | head -n1)"
Comment on lines +14 to +15

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using find ... | head -n1 in combination with set -euo pipefail can lead to flaky failures or unexpected early exits:

  1. SIGPIPE / pipefail issue: If find produces multiple lines of output, head -n1 will exit early after reading the first line. This closes the pipe, causing find to receive a SIGPIPE signal and exit with status 141. Under pipefail, this non-zero exit status propagates and triggers set -e, crashing the script.
  2. Bypassing error handling: If the $out directory does not exist, find will fail. Instead of reaching the friendly error message and exit 1 on lines 16-20, the script will crash immediately on line 14 or 15.

Appending || true to the command inside the command substitution ensures the assignment always succeeds, allowing the script to handle missing files or directories gracefully in the subsequent if block.

Suggested change
src_dmg="$(find "$out" -type f -name '*.dmg' | head -n1)"
src_zip="$(find "$out" -type f -name '*.zip' | head -n1)"
src_dmg="$(find "$out" -type f -name '*.dmg' | head -n1 || true)"
src_zip="$(find "$out" -type f -name '*.zip' | head -n1 || true)"

if [ -z "$src_dmg" ] || [ -z "$src_zip" ]; then
echo "Missing Forge artifacts under $out"
find "$out" -type f || true
exit 1
Expand All @@ -21,8 +22,8 @@ fi
mkdir -p dist-release
dmg="git-diff-review-${version}-arm64.dmg"
zip="git-diff-review-${version}-arm64.zip"
cp "${dmgs[0]}" "dist-release/${dmg}"
cp "${zips[0]}" "dist-release/${zip}"
cp "$src_dmg" "dist-release/${dmg}"
cp "$src_zip" "dist-release/${zip}"

cd dist-release
shasum -a 256 "$dmg" "$zip" > SHASUMS256.txt
Expand Down
Loading