-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Add CI check to ensure that rustdoc JSON FORMAT_VERSION
is correctly updated
#142677
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
Open
GuillaumeGomez
wants to merge
3
commits into
rust-lang:master
Choose a base branch
from
GuillaumeGomez:check-format-version-update
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+95
−1
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -7,19 +7,49 @@ | |||
use std::collections::VecDeque; | ||||
use std::num::NonZeroUsize; | ||||
use std::path::PathBuf; | ||||
use std::process::Command; | ||||
use std::str::FromStr; | ||||
use std::sync::atomic::{AtomicBool, Ordering}; | ||||
use std::thread::{self, ScopedJoinHandle, scope}; | ||||
use std::{env, process}; | ||||
|
||||
use tidy::*; | ||||
|
||||
// We set the `BASE_COMMIT` environment variable | ||||
fn set_env_base_commit() { | ||||
if let Ok(base_commit) = env::var("BASE_COMMIT") { | ||||
// Nothing to be done! | ||||
println!("base commit is {base_commit}"); | ||||
return; | ||||
} | ||||
// If first commit is from `[email protected]`, then we need to skip it as it means we're in | ||||
// the CI and it's the merge commit generated to test the PR. | ||||
let output = Command::new("git") | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This logic is much more complicated than it might seem. Could you instead reuse rust/src/build_helper/src/git.rs Line 201 in a4b9a1b
|
||||
.args(&["log", "-n", "1", "--pretty=format:%ae"]) | ||||
.output() | ||||
.expect("Failed to run `git` command to retrieve base commit"); | ||||
let output = String::from_utf8_lossy(&output.stdout); | ||||
let skip = if output.trim() == "[email protected]" { "--skip=1" } else { "--skip=0" }; | ||||
|
||||
// Now we find the last merge commit from bors to know what base commit to use. | ||||
let output = Command::new("git") | ||||
.args(&["log", "[email protected]", "-n", "1", "--pretty=format:%H", skip]) | ||||
.output() | ||||
.expect("Failed to run `git` command to retrieve base commit"); | ||||
let output = String::from_utf8_lossy(&output.stdout); | ||||
|
||||
let base_commit = output.trim(); | ||||
println!("setting base commit: {base_commit}"); | ||||
env::set_var("BASE_COMMIT", base_commit); | ||||
} | ||||
|
||||
fn main() { | ||||
// Running Cargo will read the libstd Cargo.toml | ||||
// which uses the unstable `public-dependency` feature. | ||||
// | ||||
// `setenv` might not be thread safe, so run it before using multiple threads. | ||||
env::set_var("RUSTC_BOOTSTRAP", "1"); | ||||
set_env_base_commit(); | ||||
|
||||
let root_path: PathBuf = env::args_os().nth(1).expect("need path to root of repo").into(); | ||||
let cargo: PathBuf = env::args_os().nth(2).expect("need path to cargo").into(); | ||||
|
@@ -110,6 +140,7 @@ fn main() { | |||
check!(rustdoc_css_themes, &librustdoc_path); | ||||
check!(rustdoc_templates, &librustdoc_path); | ||||
check!(rustdoc_js, &librustdoc_path, &tools_path, &src_path); | ||||
check!(rustdoc_json); | ||||
check!(known_bug, &crashes_path); | ||||
check!(unknown_revision, &tests_path); | ||||
|
||||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
//! Tidy check to ensure that `FORMAT_VERSION` was correctly updated if `rustdoc-json-types` was | ||
//! updated as well. | ||
|
||
use std::process::Command; | ||
|
||
fn git_diff(base_commit: &str, extra_arg: &str) -> Option<String> { | ||
let output = Command::new("git").arg("diff").arg(base_commit).arg(extra_arg).output().ok()?; | ||
Some(String::from_utf8_lossy(&output.stdout).into()) | ||
} | ||
|
||
pub fn check(bad: &mut bool) { | ||
let base_commit = std::env::var("BASE_COMMIT").unwrap(); | ||
|
||
// First we check that `src/rustdoc-json-types` was modified. | ||
match git_diff(&base_commit, "--name-status") { | ||
Some(output) => { | ||
if !output | ||
.lines() | ||
.any(|line| line.starts_with("M") && line.contains("src/rustdoc-json-types")) | ||
{ | ||
// `rustdoc-json-types` was not modified so nothing more to check here. | ||
return; | ||
} | ||
} | ||
None => { | ||
*bad = true; | ||
eprintln!("Failed to run `git diff`"); | ||
return; | ||
} | ||
} | ||
// Then we check that if `FORMAT_VERSION` was updated, the `Latest feature:` was also updated. | ||
match git_diff(&base_commit, "src/rustdoc-json-types") { | ||
Some(output) => { | ||
let mut format_version_updated = false; | ||
let mut latest_feature_comment_updated = false; | ||
for line in output.lines() { | ||
if line.starts_with("+pub const FORMAT_VERSION: u32 =") { | ||
format_version_updated = true; | ||
} else if line.starts_with("+// Latest feature:") { | ||
latest_feature_comment_updated = true; | ||
} | ||
} | ||
if format_version_updated != latest_feature_comment_updated { | ||
*bad = true; | ||
if latest_feature_comment_updated { | ||
eprintln!( | ||
"`Latest feature` comment was updated whereas `FORMAT_VERSION` wasn't" | ||
); | ||
} else { | ||
eprintln!( | ||
"`Latest feature` comment was not updated whereas `FORMAT_VERSION` was" | ||
); | ||
} | ||
} | ||
} | ||
None => { | ||
*bad = true; | ||
eprintln!("Failed to run `git diff`"); | ||
return; | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This 48->49 change should be reverted before merging.