Skip to content

Commit 55c3455

Browse files
authored
Merge 7a75be5 into 7d59cb3
2 parents 7d59cb3 + 7a75be5 commit 55c3455

File tree

4 files changed

+65
-2
lines changed

4 files changed

+65
-2
lines changed

.github/workflows/rustc-pull.yml

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: rustc-pull
2+
3+
on:
4+
workflow_dispatch:
5+
pull_request:
6+
schedule:
7+
# Run at 04:00 UTC every Monday
8+
- cron: '0 4 * * 1'
9+
10+
jobs:
11+
pull:
12+
#if: github.repository == 'rust-lang/rustc-dev-guide'
13+
runs-on: ubuntu-latest
14+
permissions:
15+
contents: write
16+
pull-requests: write
17+
steps:
18+
- uses: actions/checkout@v4
19+
with:
20+
fetch-depth: '0'
21+
- name: Install stable Rust toolchain
22+
run: rustup update stable
23+
- uses: Swatinem/rust-cache@v2
24+
with:
25+
workspaces: "josh-sync"
26+
cache-directories: "/home/runner/.cache/rustc-dev-guide-josh"
27+
- name: Install Josh
28+
run: RUSTFLAGS="--cap-lints warn" cargo +stable install josh-proxy --git https://github.com/josh-project/josh --tag r24.10.04
29+
- name: Setup bot git name and email
30+
run: |
31+
git config --global user.name 'The rustc-dev-guide Cronjob Bot'
32+
git config --global user.email '[email protected]'
33+
- name: Perform rustc-pull
34+
run: cargo run --manifest-path josh-sync/Cargo.toml -- rustc-pull
35+
- name: Push changes to a branch
36+
run: |
37+
BRANCH="rustc-pull"
38+
git switch -c $BRANCH
39+
git push -u origin $BRANCH --force
40+
- name: Create pull request
41+
run: |
42+
gh pr create -B master --title 'Rustc pull update' --body 'Latest update from rustc.'
43+
env:
44+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

josh-sync/src/sync.rs

+17-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use xshell::{cmd, Shell};
99
/// Used for rustc syncs.
1010
const JOSH_FILTER: &str = ":/src/doc/rustc-dev-guide";
1111
const JOSH_PORT: u16 = 42042;
12-
const UPSTREAM_REPO: &str = "rust-lang/rust";
12+
const UPSTREAM_REPO: &str = "kobzol/rust";
1313

1414
pub struct GitSync {
1515
dir: PathBuf,
@@ -45,6 +45,11 @@ impl GitSync {
4545
let josh_url =
4646
format!("http://localhost:{JOSH_PORT}/{UPSTREAM_REPO}.git@{commit}{JOSH_FILTER}.git");
4747

48+
let previous_base_commit = sh.read_file("rust-version")?.trim().to_string();
49+
if previous_base_commit == commit {
50+
return Err(anyhow::anyhow!("No changes since last pull"));
51+
}
52+
4853
// Update rust-version file. As a separate commit, since making it part of
4954
// the merge has confused the heck out of josh in the past.
5055
// We pass `--no-verify` to avoid running git hooks.
@@ -76,12 +81,22 @@ impl GitSync {
7681
};
7782
let num_roots_before = num_roots()?;
7883

84+
let sha = cmd!(sh, "git rev-parse HEAD").output().context("FAILED to get current commit")?.stdout;
85+
7986
// Merge the fetched commit.
8087
const MERGE_COMMIT_MESSAGE: &str = "Merge from rustc";
8188
cmd!(sh, "git merge FETCH_HEAD --no-verify --no-ff -m {MERGE_COMMIT_MESSAGE}")
8289
.run()
8390
.context("FAILED to merge new commits, something went wrong")?;
8491

92+
let current_sha = cmd!(sh, "git rev-parse HEAD").output().context("FAILED to get current commit")?.stdout;
93+
if current_sha == sha {
94+
cmd!(sh, "git reset --hard HEAD^")
95+
.run()
96+
.expect("FAILED to clean up after creating the preparation commit");
97+
return Err(anyhow::anyhow!("No merge was performed, nothing to pull. Rolled back the preparation commit."));
98+
}
99+
85100
// Check that the number of roots did not increase.
86101
if num_roots()? != num_roots_before {
87102
bail!("Josh created a new root commit. This is probably not the history you want.");
@@ -179,6 +194,7 @@ impl GitSync {
179194
directories::ProjectDirs::from("org", "rust-lang", "rustc-dev-guide-josh").unwrap();
180195
user_dirs.cache_dir().to_owned()
181196
};
197+
eprintln!("Using cache dir at {}", local_dir.display());
182198

183199
// Start josh, silencing its output.
184200
let mut cmd = process::Command::new("josh-proxy");

rust-version

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
9c87288a7d2f03625a813df6d3bfe43c09ad4f5a
1+
6afee111c2faf86ba884ea748967130abad37b52

triagebot.toml

+3
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,6 @@ allow-unauthenticated = [
66
"waiting-on-author",
77
"blocked",
88
]
9+
10+
# Automatically close and reopen PRs made by bots to run CI on them
11+
[bot-pull-requests]

0 commit comments

Comments
 (0)