Skip to content

Commit 0a1b974

Browse files
authored
Add script to aid in reviewing downstream pkl.impl.ghactions bump PRs (#52)
1 parent 9367a45 commit 0a1b974

File tree

3 files changed

+80
-21
lines changed

3 files changed

+80
-21
lines changed

scripts/approve_downstream_prs.sh

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#!/usr/bin/env bash
2+
3+
# This script will, for each Pkl repo, approve PRs created by ./update_downstream_ci.sh for the given version.
4+
#
5+
# Usage: ./approve_downstream_prs.sh
6+
7+
set -eo pipefail
8+
9+
MY_GIT_USER="$(gh api user --jq '.login')"
10+
11+
if [[ -z "$MY_GIT_USER" ]]; then
12+
echo "Could not determine the current user in gh. Try running \`gh auth login\`."
13+
exit 1
14+
fi
15+
16+
SCRIPT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
17+
18+
source "$SCRIPT_DIR/repos.sh"
19+
20+
VERSION=$(
21+
curl -s https://api.github.com/repos/apple/pkl-project-commons/releases \
22+
| jq -r '[.[] | select(.tag_name | startswith("pkl.impl.ghactions"))] | .[0].name | split("@")[1]'
23+
)
24+
25+
echo "Latest pkl.impl.ghactions version: $VERSION"
26+
27+
find_pr_and_approve() {
28+
repo="$1"
29+
pr_number="$(gh pr list --repo "apple/$repo" --json title,number \
30+
| jq --arg VERSION $VERSION \
31+
'.[]
32+
| select(.title == "Bump pkl.impl.ghactions to version \($VERSION)")
33+
| .number')"
34+
35+
if [ -z "$pr_number" ]; then
36+
echo "✅ No PR to approve for $repo"
37+
return 0
38+
fi
39+
40+
existing_approvals="$(GH_PAGER='' gh pr view --repo "apple/$repo" "$pr_number" --json reviews | \
41+
jq --arg MY_GIT_USER $MY_GIT_USER \
42+
'.reviews | map(select(.author.login == $MY_GIT_USER and .state == "APPROVED")) | length')"
43+
if [ "$existing_approvals" != "0" ]; then
44+
echo "✅ https://github.com/apple/$repo/pull/$pr_number already approved"
45+
return 0
46+
fi
47+
48+
echo "🔧 Approve https://github.com/apple/$repo/pull/$pr_number? Files changed:"
49+
GH_PAGER='' gh pr diff --name-only --repo "apple/$repo" "$pr_number"
50+
echo
51+
read -p "Press enter to approve or ^C to quit"
52+
gh pr review --repo "apple/$repo" "$pr_number" --approve
53+
echo ""
54+
}
55+
56+
for repo in "${REPOS[@]}"; do
57+
find_pr_and_approve "$repo"
58+
done

scripts/repos.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
REPOS=(
2+
"pkl"
3+
"pkl-go"
4+
"pkl-go-examples"
5+
"pkl-intellij"
6+
"pkl-jvm-examples"
7+
"pkl-k8s"
8+
"pkl-k8s-examples"
9+
"pkl-lang.org"
10+
"pkl-lsp"
11+
"pkl-neovim"
12+
"pkl-package-docs"
13+
"pkl-pantry"
14+
"pkl-spring"
15+
"pkl-swift"
16+
"pkl-swift-examples"
17+
"pkl-vscode"
18+
"pkl.tmbundle"
19+
"rules_pkl"
20+
"tree-sitter-pkl"
21+
)

scripts/update_downstream_ci.sh

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,27 +16,7 @@ fi
1616

1717
SCRIPT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
1818

19-
REPOS=(
20-
"pkl"
21-
"pkl-go"
22-
"pkl-go-examples"
23-
"pkl-intellij"
24-
"pkl-jvm-examples"
25-
"pkl-k8s"
26-
"pkl-k8s-examples"
27-
"pkl-lang.org"
28-
"pkl-lsp"
29-
"pkl-neovim"
30-
"pkl-package-docs"
31-
"pkl-pantry"
32-
"pkl-spring"
33-
"pkl-swift"
34-
"pkl-swift-examples"
35-
"pkl-vscode"
36-
"pkl.tmbundle"
37-
"rules_pkl"
38-
"tree-sitter-pkl"
39-
)
19+
source "$SCRIPT_DIR/repos.sh"
4020

4121
LATEST_PACKAGE_VERSION=$(
4222
curl -s https://api.github.com/repos/apple/pkl-project-commons/releases \

0 commit comments

Comments
 (0)