Skip to content

Commit 3af6103

Browse files
committed
fix release script
so it now: - records existing workflow runs before dispatch - waits for a new run matching the current HEAD SHA - validates that dist/ contains exactly the expected version artifact names before signing/uploading - refuses to create a GitHub release if the release version already exists
1 parent 75dac66 commit 3af6103

1 file changed

Lines changed: 62 additions & 3 deletions

File tree

release.sh

Lines changed: 62 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ fi
4545
echo "Project version: $VERSION (tag: $TAG)"
4646

4747
current_branch=$(git rev-parse --abbrev-ref HEAD)
48+
current_sha=$(git rev-parse HEAD)
4849
if [ "$current_branch" != "main" ]; then
4950
echo "ERROR: release.sh must be run from the main branch. Current branch: $current_branch"
5051
exit 1
@@ -109,20 +110,35 @@ fi
109110

110111
if [ "$BUILD" = true ]; then
111112
branch="$current_branch"
113+
previous_runs_file=$(mktemp)
114+
gh run list --repo "$REPO" --workflow "$WORKFLOW" --branch "$branch" \
115+
--limit 20 --json databaseId --jq '.[].databaseId' > "$previous_runs_file"
116+
112117
echo "Triggering workflow on branch: $branch"
118+
echo "Expected workflow commit: $current_sha"
113119
gh workflow run "$WORKFLOW" --repo "$REPO" --ref "$branch"
114120

115121
echo "Waiting for workflow run to appear..."
116122
run_id=""
117123
for attempt in $(seq 1 12); do
118124
sleep 5
119-
run_id=$(gh run list --repo "$REPO" --workflow "$WORKFLOW" --branch "$branch" \
120-
--limit 1 --json databaseId,status --jq '.[0].databaseId')
125+
run_id=$(
126+
gh run list --repo "$REPO" --workflow "$WORKFLOW" --branch "$branch" \
127+
--limit 20 --json databaseId,headSha,status \
128+
--jq ".[] | select(.headSha == \"$current_sha\") | .databaseId" |
129+
while read -r candidate_run_id; do
130+
if ! grep -qx "$candidate_run_id" "$previous_runs_file"; then
131+
echo "$candidate_run_id"
132+
break
133+
fi
134+
done
135+
)
121136
if [ -n "$run_id" ]; then
122137
break
123138
fi
124-
echo " Attempt $attempt/12: run not yet visible..."
139+
echo " Attempt $attempt/12: new run for $current_sha not yet visible..."
125140
done
141+
rm -f "$previous_runs_file"
126142

127143
if [ -z "$run_id" ]; then
128144
echo "ERROR: Could not find workflow run after 60 seconds."
@@ -164,6 +180,45 @@ if [ "$BUILD" = true ]; then
164180
ls -lh "$DIST_DIR/"
165181
fi
166182

183+
expected_assets=(
184+
"alipsa-accounting-${VERSION}-linux.zip"
185+
"alipsa-accounting-${VERSION}-windows.zip"
186+
"alipsa-accounting-${VERSION}-macos.zip"
187+
"app-${VERSION}.zip"
188+
)
189+
missing_assets=()
190+
for asset in "${expected_assets[@]}"; do
191+
if [ ! -f "$DIST_DIR/$asset" ]; then
192+
missing_assets+=("$asset")
193+
fi
194+
done
195+
196+
wrong_version_assets=()
197+
for file in "$DIST_DIR"/alipsa-accounting-*.zip "$DIST_DIR"/app-*.zip; do
198+
[ -e "$file" ] || continue
199+
name=$(basename "$file")
200+
case " ${expected_assets[*]} " in
201+
*" $name "*) ;;
202+
*) wrong_version_assets+=("$name") ;;
203+
esac
204+
done
205+
206+
if [ "${#missing_assets[@]}" -gt 0 ] || [ "${#wrong_version_assets[@]}" -gt 0 ]; then
207+
echo "ERROR: Artifacts in $DIST_DIR do not match project version $VERSION."
208+
if [ "${#missing_assets[@]}" -gt 0 ]; then
209+
echo "Missing expected artifacts:"
210+
printf ' %s\n' "${missing_assets[@]}"
211+
fi
212+
if [ "${#wrong_version_assets[@]}" -gt 0 ]; then
213+
echo "Unexpected artifact versions:"
214+
printf ' %s\n' "${wrong_version_assets[@]}"
215+
fi
216+
echo ""
217+
echo "Artifacts in $DIST_DIR:"
218+
find "$DIST_DIR" -maxdepth 1 -type f -exec basename {} \; | sort | sed 's/^/ /'
219+
exit 1
220+
fi
221+
167222
if [ "$SIGN" = true ]; then
168223
echo ""
169224
echo "Signing artifacts with GPG..."
@@ -183,6 +238,10 @@ fi
183238
if [ "$RELEASE" = true ]; then
184239
echo ""
185240
echo "Creating GitHub release $TAG..."
241+
if gh release view "$TAG" --repo "$REPO" >/dev/null 2>&1; then
242+
echo "ERROR: GitHub release $TAG already exists. Delete it or use gh release upload --clobber intentionally."
243+
exit 1
244+
fi
186245
mapfile -t release_assets < <(find "$DIST_DIR" -maxdepth 1 -type f)
187246
gh release create "$TAG" \
188247
--repo "$REPO" \

0 commit comments

Comments
 (0)