Skip to content

Rustc pull #2201

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 13 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions .github/workflows/rustc-pull.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
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: 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
run: |
git config --global user.name 'The rustc-dev-guide Cronjob Bot'
git config --global user.email '[email protected]'
- 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"
git switch -c $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.'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
18 changes: 17 additions & 1 deletion josh-sync/src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -76,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.");
Expand Down Expand Up @@ -179,6 +194,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");
Expand Down
2 changes: 1 addition & 1 deletion rust-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
9c87288a7d2f03625a813df6d3bfe43c09ad4f5a
e9d6f7ea1ecb467f8836e4695a9c41db28ba6804
3 changes: 3 additions & 0 deletions triagebot.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Loading