You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Bug: gh api --paginate already concatenates paginated results into a single JSON array, so -s 'add' is wrong for single-file output.
When --paginate is used and output is redirected to a single file (> "$pr_response"), gh writes one combined JSON array (not one array per page). Applying jq -s slurps that one array into a wrapper array [[ ... ]], and then add flattens it back β this works accidentally, but it adds unnecessary complexity and is fragile if gh ever changes its paging output format. More importantly, the jq -e -s 'length > 0 and all(.[]; type == "array")' validation at line 366 implicitly depends on this wrapping behavior.
Dropping -s and removing add | makes both the validation and the transform cleaner and correct:
Reliability: Warning is emitted and sleep is executed even after the final (3rd) failed attempt.
The echo + sleep block runs unconditionally after every failed attempt, including the last one. After the 3rd attempt fails, the loop exits naturally and then waits an additional sleep 6 seconds before the if [[ "$pr_success" != "true" ]] block exits with failure. The sleep after the final attempt is wasted time.
Fix: guard the sleep behind a check that skips it on the last iteration.
π‘ Suggested Change
Before:
echo "::warning title=Retrying pull request evidence::GitHub PR metadata for commit $commit_sha was unavailable or malformed (attempt $attempt/3)." >&2
sleep "$((attempt * 2))"
After:
echo "::warning title=Retrying pull request evidence::GitHub PR metadata for commit $commit_sha was unavailable or malformed (attempt $attempt/3)." >&2
if [[ "$attempt" -lt 3 ]]; then
sleep "$((attempt * 2))"
fi
Security / correctness: Unvalidated commit_sha used in a filename and a URL path without sanitisation.
commit_sha is sourced from jq -r '.commits[].sha' release-assets/COMPARE.json, which is derived from a GitHub API response. While SHA values are expected to be hex strings, constructing a filesystem path (release-assets/PR_${commit_sha}.json) and embedding it directly in the API URL (/commits/${commit_sha}/pulls) without any validation leaves a small but real injection surface if the upstream JSON were ever tampered with or the field contained unexpected content (e.g. path-traversal characters like ../).
Consider validating the SHA with a regex guard before use:
The guard condition length > 0 and all(.[]; type == "array") (with -s slurp) treats an empty JSON array [] from the GitHub API as invalid and triggers a retry. However, an empty array is a legitimate response when a commit has no associated pull requests (e.g., direct pushes). This means every such commit will exhaust all 3 attempts and then exit 1, aborting the release workflow even though no real error occurred.
The intent of the check appears to be detecting a truncated/corrupt response (e.g., gh wrote nothing or wrote malformed JSON). A better check would simply validate that the file is well-formed JSON without requiring it to be non-empty:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes a failure in GitHub Draft Release v2 when building the complete release snapshot because a GitHub commit-to-PR API response was truncated.
Changes
Validation
npm run test:release-workflow -- --run: 31 tests passed, including 21 release workflow tests.PULL_REQUESTS.json.