Skip to content

Commit ff7f6d2

Browse files
committed
Subtree update automation: use fast version of subtree split
repo-filter does not produce consistent SHA hashes. While we were aware of this, we hadn't realized that this made incremental non-interactive updates of the branch a matter of luck as git may or may not be able to automatically resolve conflicts. (It worked for the update to 2025-02-10, but failed for the next one.) git-subtree-split does produce consistent SHA hashes, but the native `git-subtree-split` implementation is a shell script, and thus was found to be too slow (which is why we chose repo-filter in the first place). splitsh-lite is an implementation of just the `subtree split` command in Go and libgit2. This makes `subtree split` even faster than `repo-filter` at 35 seconds vs 50 seconds (on a GitHub runner).
1 parent 4cec565 commit ff7f6d2

File tree

1 file changed

+34
-14
lines changed

1 file changed

+34
-14
lines changed

.github/workflows/update-subtree.yml

+34-14
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ defaults:
1111

1212
jobs:
1313
update-subtree-library:
14-
runs-on: ubuntu-latest
14+
# Changing the host platform may alter the libgit2 version as used by
15+
# splitsh-lite, which will require changing the version of git2go.
16+
# See https://github.com/jeffWelling/git2go?tab=readme-ov-file#which-go-version-to-use
17+
runs-on: ubuntu-24.04
1518

1619
steps:
1720
- name: Checkout Repository
@@ -34,12 +37,6 @@ jobs:
3437
fetch-depth: 0
3538
path: rust-tmp
3639

37-
- name: Checkout git-filter-repo
38-
uses: actions/checkout@v4
39-
with:
40-
repository: newren/git-filter-repo
41-
path: git-filter-repo
42-
4340
- name: Fetch toolchain versions
4441
run: |
4542
CURRENT_TOOLCHAIN_DATE=$(grep -oP 'channel = "nightly-\K\d{4}-\d{2}-\d{2}' verify-rust-std/rust-toolchain.toml)
@@ -77,6 +74,30 @@ jobs:
7774
env:
7875
GH_TOKEN: ${{ github.token }}
7976

77+
- name: Checkout splitsh-lite
78+
if: ${{ env.SUBTREE_PR_EXISTS == 'no' }}
79+
uses: actions/checkout@v4
80+
with:
81+
repository: splitsh/lite
82+
path: splitsh-lite
83+
84+
- name: Build splitsh-lite
85+
if: ${{ env.SUBTREE_PR_EXISTS == 'no' }}
86+
run: |
87+
cd splitsh-lite
88+
sudo apt-get install -y golang libgit2-dev
89+
# git2go upstream hasn't been updated to more recent versions of
90+
# libgit2, so using a fork that does stay up to date
91+
sed -i 's#github.com/libgit2/git2go#github.com/jeffwelling/git2go#' go.mod splitter/*
92+
# may need to adjust "v37" to a higher number per
93+
# https://github.com/jeffWelling/git2go?tab=readme-ov-file#which-go-version-to-use
94+
# depening on the libgit2 version being installed
95+
sed -i -e 's/v34/v37/g' go.mod splitter/*.go
96+
# v37.0.0 had issues that weren't fully fixed until v37.0.4
97+
sed -i 's/v37.0.0/v37.0.4/' go.mod
98+
go mod tidy
99+
go build -o splitsh-lite github.com/splitsh/lite
100+
80101
- name: Update subtree/library locally
81102
if: ${{ env.SUBTREE_PR_EXISTS == 'no' }}
82103
run: |
@@ -89,16 +110,13 @@ jobs:
89110
fi
90111
91112
git checkout ${NEXT_COMMIT_HASH}
92-
../git-filter-repo/git-filter-repo --subdirectory-filter library --force
93-
git checkout -b subtree/library
113+
/usr/bin/time -v ../splitsh-lite/splitsh-lite --progress --prefix=library --target subtree/library
114+
git checkout -b subtree/library subtree/library
94115
95116
cd ../verify-rust-std
96117
git remote add rust-filtered ../rust-tmp/
97118
git fetch rust-filtered
98119
git checkout -b subtree/library rust-filtered/subtree/library
99-
# The filter-subtree operation adds an extraneous `library/` folder containing the submodules
100-
# (c.f. https://github.com/model-checking/verify-rust-std/issues/249), so remove that before committing.
101-
rm -rf library
102120
SUBTREE_HEAD_MSG=$(git log --format=%s -n 1 origin/subtree/library)
103121
UPSTREAM_FROM=$(git log --grep="${SUBTREE_HEAD_MSG}" -n 1 --format=%H rust-filtered/subtree/library)
104122
UPSTREAM_HEAD=$(git log --format=%H -n 1 rust-filtered/subtree/library)
@@ -107,7 +125,6 @@ jobs:
107125
echo "MERGE_CONFLICTS=noop" >> $GITHUB_ENV
108126
else
109127
git branch --set-upstream-to=origin/subtree/library
110-
git -c user.name=gitbot -c user.email=git@bot rebase
111128
echo "MERGE_CONFLICTS=maybe" >> $GITHUB_ENV
112129
fi
113130
@@ -130,12 +147,15 @@ jobs:
130147
if: ${{ env.MERGE_CONFLICTS != 'noop' && env.MERGE_PR_EXISTS == 'no' }}
131148
run: |
132149
cd verify-rust-std
150+
if ! git rev-parse --verify subtree/library; then
151+
git checkout -t -b subtree/library origin/update-subtree/library
152+
fi
133153
git checkout main
134154
135155
# This command may fail, which will require human intervention.
136156
if ! git \
137157
-c user.name=gitbot -c user.email=git@bot \
138-
subtree merge --prefix=library update-subtree/library --squash; then
158+
subtree merge --prefix=library subtree/library --squash; then
139159
echo "MERGE_CONFLICTS=yes" >> $GITHUB_ENV
140160
git -c user.name=gitbot -c user.email=git@bot commit -a -m "Merge from $NEXT_COMMIT_HASH with conflicts"
141161
else

0 commit comments

Comments
 (0)