From a32fc12340c1b4ab090bc1150e92a59d266f1971 Mon Sep 17 00:00:00 2001 From: Jeffrey Johnson Date: Mon, 19 Oct 2026 13:14:53 -0700 Subject: [PATCH] fix(downstream-upgrade): reserve sync stdout for PR number --- scripts/downstream-upgrade/pr-sync.sh | 5 +++-- .../downstream-upgrade/tests/test_pr_sync.sh | 22 ++++++++++++++++--- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/scripts/downstream-upgrade/pr-sync.sh b/scripts/downstream-upgrade/pr-sync.sh index 92f8e183..6a7dac02 100755 --- a/scripts/downstream-upgrade/pr-sync.sh +++ b/scripts/downstream-upgrade/pr-sync.sh @@ -33,11 +33,12 @@ case "${1:?usage: pr-sync.sh }" in BODY_FILE="${3:?sync }" TITLE="chore(deps): upgrade @fiestaboard/ui to v$VERSION" pr=$(open_pr) + # Keep stdout reserved for the PR number captured by the workflow. if [ -n "$pr" ]; then - "$GH_BIN" pr edit "$pr" -R "$REPO" --title "$TITLE" --body-file "$BODY_FILE" + "$GH_BIN" pr edit "$pr" -R "$REPO" --title "$TITLE" --body-file "$BODY_FILE" >&2 else "$GH_BIN" pr create -R "$REPO" --head "$BRANCH" --base main \ - --title "$TITLE" --body-file "$BODY_FILE" --label upgrade-pending + --title "$TITLE" --body-file "$BODY_FILE" --label upgrade-pending >&2 pr=$(open_pr) fi echo "$pr" diff --git a/scripts/downstream-upgrade/tests/test_pr_sync.sh b/scripts/downstream-upgrade/tests/test_pr_sync.sh index 9cd15ba5..c9ff58e9 100755 --- a/scripts/downstream-upgrade/tests/test_pr_sync.sh +++ b/scripts/downstream-upgrade/tests/test_pr_sync.sh @@ -9,7 +9,20 @@ mkdir -p "$tmp/bin" cat > "$tmp/bin/gh" <> "$tmp/gh-calls.log" -if [ "\$1 \$2" = "pr list" ]; then printf '%s' "\$PR_LIST_OUTPUT"; fi +case "\$1 \$2" in + "pr list") + if [ -f "$tmp/created-pr" ]; then + echo 8 + else + printf '%s' "\$PR_LIST_OUTPUT" + fi + ;; + "pr create") + touch "$tmp/created-pr" + echo "https://github.com/acme/app/pull/8" + ;; + "pr edit") echo "https://github.com/acme/app/pull/\$3" ;; +esac EOF chmod +x "$tmp/bin/gh" @@ -18,14 +31,17 @@ echo "release notes" > "$tmp/body.md" # No open PR → create. : > "$tmp/gh-calls.log" -PR_LIST_OUTPUT="" run sync 0.4.0 "$tmp/body.md" > /dev/null +pr=$(PR_LIST_OUTPUT="" run sync 0.4.0 "$tmp/body.md") +assert_eq "8" "$pr" "sync stdout is only the created PR number" assert_file_contains "$tmp/gh-calls.log" "pr create" "creates when none open" assert_file_contains "$tmp/gh-calls.log" "upgrade-pending" "initial label applied" assert_file_contains "$tmp/gh-calls.log" "chore(deps): upgrade @fiestaboard/ui to v0.4.0" "title has version" # Open PR #7 → edit, not create. +rm "$tmp/created-pr" : > "$tmp/gh-calls.log" -PR_LIST_OUTPUT="7" run sync 0.5.0 "$tmp/body.md" > /dev/null +pr=$(PR_LIST_OUTPUT="7" run sync 0.5.0 "$tmp/body.md") +assert_eq "7" "$pr" "sync stdout is only the existing PR number" assert_file_contains "$tmp/gh-calls.log" "pr edit 7" "edits existing PR" if grep -q "pr create" "$tmp/gh-calls.log"; then fail "must not create when PR open"; fi