Skip to content

Subtree Update

Subtree Update #3

name: Subtree Update
on:
schedule:
- cron: '0 14 * * *' # Run at 14:00 UTC every day
workflow_dispatch:
defaults:
run:
shell: bash
jobs:
update-subtree-library:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Checkout Kani
uses: actions/checkout@v4
with:
repository: model-checking/kani
path: kani-tmp
- name: Fetch Kani toolchain version
run: |
cd kani-tmp
TOOLCHAIN_DATE=$(grep -oP 'channel = "nightly-\K\d{4}-\d{2}-\d{2}' rust-toolchain.toml)
COMMIT_HASH=$(curl https://static.rust-lang.org/dist/$TOOLCHAIN_DATE/channel-rust-nightly-git-commit-hash.txt)
if [ -z "$COMMIT_HASH" ]; then
echo "Could not find commit hash on static.rust-lang.org"
exit 1
fi
echo "Kani toolchain date: ${TOOLCHAIN_DATE}"
echo "TOOLCHAIN_DATE=${TOOLCHAIN_DATE}" >> $GITHUB_ENV
echo "Kani toolchain hash: ${COMMIT_HASH}"
echo "COMMIT_HASH=${COMMIT_HASH}" >> $GITHUB_ENV
cd ..
rm -r kani-tmp
- name: Update subtree/library locally
run: |
pushd ..
git clone [email protected]:newren/git-filter-repo
git clone https://github.com/rust-lang/rust rust-tmp
cd rust-tmp
# Ensure "upstream/master" branch contains the target commit
if ! git show ${COMMIT_HASH} --oneline --no-patch; then
echo "Rust commit ${COMMIT_HASH} cannot be found."
exit 1
fi
git checkout ${COMMIT_HASH}
../git-filter-repo/git-filter-repo --subdirectory-filter library --force
git checkout -b subtree/library
popd
git remote add rust-filtered ../rust-tmp/
git fetch rust-filtered
git checkout -b update-subtree/library rust-filtered/subtree/library
git rebase origin/subtree/library
- name: Create Pull Request
uses: peter-evans/create-pull-request@v7
with:
title: 'Update subtree/library'
body: |
This is an automated PR to update the subtree/library branch to the changes
up to and including ${{ env.COMMIT_HASH }} of ${{ env.TOOLCHAIN_DATE }}.
branch: update-subtree/library
delete-branch: true
base: subtree/library
- name: Merge subtree/library changes
run: |
SYNC_BRANCH="sync-$TOOLCHAIN_DATE"
git checkout -t -b ${SYNC_BRANCH} origin/main
git submodule update --init
# This command may fail, which will require human intervention.
if ! git subtree merge --prefix=library update-subtree/library --squash; then
echo "MERGE_CONFLICTS=yes" >> $GITHUB_ENV
git commit -a -m "Merge from $COMMIT_HASH with conflicts"
else
echo "MERGE_CONFLICTS=no" >> $GITHUB_ENV
fi
sed -i "s/^channel = \"nightly-.*\"/channel = \"${TOOLCHAIN_DATE}\"/" rust-toolchain.toml
git commit "Update toolchain to ${TOOLCHAIN_DATE}" rust-toolchain.toml
- name: Create Pull Request without conflicts
if: ${{ env.MERGE_CONFLICTS == 'no' }}
uses: peter-evans/create-pull-request@v7
with:
title: 'Merge subtree update'
body: |
This is an automated PR to merge library subtree updates
up to and including ${{ env.COMMIT_HASH }} of ${{ env.TOOLCHAIN_DATE }}
into main. This is a clean merge, no conflicts were detected.
delete-branch: true
- name: Create Pull Request with conflicts
if: ${{ env.MERGE_CONFLICTS == 'yes' }}
uses: peter-evans/create-pull-request@v7
with:
title: 'Merge subtree update'
body: |
This is an automated PR to merge library subtree updates
up to and including ${{ env.COMMIT_HASH }} of ${{ env.TOOLCHAIN_DATE }}
into main. `git merge` resulted in conflicts, which require manual resolution.
Files were commited with merge conflict markers.
delete-branch: true