GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — tools: improve commit queue failure comment · nodejs/node@a457631

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • tools/actions
    • commit-queue.sh
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎tools/actions/commit-queue.sh‎

Copy file name to clipboardExpand all lines: tools/actions/commit-queue.sh
+56-4Lines changed: 56 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,62 @@ COMMIT_QUEUE_FAILED_LABEL="commit-queue-failed"
1010

1111
cqurl="${GITHUB_SERVER_URL:?}/${GITHUB_REPOSITORY:?}/actions/runs/${GITHUB_RUN_ID:?}"
1212

13+
escape_code_block_or_line() {
14+
case $1 in
15+
*"
16+
"*|'') fence='```' sep='
17+
' ;;
18+
*[![:space:]]*) fence='`' sep=' ' ;;
19+
*) fence='`' sep='' ;;
20+
esac
21+
while case $1 in *"$fence"*) ;; *) false ;; esac; do
22+
fence=$fence'`'
23+
done
24+
printf '%s%s%s%s%s\n' "$fence" "$sep" "$1" "$sep" "$fence"
25+
}
26+
1327
commit_queue_failed() {
1428
pr=$1
29+
reported_failure=${2:-}
1530

1631
gh -R "$GITHUB_REPOSITORY" pr edit "$pr" --add-label "${COMMIT_QUEUE_FAILED_LABEL}" --remove-label "${COMMIT_QUEUE_LABEL}"
1732

18-
body="<details><summary>Commit Queue failed</summary><pre>$(sed -e 's/&/\&amp;/g' -e 's/</\&lt;/g' -e 's/>/\&gt;/g' output)</pre><a href='$cqurl'>$cqurl</a></details>"
33+
last_output_line=$(awk 'NF { line = $0 } END { sub(/^[[:space:]]*/, "", line); print line }' output)
34+
# shellcheck disable=SC2016
35+
missing_policy_message='ℹ Add `commit-queue-squash` label to land the PR as one commit, or `commit-queue-rebase` to land as separate commits.'
36+
if [ "$last_output_line" = "$missing_policy_message" ]; then
37+
failure_body='This pull request has multiple commits, but no landing policy was selected.
38+
39+
Add https://github.com/nodejs/node/labels/commit-queue-squash to land it as one commit, or https://github.com/nodejs/node/labels/commit-queue-rebase to land the commits separately.'
40+
else
41+
if [ -z "$reported_failure" ]; then
42+
reported_failure=$(grep -e '✘' -e '⚠' output | tail -n 10)
43+
fi
44+
if [ -z "$reported_failure" ]; then
45+
reported_failure=$(tail -n 10 output)
46+
fi
47+
if [ -z "$reported_failure" ]; then
48+
reported_failure='No failure reason was reported.'
49+
fi
50+
failure_body=$(escape_code_block_or_line "$reported_failure")
51+
fi
52+
53+
raw_output=$(cat output)
54+
55+
body="### Commit Queue failed
56+
57+
$failure_body
58+
59+
The pull request was removed from the Commit Queue and labeled https://github.com/nodejs/node/labels/commit-queue-failed. After resolving the failure, remove that label and add https://github.com/nodejs/node/labels/commit-queue to retry.
60+
61+
<details>
62+
<summary>Full Commit Queue output</summary>
63+
64+
$(escape_code_block_or_line "$raw_output")
65+
66+
</details>
67+
68+
[View workflow run]($cqurl)"
1969
echo "$body"
2070

2171
gh -R "$GITHUB_REPOSITORY" pr comment "$pr" --body "$body"
@@ -63,7 +113,8 @@ for pr in "$@"; do
63113
commits="${start_sha}...${end_sha}"
64114

65115
if ! git push $UPSTREAM $DEFAULT_BRANCH >> output 2>&1; then
66-
commit_queue_failed "$pr"
116+
commit_queue_failed "$pr" \
117+
"Failed to push the landed commits to ${UPSTREAM}/${DEFAULT_BRANCH}."
67118
continue
68119
fi
69120
else
@@ -80,9 +131,10 @@ for pr in "$@"; do
80131
--arg head "${commit_head}" \
81132
'{merge_method:"squash",commit_title:$title,commit_message:$body,sha:$head}' |\
82133
gh api -X PUT "repos/${GITHUB_REPOSITORY}/pulls/${pr}/merge" --input -\
83-
--jq 'if .merged then .sha else halt_error end'
134+
--jq 'if .merged then .sha else halt_error end' 2>> output
84135
)"; then
85-
commit_queue_failed "$pr"
136+
commit_queue_failed "$pr" \
137+
'GitHub failed to squash and merge this pull request.'
86138
continue
87139
fi
88140
fi

0 commit comments

Comments
0 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.