Sync with upstream #380
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
on: | |
schedule: | |
# 1:05 past midnight UTC | |
- cron: "5 1 * * *" | |
name: "Sync with upstream" | |
jobs: | |
sync: | |
name: "Sync" | |
runs-on: "ubuntu-latest" | |
env: | |
DEFAULT_BRANCH: "main" | |
steps: | |
# https://github.com/actions/runner-images/issues/2840#issuecomment-790492173 | |
- name: "Free up disk space" | |
run: | | |
sudo rm -rf /usr/share/dotnet | |
sudo rm -rf /opt/ghc | |
sudo rm -rf "/usr/local/share/boost" | |
sudo rm -rf "$AGENT_TOOLSDIRECTORY" | |
- name: "Checkout source code" | |
uses: "actions/checkout@v3" | |
with: | |
# Subsequent actions are not triggered unless using PAT | |
token: "${{ secrets.GH_PAT }}" | |
fetch-depth: 0 | |
submodules: true | |
- name: "Setup toolchain" | |
uses: "actions-rs/toolchain@v1" | |
with: | |
toolchain: "stable" | |
profile: "minimal" | |
override: true | |
- uses: "Swatinem/rust-cache@v1" | |
with: | |
cache-on-failure: true | |
- name: "Install protoc" | |
uses: "Noelware/[email protected]" | |
- name: "Config Git" | |
run: | | |
git config user.name "Jonathan LEI" | |
git config user.email "[email protected]" | |
- name: "Update branch" | |
run: | | |
git fetch origin | |
git remote add upstream https://github.com/eqlabs/pathfinder | |
git fetch upstream --no-tags | |
MERGE_BASE=$(git merge-base origin/$DEFAULT_BRANCH upstream/$DEFAULT_BRANCH) | |
# Don't force push unnecessarily unless changes are detected | |
if [[ $(git rev-list $MERGE_BASE..upstream/$DEFAULT_BRANCH | wc -l) -ne 0 ]]; then | |
# Brings files from `home` to default branch | |
git checkout $DEFAULT_BRANCH | |
git reset --hard upstream/$DEFAULT_BRANCH | |
git checkout origin/home . | |
git add . | |
git commit -m "chore: README and CI changes" | |
# Here, we pick commits on the default branch except the first one. We do this instead | |
# of a naive rebase because the `home` branch might have changed, causing merge | |
# conflicts. | |
COMMIT_COUNT=$(git rev-list $MERGE_BASE..origin/$DEFAULT_BRANCH | wc -l) | |
git cherry-pick origin/$DEFAULT_BRANCH~$(($COMMIT_COUNT-1))..origin/$DEFAULT_BRANCH | |
# Makes sure the updated local branch builds | |
cargo build --all --all-targets | |
# Push updated branch | |
git push --force-with-lease | |
else | |
echo "No changes detected on upstream $DEFAULT_BRANCH" | |
fi |