From c92957d38a6486dbcb7ac0668e4b24b02f94ccbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ber=C3=A1nek?= Date: Wed, 8 Jan 2025 15:26:14 +0100 Subject: [PATCH 1/3] Print an explicit message if the base repo head commit is up-to-date --- josh-sync/src/sync.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/josh-sync/src/sync.rs b/josh-sync/src/sync.rs index da21a4c9a..1c1757a46 100644 --- a/josh-sync/src/sync.rs +++ b/josh-sync/src/sync.rs @@ -45,6 +45,11 @@ impl GitSync { let josh_url = format!("http://localhost:{JOSH_PORT}/{UPSTREAM_REPO}.git@{commit}{JOSH_FILTER}.git"); + let previous_base_commit = sh.read_file("rust-version")?.trim().to_string(); + if previous_base_commit == commit { + return Err(anyhow::anyhow!("No changes since last pull")); + } + // Update rust-version file. As a separate commit, since making it part of // the merge has confused the heck out of josh in the past. // We pass `--no-verify` to avoid running git hooks. From 482ebfbbae7d4a4b20b25378c4ba2d13a1734101 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ber=C3=A1nek?= Date: Wed, 8 Jan 2025 17:17:03 +0100 Subject: [PATCH 2/3] Error if there is nothing to pull --- josh-sync/src/sync.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/josh-sync/src/sync.rs b/josh-sync/src/sync.rs index 1c1757a46..eff80b109 100644 --- a/josh-sync/src/sync.rs +++ b/josh-sync/src/sync.rs @@ -81,12 +81,22 @@ impl GitSync { }; let num_roots_before = num_roots()?; + let sha = cmd!(sh, "git rev-parse HEAD").output().context("FAILED to get current commit")?.stdout; + // Merge the fetched commit. const MERGE_COMMIT_MESSAGE: &str = "Merge from rustc"; cmd!(sh, "git merge FETCH_HEAD --no-verify --no-ff -m {MERGE_COMMIT_MESSAGE}") .run() .context("FAILED to merge new commits, something went wrong")?; + let current_sha = cmd!(sh, "git rev-parse HEAD").output().context("FAILED to get current commit")?.stdout; + if current_sha == sha { + cmd!(sh, "git reset --hard HEAD^") + .run() + .expect("FAILED to clean up after creating the preparation commit"); + return Err(anyhow::anyhow!("No merge was performed, nothing to pull. Rolled back the preparation commit.")); + } + // Check that the number of roots did not increase. if num_roots()? != num_roots_before { bail!("Josh created a new root commit. This is probably not the history you want."); From 4c02798cb44de021b8fffd056bc3a138f9329840 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ber=C3=A1nek?= Date: Wed, 8 Jan 2025 17:54:02 +0100 Subject: [PATCH 3/3] Add CI workflow for performing rustc-pull --- .github/workflows/rustc-pull.yml | 55 ++++++++++++++++++++++++++++++++ triagebot.toml | 3 ++ 2 files changed, 58 insertions(+) create mode 100644 .github/workflows/rustc-pull.yml diff --git a/.github/workflows/rustc-pull.yml b/.github/workflows/rustc-pull.yml new file mode 100644 index 000000000..dcb90b84d --- /dev/null +++ b/.github/workflows/rustc-pull.yml @@ -0,0 +1,55 @@ +name: rustc-pull + +on: + workflow_dispatch: + schedule: + # Run at 04:00 UTC every Monday + - cron: '0 4 * * 1' + +jobs: + pull: + if: github.repository == 'rust-lang/rustc-dev-guide' + runs-on: ubuntu-latest + permissions: + contents: write + pull-requests: write + steps: + - uses: actions/checkout@v4 + with: + # We need the full history for josh to work + fetch-depth: '0' + - name: Install stable Rust toolchain + run: rustup update stable + - uses: Swatinem/rust-cache@v2 + with: + workspaces: "josh-sync" + # Cache the josh directory with checked out rustc + cache-directories: "/home/runner/.cache/rustc-dev-guide-josh" + - name: Install josh + run: RUSTFLAGS="--cap-lints warn" cargo +stable install josh-proxy --git https://github.com/josh-project/josh --tag r24.10.04 + - name: Setup bot git name and email + run: | + git config --global user.name 'The rustc-dev-guide Cronjob Bot' + git config --global user.email 'github-actions@github.com' + - name: Perform rustc-pull + run: cargo run --manifest-path josh-sync/Cargo.toml -- rustc-pull + - name: Push changes to a branch + run: | + # Update a sticky branch that is used only for rustc pulls + BRANCH="rustc-pull" + git switch -c $BRANCH + git push -u origin $BRANCH --force + - name: Create pull request + run: | + # Check if an open pull request for an rustc pull update already exists + # If it does, the previous push has just updated it + # If not, we create it now + RESULT=`gh pr list --author github-actions[bot] --state open -q 'map(select(.title=="Rustc pull update")) | length' --json title` + if [[ "$RESULT" -eq 0 ]]; then + echo "Creating new pull request" + gh pr create -B master --title 'Rustc pull update' --body 'Latest update from rustc.' + else + echo "Updated existing pull request" + fi + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/triagebot.toml b/triagebot.toml index ccb0de862..12aa0b7b8 100644 --- a/triagebot.toml +++ b/triagebot.toml @@ -6,3 +6,6 @@ allow-unauthenticated = [ "waiting-on-author", "blocked", ] + +# Automatically close and reopen PRs made by bots to run CI on them +[bot-pull-requests]