Skip to content

Commit 00ca764

Browse files
committed
Automate subtree update
There should not be a need for manual processes for the first stage of the subtree update, i.e., updating our subtree/library branch. Merge conflicts (which might require a human to intervene) will only happen once attempting to merge from subtree/library back into main. Automation for this stage has been added, will create a PR separate from the above one, and will likely require manual intervention.
1 parent b410f4e commit 00ca764

File tree

1 file changed

+147
-0
lines changed

1 file changed

+147
-0
lines changed

.github/workflows/update-subtree.yml

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
name: Subtree Update
2+
3+
on:
4+
schedule:
5+
- cron: '0 14 * * *' # Run at 14:00 UTC every day
6+
workflow_dispatch:
7+
8+
defaults:
9+
run:
10+
shell: bash
11+
12+
jobs:
13+
update-subtree-library:
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- name: Checkout Repository
18+
uses: actions/checkout@v4
19+
with:
20+
fetch-depth: 0
21+
path: verify-rust-std
22+
submodules: true
23+
24+
- name: Checkout Kani
25+
uses: actions/checkout@v4
26+
with:
27+
repository: model-checking/kani
28+
path: kani-tmp
29+
30+
- name: Checkout Rust
31+
uses: actions/checkout@v4
32+
with:
33+
repository: rust-lang/rust
34+
fetch-depth: 0
35+
path: rust-tmp
36+
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+
43+
- name: Fetch Kani toolchain version
44+
run: |
45+
cd kani-tmp
46+
TOOLCHAIN_DATE=$(grep -oP 'channel = "nightly-\K\d{4}-\d{2}-\d{2}' rust-toolchain.toml)
47+
COMMIT_HASH=$(curl https://static.rust-lang.org/dist/$TOOLCHAIN_DATE/channel-rust-nightly-git-commit-hash.txt)
48+
if [ -z "$COMMIT_HASH" ]; then
49+
echo "Could not find commit hash on static.rust-lang.org"
50+
exit 1
51+
fi
52+
echo "Kani toolchain date: ${TOOLCHAIN_DATE}"
53+
echo "TOOLCHAIN_DATE=${TOOLCHAIN_DATE}" >> $GITHUB_ENV
54+
echo "Kani toolchain hash: ${COMMIT_HASH}"
55+
echo "COMMIT_HASH=${COMMIT_HASH}" >> $GITHUB_ENV
56+
57+
- name: Update subtree/library locally
58+
run: |
59+
cd rust-tmp
60+
61+
# Ensure "upstream/master" branch contains the target commit
62+
if ! git show ${COMMIT_HASH} --oneline --no-patch; then
63+
echo "Rust commit ${COMMIT_HASH} cannot be found."
64+
exit 1
65+
fi
66+
67+
git checkout ${COMMIT_HASH}
68+
../git-filter-repo/git-filter-repo --subdirectory-filter library --force
69+
git checkout -b subtree/library
70+
71+
cd ../verify-rust-std
72+
git remote add rust-filtered ../rust-tmp/
73+
git fetch rust-filtered
74+
git checkout -b subtree/library rust-filtered/subtree/library
75+
SUBTREE_HEAD_MSG=$(git log --format=%s -n 1 origin/subtree/library)
76+
UPSTREAM_FROM=$(git log --grep="${SUBTREE_HEAD_MSG}" -n 1 --format=%H rust-filtered/subtree/library)
77+
UPSTREAM_HEAD=$(git log --format=%H -n 1 rust-filtered/subtree/library)
78+
if [ "${UPSTREAM_HEAD}" = "${UPSTREAM_FROM}" ]; then
79+
echo "Nothing to do, ${UPSTREAM_FROM} matches ${UPSTREAM_HEAD} (${SUBTREE_HEAD_MSG})"
80+
echo "MERGE_CONFLICTS=noop" >> $GITHUB_ENV
81+
else
82+
git branch --set-upstream-to=origin/subtree/library
83+
git -c user.name=gitbot -c user.email=git@bot rebase
84+
echo "MERGE_CONFLICTS=maybe" >> $GITHUB_ENV
85+
fi
86+
87+
- name: Create Pull Request
88+
if: ${{ env.MERGE_CONFLICTS != 'noop' }}
89+
uses: peter-evans/create-pull-request@v7
90+
with:
91+
title: 'Update subtree/library'
92+
body: |
93+
This is an automated PR to update the subtree/library branch to the changes
94+
up to and including ${{ env.COMMIT_HASH }} of ${{ env.TOOLCHAIN_DATE }}.
95+
branch: update-subtree/library
96+
delete-branch: true
97+
base: subtree/library
98+
path: verify-rust-std
99+
100+
- name: Merge subtree/library changes
101+
if: ${{ env.MERGE_CONFLICTS != 'noop' }}
102+
run: |
103+
cd verify-rust-std
104+
git checkout main
105+
106+
# This command may fail, which will require human intervention.
107+
if ! git \
108+
-c user.name=gitbot -c user.email=git@bot \
109+
subtree merge --prefix=library update-subtree/library --squash; then
110+
echo "MERGE_CONFLICTS=yes" >> $GITHUB_ENV
111+
git -c user.name=gitbot -c user.email=git@bot commit -a -m "Merge from $COMMIT_HASH with conflicts"
112+
else
113+
echo "MERGE_CONFLICTS=no" >> $GITHUB_ENV
114+
fi
115+
116+
sed -i "s/^channel = \"nightly-.*\"/channel = \"${TOOLCHAIN_DATE}\"/" rust-toolchain.toml
117+
git -c user.name=gitbot -c user.email=git@bot \
118+
commit -m "Update toolchain to ${TOOLCHAIN_DATE}" rust-toolchain.toml
119+
120+
- name: Create Pull Request without conflicts
121+
if: ${{ env.MERGE_CONFLICTS == 'no' }}
122+
uses: peter-evans/create-pull-request@v7
123+
with:
124+
title: 'Merge subtree update'
125+
body: |
126+
This is an automated PR to merge library subtree updates
127+
up to and including ${{ env.COMMIT_HASH }} of ${{ env.TOOLCHAIN_DATE }}
128+
into main. This is a clean merge, no conflicts were detected.
129+
branch: sync-${{ env.TOOLCHAIN_DATE }}
130+
delete-branch: true
131+
base: main
132+
path: verify-rust-std
133+
134+
- name: Create Pull Request with conflicts
135+
if: ${{ env.MERGE_CONFLICTS == 'yes' }}
136+
uses: peter-evans/create-pull-request@v7
137+
with:
138+
title: 'Merge subtree update'
139+
body: |
140+
This is an automated PR to merge library subtree updates
141+
up to and including ${{ env.COMMIT_HASH }} of ${{ env.TOOLCHAIN_DATE }}
142+
into main. `git merge` resulted in conflicts, which require manual resolution.
143+
Files were commited with merge conflict markers.
144+
branch: sync-${{ env.TOOLCHAIN_DATE }}
145+
delete-branch: true
146+
base: main
147+
path: verify-rust-std

0 commit comments

Comments
 (0)