Skip to content

Commit a1e4273

Browse files
authored
Merge pull request #2202 from Kobzol/pull-ci
2 parents 06c7682 + 4c02798 commit a1e4273

File tree

3 files changed

+73
-0
lines changed

3 files changed

+73
-0
lines changed

Diff for: .github/workflows/rustc-pull.yml

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: rustc-pull
2+
3+
on:
4+
workflow_dispatch:
5+
schedule:
6+
# Run at 04:00 UTC every Monday
7+
- cron: '0 4 * * 1'
8+
9+
jobs:
10+
pull:
11+
if: github.repository == 'rust-lang/rustc-dev-guide'
12+
runs-on: ubuntu-latest
13+
permissions:
14+
contents: write
15+
pull-requests: write
16+
steps:
17+
- uses: actions/checkout@v4
18+
with:
19+
# We need the full history for josh to work
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 the josh directory with checked out rustc
27+
cache-directories: "/home/runner/.cache/rustc-dev-guide-josh"
28+
- name: Install josh
29+
run: RUSTFLAGS="--cap-lints warn" cargo +stable install josh-proxy --git https://github.com/josh-project/josh --tag r24.10.04
30+
- name: Setup bot git name and email
31+
run: |
32+
git config --global user.name 'The rustc-dev-guide Cronjob Bot'
33+
git config --global user.email '[email protected]'
34+
- name: Perform rustc-pull
35+
run: cargo run --manifest-path josh-sync/Cargo.toml -- rustc-pull
36+
- name: Push changes to a branch
37+
run: |
38+
# Update a sticky branch that is used only for rustc pulls
39+
BRANCH="rustc-pull"
40+
git switch -c $BRANCH
41+
git push -u origin $BRANCH --force
42+
- name: Create pull request
43+
run: |
44+
# Check if an open pull request for an rustc pull update already exists
45+
# If it does, the previous push has just updated it
46+
# If not, we create it now
47+
RESULT=`gh pr list --author github-actions[bot] --state open -q 'map(select(.title=="Rustc pull update")) | length' --json title`
48+
if [[ "$RESULT" -eq 0 ]]; then
49+
echo "Creating new pull request"
50+
gh pr create -B master --title 'Rustc pull update' --body 'Latest update from rustc.'
51+
else
52+
echo "Updated existing pull request"
53+
fi
54+
env:
55+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Diff for: josh-sync/src/sync.rs

+15
Original file line numberDiff line numberDiff line change
@@ -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.");

Diff for: 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)