From 79fda33cd1c700bd51da14a99a31dde901c13a07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ber=C3=A1nek?= Date: Tue, 7 Jan 2025 18:53:22 +0100 Subject: [PATCH 01/14] Add CI workflow for performing `rustc-pull` --- .github/workflows/rustc-pull.yml | 41 ++++++++++++++++++++++++++++++++ triagebot.toml | 3 +++ 2 files changed, 44 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..f7c529f13 --- /dev/null +++ b/.github/workflows/rustc-pull.yml @@ -0,0 +1,41 @@ +name: rustc-pull + +on: + workflow_dispatch: + pull_request: + 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: read + pull-requests: write + steps: + - uses: actions/checkout@v4 + - name: Install stable Rust toolchain + run: rustup update stable + - uses: Swatinem/rust-cache@v2 + with: + workspaces: "josh-sync" + - 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 'rustc-dev-guide@cron.bot' + - name: Perform rustc-pull + run: cargo run --manifest-path josh-sync/Cargo.toml -- rustc-pull + - name: Push changes to a branch + run: | + BRANCH="rustc-pull-$(date -u +%Y-%m-%d)" + git switch -c $BRANCH + git push -u origin $BRANCH + - name: Create pull request + run: | + gh pr create -B master --title 'Rustc pull update' --body 'Latest update from rustc.' +# 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] From 43c37f409bafd2ad87f88a14df8447b558ef5ab3 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 02/14] Check if there is anything to pull --- .github/workflows/rustc-pull.yml | 2 +- josh-sync/src/sync.rs | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/rustc-pull.yml b/.github/workflows/rustc-pull.yml index f7c529f13..9a068dc4e 100644 --- a/.github/workflows/rustc-pull.yml +++ b/.github/workflows/rustc-pull.yml @@ -1,4 +1,4 @@ -name: rustc-pull +name: rustc-pullx on: workflow_dispatch: 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 ef3a86cfd3921741f8037a909391b72f363520b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ber=C3=A1nek?= Date: Wed, 8 Jan 2025 15:54:34 +0100 Subject: [PATCH 03/14] WIP --- .github/workflows/rustc-pull.yml | 11 +++++++---- josh-sync/src/sync.rs | 3 ++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/.github/workflows/rustc-pull.yml b/.github/workflows/rustc-pull.yml index 9a068dc4e..e49ffec5e 100644 --- a/.github/workflows/rustc-pull.yml +++ b/.github/workflows/rustc-pull.yml @@ -1,4 +1,4 @@ -name: rustc-pullx +name: rustc-pull on: workflow_dispatch: @@ -12,15 +12,18 @@ jobs: #if: github.repository == 'rust-lang/rustc-dev-guide' runs-on: ubuntu-latest permissions: - contents: read + contents: write pull-requests: write steps: - uses: actions/checkout@v4 + with: + fetch-depth: '0' - name: Install stable Rust toolchain run: rustup update stable - uses: Swatinem/rust-cache@v2 with: workspaces: "josh-sync" + 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 @@ -37,5 +40,5 @@ jobs: - name: Create pull request run: | gh pr create -B master --title 'Rustc pull update' --body 'Latest update from rustc.' -# env: -# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/josh-sync/src/sync.rs b/josh-sync/src/sync.rs index 1c1757a46..afd972191 100644 --- a/josh-sync/src/sync.rs +++ b/josh-sync/src/sync.rs @@ -9,7 +9,7 @@ use xshell::{cmd, Shell}; /// Used for rustc syncs. const JOSH_FILTER: &str = ":/src/doc/rustc-dev-guide"; const JOSH_PORT: u16 = 42042; -const UPSTREAM_REPO: &str = "rust-lang/rust"; +const UPSTREAM_REPO: &str = "kobzol/rust"; pub struct GitSync { dir: PathBuf, @@ -184,6 +184,7 @@ impl GitSync { directories::ProjectDirs::from("org", "rust-lang", "rustc-dev-guide-josh").unwrap(); user_dirs.cache_dir().to_owned() }; + eprintln!("Using cache dir at {}", local_dir.display()); // Start josh, silencing its output. let mut cmd = process::Command::new("josh-proxy"); From f60614ddf81cd2761e5f19f6b1ea62a08040fa79 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 04/14] Error if there is nothing to pull --- josh-sync/src/sync.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/josh-sync/src/sync.rs b/josh-sync/src/sync.rs index afd972191..ee4fa52e2 100644 --- a/josh-sync/src/sync.rs +++ b/josh-sync/src/sync.rs @@ -81,12 +81,19 @@ impl GitSync { }; let num_roots_before = num_roots()?; + let sha = cmd!(sh, "git rev-parse HEAD").run().context("FAILED to get current commit")?; + // 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").run().context("FAILED to get current commit")?; + if current_sha == sha { + return Err(anyhow::anyhow!("No merge was performed, nothing to pull")); + } + // 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 15805e67a2c997ab887af26c83401f989b45823d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ber=C3=A1nek?= Date: Wed, 8 Jan 2025 17:17:34 +0100 Subject: [PATCH 05/14] Preparing for merge from rustc --- rust-version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust-version b/rust-version index 651db7864..20000c1fe 100644 --- a/rust-version +++ b/rust-version @@ -1 +1 @@ -9c87288a7d2f03625a813df6d3bfe43c09ad4f5a +b6eb59a9337da9d2f317610c22b1275323e0ad0a From 5bb131025c59737f3c671e274ada7180209a7655 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ber=C3=A1nek?= Date: Wed, 8 Jan 2025 17:19:08 +0100 Subject: [PATCH 06/14] WIP --- .github/workflows/rustc-pull.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/rustc-pull.yml b/.github/workflows/rustc-pull.yml index e49ffec5e..aac0ca067 100644 --- a/.github/workflows/rustc-pull.yml +++ b/.github/workflows/rustc-pull.yml @@ -34,9 +34,9 @@ jobs: run: cargo run --manifest-path josh-sync/Cargo.toml -- rustc-pull - name: Push changes to a branch run: | - BRANCH="rustc-pull-$(date -u +%Y-%m-%d)" + BRANCH="rustc-pull" git switch -c $BRANCH - git push -u origin $BRANCH + git push -u origin $BRANCH --force - name: Create pull request run: | gh pr create -B master --title 'Rustc pull update' --body 'Latest update from rustc.' From 007fd8dc15dde4bc092a256d65a5e20614fc05f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ber=C3=A1nek?= Date: Wed, 8 Jan 2025 17:21:11 +0100 Subject: [PATCH 07/14] Clean up preparation commit if no pull was performed --- josh-sync/src/sync.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/josh-sync/src/sync.rs b/josh-sync/src/sync.rs index ee4fa52e2..9bccad490 100644 --- a/josh-sync/src/sync.rs +++ b/josh-sync/src/sync.rs @@ -91,7 +91,10 @@ impl GitSync { let current_sha = cmd!(sh, "git rev-parse HEAD").run().context("FAILED to get current commit")?; if current_sha == sha { - return Err(anyhow::anyhow!("No merge was performed, nothing to pull")); + 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. From 4a24d5d4817a51d292273148a306d30f50095c1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ber=C3=A1nek?= Date: Wed, 8 Jan 2025 17:22:44 +0100 Subject: [PATCH 08/14] Update RDG --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 7ce7d4ddf..219092c5d 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,6 @@ [![CI](https://github.com/rust-lang/rustc-dev-guide/actions/workflows/ci.yml/badge.svg)](https://github.com/rust-lang/rustc-dev-guide/actions/workflows/ci.yml) +# Update RDG This is a collaborative effort to build a guide that explains how rustc works. The aim of the guide is to help new contributors get oriented From 243a580cd67382e2ac298f31d8eca2b47e1ffa9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ber=C3=A1nek?= Date: Wed, 8 Jan 2025 17:21:29 +0100 Subject: [PATCH 09/14] WIP --- rust-version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust-version b/rust-version index 20000c1fe..8973951e3 100644 --- a/rust-version +++ b/rust-version @@ -1 +1 @@ -b6eb59a9337da9d2f317610c22b1275323e0ad0a +6afee111c2faf86ba884ea748967130abad37b52 From 7a75be5f89a12a8227095a73bf5fa4d3407e39fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ber=C3=A1nek?= Date: Wed, 8 Jan 2025 17:26:39 +0100 Subject: [PATCH 10/14] fixup! Clean up preparation commit if no pull was performed --- josh-sync/src/sync.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/josh-sync/src/sync.rs b/josh-sync/src/sync.rs index 9bccad490..cc1e10e5f 100644 --- a/josh-sync/src/sync.rs +++ b/josh-sync/src/sync.rs @@ -81,7 +81,7 @@ impl GitSync { }; let num_roots_before = num_roots()?; - let sha = cmd!(sh, "git rev-parse HEAD").run().context("FAILED to get current commit")?; + 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"; @@ -89,7 +89,7 @@ impl GitSync { .run() .context("FAILED to merge new commits, something went wrong")?; - let current_sha = cmd!(sh, "git rev-parse HEAD").run().context("FAILED to get current commit")?; + 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() From 3463e929a88aacdf15ab3af6520a743774fc6c9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ber=C3=A1nek?= Date: Wed, 8 Jan 2025 17:30:54 +0100 Subject: [PATCH 11/14] Add comment --- .github/workflows/rustc-pull.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/rustc-pull.yml b/.github/workflows/rustc-pull.yml index aac0ca067..a936a73dc 100644 --- a/.github/workflows/rustc-pull.yml +++ b/.github/workflows/rustc-pull.yml @@ -34,6 +34,7 @@ jobs: 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 for rustc pulls BRANCH="rustc-pull" git switch -c $BRANCH git push -u origin $BRANCH --force From 47be123324fd3222e803761fa42f86cd4a744966 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ber=C3=A1nek?= Date: Wed, 8 Jan 2025 17:44:38 +0100 Subject: [PATCH 12/14] Create PR conditionally --- .github/workflows/rustc-pull.yml | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/.github/workflows/rustc-pull.yml b/.github/workflows/rustc-pull.yml index a936a73dc..07cb1ac76 100644 --- a/.github/workflows/rustc-pull.yml +++ b/.github/workflows/rustc-pull.yml @@ -40,6 +40,15 @@ jobs: git push -u origin $BRANCH --force - name: Create pull request run: | - gh pr create -B master --title 'Rustc pull update' --body 'Latest update from rustc.' + # 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 }} From 15843e2cd686257ea28bbc0f760480176190b306 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ber=C3=A1nek?= Date: Wed, 8 Jan 2025 17:48:03 +0100 Subject: [PATCH 13/14] Update RDG2 --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 219092c5d..62148b4ca 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ [![CI](https://github.com/rust-lang/rustc-dev-guide/actions/workflows/ci.yml/badge.svg)](https://github.com/rust-lang/rustc-dev-guide/actions/workflows/ci.yml) # Update RDG +# Update RDG2 This is a collaborative effort to build a guide that explains how rustc works. The aim of the guide is to help new contributors get oriented From 5b957286c27ae21943cb3daa74b8baa6d8401891 Mon Sep 17 00:00:00 2001 From: The rustc-dev-guide Cronjob Bot Date: Wed, 8 Jan 2025 16:48:59 +0000 Subject: [PATCH 14/14] Preparing for merge from rustc --- rust-version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust-version b/rust-version index 8973951e3..d564ea5d2 100644 --- a/rust-version +++ b/rust-version @@ -1 +1 @@ -6afee111c2faf86ba884ea748967130abad37b52 +7a60097505d9d338a30ec6ead96ad8ff77c65e60