Skip to content

Commit 9b78af9

Browse files
authored
Add script to allow running CI on community PRs (#6016)
The script can be executed like so: ./scripts/run-ci-on-community-pr.sh <pr-id> It will do the following: 1. Rebase the community PR againt its target branch. 2. Sign all the commits in the community PR. 3. Create a temporary PR to allow running of CI in the community PR. The temporary PR can be closed once CI has completed running.
1 parent bc0b431 commit 9b78af9

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

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

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
PR_ID=${1:-}
6+
7+
if [ -z "$PR_ID" ]; then
8+
echo "Usage: $0 <pr-id>"
9+
echo
10+
echo "This will:"
11+
echo "1. Rebase the PR with its target branch, with each contained commit signed."
12+
echo "2. Create a temporary PR to allow running CI on the community PR."
13+
echo
14+
echo "Prerequisites:"
15+
echo "- You must have a GPG key configured to use with git."
16+
echo "- You must have write access to the PR."
17+
echo
18+
exit 1
19+
fi
20+
21+
GITHUB_USER=$(gh api user --jq .login)
22+
BASE_COMMIT=$(gh pr view $PR_ID --json baseRefOid --jq '.baseRefOid')
23+
TEMP_BRANCH=$GITHUB_USER/tmp-ci-run-$PR_ID-$(date +%s)
24+
WORKTREE_DIR=$(mktemp -d)
25+
ORIGINAL_DIR=$(pwd)
26+
27+
cleanup() {
28+
if [ -n "${WORKTREE_DIR:-}" ] && [ -d "$WORKTREE_DIR" ]; then
29+
cd "$ORIGINAL_DIR" 2>/dev/null || true
30+
git worktree remove "$WORKTREE_DIR" 2>/dev/null || true
31+
fi
32+
}
33+
34+
trap cleanup EXIT ERR INT
35+
36+
git worktree add $WORKTREE_DIR
37+
cd $WORKTREE_DIR
38+
39+
git fetch origin
40+
gh pr checkout $PR_ID
41+
git rebase --gpg-sign $BASE_COMMIT
42+
git push --force
43+
git push origin HEAD:$TEMP_BRANCH
44+
45+
gh pr create \
46+
--head $TEMP_BRANCH \
47+
--draft \
48+
--label "semver-patch" \
49+
--title "Temp: Run CI on community PR #$PR_ID" \
50+
--body "This is a temporary PR to allow running CI on the community PR #$PR_ID. It should be closed after CI has completed running."
51+
gh pr view $TEMP_BRANCH --web

0 commit comments

Comments
 (0)