Skip to content
Merged
Show file tree
Hide file tree
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
5 changes: 3 additions & 2 deletions scripts/downstream-upgrade/pr-sync.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,12 @@ case "${1:?usage: pr-sync.sh <ensure-labels|sync|set-state|comment>}" in
BODY_FILE="${3:?sync <version> <body-file>}"
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"
Expand Down
22 changes: 19 additions & 3 deletions scripts/downstream-upgrade/tests/test_pr_sync.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,20 @@ mkdir -p "$tmp/bin"
cat > "$tmp/bin/gh" <<EOF
#!/usr/bin/env bash
echo "\$@" >> "$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"

Expand All @@ -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

Expand Down
Loading