fix(release): distinguish missing releases from GitHub errors

This commit is contained in:
Vincent Koc
2026-06-26 14:55:55 -07:00
parent c324cc6068
commit f217b94092
2 changed files with 34 additions and 1 deletions
@@ -309,7 +309,21 @@ jobs:
UPDATE_EXISTING: ${{ inputs.update_existing }}
run: |
set -euo pipefail
if gh release view "$RELEASE_TAG" --repo "$GITHUB_REPOSITORY" >/dev/null 2>&1; then
RELEASE_VIEW_ERROR="$(mktemp)"
trap 'rm -f "$RELEASE_VIEW_ERROR"' EXIT
if gh release view "$RELEASE_TAG" --repo "$GITHUB_REPOSITORY" >/dev/null 2>"$RELEASE_VIEW_ERROR"; then
RELEASE_EXISTS=true
else
RELEASE_VIEW_STATUS=$?
if [[ "$RELEASE_VIEW_STATUS" -eq 1 ]] && grep -Eiq '(^|[^0-9])404([^0-9]|$)|release not found' "$RELEASE_VIEW_ERROR"; then
RELEASE_EXISTS=false
else
cat "$RELEASE_VIEW_ERROR" >&2
exit "$RELEASE_VIEW_STATUS"
fi
fi
if [[ "$RELEASE_EXISTS" == "true" ]]; then
if [[ "$UPDATE_EXISTING" != "true" ]]; then
echo "GitHub Release ${RELEASE_TAG} already exists. Rerun with update_existing=true to repair it." >&2
exit 1
@@ -26,4 +26,23 @@ describe("ClawHub CLI release workflows", () => {
expect(githubRelease).toContain("Publish artifact tarball URL does not match npm metadata.");
expect(githubRelease).toContain("Publish artifact integrity does not match npm metadata.");
});
it("does not treat arbitrary gh release view failures as a missing release", () => {
const githubRelease = readFileSync(
resolve(".github/workflows/clawhub-cli-github-release.yml"),
"utf8",
);
expect(githubRelease).toContain("RELEASE_VIEW_STATUS=$?");
expect(githubRelease).toContain(
`if [[ "$RELEASE_VIEW_STATUS" -eq 1 ]] && grep -Eiq '(^|[^0-9])404([^0-9]|$)|release not found' "$RELEASE_VIEW_ERROR"; then`,
);
expect(githubRelease).toContain('cat "$RELEASE_VIEW_ERROR" >&2');
expect(githubRelease).toContain('exit "$RELEASE_VIEW_STATUS"');
expect(githubRelease).toContain("RELEASE_EXISTS=false");
expect(githubRelease).toContain('gh release create "$RELEASE_TAG"');
expect(githubRelease).not.toContain(
'if gh release view "$RELEASE_TAG" --repo "$GITHUB_REPOSITORY" >/dev/null 2>&1; then',
);
});
});