Skip to content

Commit 9514838

Browse files
authored
Add script that bumps pkl.impl.ghactions (#38)
This adds a script to bump package pkl.impl.ghactions, and generate pull requests for every Pkl repo.
1 parent d965ff5 commit 9514838

File tree

2 files changed

+153
-0
lines changed

2 files changed

+153
-0
lines changed

README.adoc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,15 @@ For example:
1414
----
1515
./scripts/publish_package.sh pkl.impl.ghactions
1616
----
17+
18+
== Updating `pkl.impl.ghactions`
19+
20+
There is a script in `./scripts/update_downstream_ci.sh` that auto-bumps the `pkl.impl.ghactions` package in every downstream repository.
21+
22+
This script should be run whenever a new package is published.
23+
24+
This tool assumes:
25+
26+
1. You have `pkl`, `jq`, and `gh` installed.
27+
2. You are logged into `gh`.
28+
3. You have every downstream repo forked onto your personal GitHub account.

scripts/update_downstream_ci.sh

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
#!/usr/bin/env bash
2+
# This script will, for each Pkl repo, bump the version of `pkl.impl.ghactions` to the latest version, and
3+
# create a GitHub pull request.
4+
# It assumes that every repo exists in a forked account.
5+
#
6+
# Usage: ./update_downstream_ci.sh
7+
8+
set -eo pipefail
9+
10+
MY_GIT_USER="$(gh api user --jq '.login')"
11+
12+
if [[ -z "$MY_GIT_USER" ]]; then
13+
echo "Could not determine the current user in gh. Try running \`gh auth login\`."
14+
exit 1
15+
fi
16+
17+
SCRIPT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
18+
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+
)
40+
41+
LATEST_PACKAGE_VERSION=$(
42+
curl -s https://api.github.com/repos/apple/pkl-project-commons/releases \
43+
| jq -r '[.[] | select(.tag_name | startswith("pkl.impl.ghactions"))] | .[0].name | split("@")[1]'
44+
)
45+
46+
echo "Latest pkl.impl.ghactions version: $LATEST_PACKAGE_VERSION"
47+
echo ""
48+
49+
declare -a CREATED_PRS
50+
declare -a SKIPPED_REPOS
51+
52+
function repo_dir() {
53+
echo "$SCRIPT_DIR/../build/update_downstream_ci/$1"
54+
}
55+
56+
function fetch_repo() {
57+
echo "📦 Fetching $1..."
58+
REPO_DIR="$(repo_dir "$1")"
59+
if [[ ! -d "$REPO_DIR" ]]; then
60+
git clone -o upstream "[email protected]:apple/$1.git" "$REPO_DIR" 2>&1 | grep -v "Cloning into" || true
61+
cd "$REPO_DIR"
62+
git remote add origin "[email protected]:$MY_GIT_USER/$1.git" 2>&1
63+
else
64+
cd "$REPO_DIR"
65+
git fetch upstream 2>&1 | grep -v "From github.com" || true
66+
git checkout main &> /dev/null
67+
git reset --hard upstream/main &> /dev/null
68+
fi
69+
}
70+
71+
function update_repo() {
72+
echo "🔧 Updating $1..."
73+
cd "$(repo_dir "$1")/.github"
74+
75+
# if bump-github-actions branch exists, and the PklProject there has the correct version, just exit early.
76+
if git show-ref --verify --quiet refs/heads/bump-github-actions; then
77+
git checkout bump-github-actions &> /dev/null || true
78+
if grep -q "pkl.impl.ghactions@$LATEST_PACKAGE_VERSION" PklProject; then
79+
echo "$1 already has the correct version $LATEST_PACKAGE_VERSION"
80+
SKIPPED_REPOS+=("$1 (already up to date)")
81+
return 0
82+
fi
83+
# wrong version, reset to upstream/main and continue
84+
git checkout main &> /dev/null || true
85+
git branch -D bump-github-actions &> /dev/null || true
86+
git reset --hard upstream/main &> /dev/null || true
87+
fi
88+
89+
sed -i '' -E "s|(package://pkg.pkl-lang.org/pkl-project-commons/pkl.impl.ghactions@)[0-9]+\.[0-9]+\.[0-9]+|\\1$LATEST_PACKAGE_VERSION|g" PklProject
90+
echo " Resolving dependencies..."
91+
pkl project resolve > /dev/null
92+
echo " Evaluating Pkl files..."
93+
pkl eval -m . index.pkl > /dev/null
94+
if [[ -z "$(git diff)" ]]; then
95+
echo "✅ Nothing to update for $1"
96+
SKIPPED_REPOS+=("$1 (no changes needed)")
97+
return 0
98+
fi
99+
echo " Creating branch and commit..."
100+
git co -b bump-github-actions &> /dev/null
101+
git add . &> /dev/null
102+
git commit -m "Bump pkl.impl.ghactions to version $LATEST_PACKAGE_VERSION" &> /dev/null
103+
echo " Pushing to origin..."
104+
git push -u origin bump-github-actions 2>&1 | grep -v "branch 'bump-github-actions' set up" || true
105+
echo " Creating pull request..."
106+
PR_URL=$(gh pr create --repo "apple/$1" --base main --head "$MY_GIT_USER:bump-github-actions" \
107+
--title "Bump pkl.impl.ghactions to version $LATEST_PACKAGE_VERSION" \
108+
--body "Updates pkl.impl.ghactions package to version $LATEST_PACKAGE_VERSION" 2>&1 | grep "https://")
109+
echo "$PR_URL"
110+
CREATED_PRS+=("$1|$PR_URL")
111+
echo "✅ Successfully created PR for $1"
112+
}
113+
114+
for repo in "${REPOS[@]}"; do
115+
fetch_repo "$repo"
116+
update_repo "$repo"
117+
echo ""
118+
done
119+
120+
echo "═══════════════════════════════════════════════════════════════"
121+
echo "Summary"
122+
echo "═══════════════════════════════════════════════════════════════"
123+
echo ""
124+
125+
if [[ ${#CREATED_PRS[@]} -gt 0 ]]; then
126+
echo "Pull Requests Created (${#CREATED_PRS[@]}):"
127+
for pr_info in "${CREATED_PRS[@]}"; do
128+
IFS='|' read -r repo url <<< "$pr_info"
129+
echo "$repo"
130+
echo " $url"
131+
done
132+
echo ""
133+
fi
134+
135+
if [[ ${#SKIPPED_REPOS[@]} -gt 0 ]]; then
136+
echo "Skipped (${#SKIPPED_REPOS[@]}):"
137+
for skip_info in "${SKIPPED_REPOS[@]}"; do
138+
echo "$skip_info"
139+
done
140+
echo ""
141+
fi

0 commit comments

Comments
 (0)