Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ffc4600

Browse files
authored
chore: improve script for running CI on community PRs (#6537)
The script now checks if some of the most common issues related to the prerequisites are met before continuing. A new `--check` option has also been added to check these prerequisites and then exit.
1 parent 8c2be9b commit ffc4600

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

scripts/run-ci-on-community-pr.sh

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,52 @@
22

33
set -euo pipefail
44

5-
PR_ID=${1:-}
5+
check_gh() {
6+
if ! command -v gh >/dev/null 2>&1; then
7+
echo "Error: GitHub CLI 'gh' is not installed. Install from https://cli.github.com and run 'gh auth login'."
8+
exit 1
9+
fi
10+
if ! gh auth status >/dev/null 2>&1; then
11+
echo "Error: GitHub CLI 'gh' is not authenticated. Run 'gh auth login' and ensure you can access the repository."
12+
exit 1
13+
fi
14+
if ! gh api user >/dev/null 2>&1; then
15+
echo "Error: 'gh' cannot access the GitHub API. Check your network or authentication."
16+
exit 1
17+
fi
18+
}
19+
20+
ARG=${1:-}
21+
if [ "${ARG}" = "--check" ] || [ "${ARG}" = "-c" ]; then
22+
check_gh
23+
USER_LOGIN=$(gh api user --jq .login)
24+
echo "GitHub CLI is installed and authenticated as: ${USER_LOGIN}"
25+
exit 0
26+
fi
27+
28+
PR_ID=${ARG}
629

730
if [ -z "$PR_ID" ]; then
831
echo "Usage: $0 <pr-id>"
32+
echo " $0 <options>"
933
echo
1034
echo "This will:"
1135
echo "1. Rebase the PR with its target branch, with each contained commit signed."
1236
echo "2. Create a temporary PR to allow running CI on the community PR."
1337
echo
38+
echo "Options:"
39+
echo " --check, -c Verify GitHub CLI installation and authentication, then exit."
40+
echo
1441
echo "Prerequisites:"
1542
echo "- You must have a GPG key configured to use with git."
1643
echo "- You must have write access to the PR."
44+
echo "- You must have the GitHub CLI installed."
1745
echo
1846
exit 1
1947
fi
2048

49+
check_gh
50+
2151
GITHUB_USER=$(gh api user --jq .login)
2252
BASE_COMMIT=$(gh pr view $PR_ID --json baseRefOid --jq '.baseRefOid')
2353
TEMP_BRANCH=$GITHUB_USER/tmp-ci-run-$PR_ID-$(date +%s)

0 commit comments

Comments
 (0)