-
Notifications
You must be signed in to change notification settings - Fork 1k
Rustify ci/build_and_test.* scripts
#6855
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
4fb8553
Split `ci/integration.rs` "common" code into another file
GuillaumeGomez 11221ad
Migrate `build_and_test` scripts to Rust
GuillaumeGomez a681fd8
Remove usage of `INTEGRATION` env variable
GuillaumeGomez e599b32
Update github actions scripts to use new rust binary
GuillaumeGomez 5b938cb
Make `-Dwarnings` mandatory when running `build-and-test`
GuillaumeGomez a64a640
Make `ci-integration` its own package to avoid rebuilding it
GuillaumeGomez c56702b
Make ci/target ignored path more precise
GuillaumeGomez 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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,7 @@ | ||
| [package] | ||
| name = "ci-integration" | ||
| version = "0.0.1" | ||
| edition = "2024" | ||
| publish = false | ||
|
|
||
| [workspace] |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,49 @@ | ||
| use crate::common::run_command_with_env; | ||
|
|
||
| use std::collections::HashMap; | ||
|
|
||
| fn run_tests_in_dir(env: &HashMap<&str, &str>, dir: &str) -> Result<(), String> { | ||
| run_command_with_env("cargo", &["build", "--locked"], dir, &env)?; | ||
| run_command_with_env("cargo", &["test"], dir, &env) | ||
| } | ||
|
|
||
| pub fn runner() -> Result<(), String> { | ||
| let Ok(rustflags) = std::env::var("RUSTFLAGS") else { | ||
| return Err( | ||
| "`RUSTFLAGS` environment variable must be set to run `build-and-test`".to_string(), | ||
| ); | ||
| }; | ||
| if !rustflags.contains("-D warnings") && !rustflags.contains("-Dwarnings") { | ||
| return Err( | ||
| "`RUSTFLAGS` environment variable must contain `-Dwarnings` to run `build-and-test`" | ||
| .to_string(), | ||
| ); | ||
| } | ||
|
|
||
| let mut env = HashMap::from([("RUSTFLAGS", "-D warnings"), ("RUSTFMT_CI", "1")]); | ||
| let value_holder; | ||
| if let Ok(cfg_release_channel) = std::env::var("CFG_RELEASE_CHANNEL") { | ||
| value_holder = cfg_release_channel; | ||
| env.insert("CFG_RELEASE_CHANNEL", value_holder.as_str()); | ||
| } | ||
|
jieyouxu marked this conversation as resolved.
|
||
|
|
||
| // Print version information | ||
| run_command_with_env("rustc", &["-Vv"], ".", &env)?; | ||
| run_command_with_env("cargo", &["-v"], ".", &env)?; | ||
|
|
||
| // Build and test main crate | ||
| let options: &[&str] = | ||
| if std::env::var("CFG_RELEASE_CHANNEL").is_ok_and(|value| value == "nightly") { | ||
| &["build", "--locked", "--all-features"] | ||
| } else { | ||
| &["build", "--locked"] | ||
| }; | ||
| run_command_with_env("cargo", options, ".", &env)?; | ||
| run_command_with_env("cargo", &["test"], ".", &env)?; | ||
|
|
||
| // Build and test config_proc_macro | ||
| run_tests_in_dir(&env, "config_proc_macro")?; | ||
| run_tests_in_dir(&env, "check_diff")?; | ||
|
|
||
| Ok(()) | ||
| } | ||
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,87 @@ | ||
| use std::collections::HashMap; | ||
| use std::ffi::OsStr; | ||
| use std::path::Path; | ||
| use std::process::Command; | ||
|
|
||
| pub fn write_file(file_path: impl AsRef<Path>, content: &str) -> Result<(), String> { | ||
| std::fs::write(&file_path, content).map_err(|error| { | ||
| format!( | ||
| "Failed to create empty `{}` file: {error:?}", | ||
| file_path.as_ref().display(), | ||
| ) | ||
| }) | ||
| } | ||
|
|
||
| pub fn run_command_with_env<I, S>( | ||
| bin: &str, | ||
| args: I, | ||
| current_dir: &str, | ||
| env: &HashMap<&str, &str>, | ||
| ) -> Result<(), String> | ||
| where | ||
| I: IntoIterator<Item = S>, | ||
| S: AsRef<OsStr>, | ||
| { | ||
| let exit_status = Command::new(bin) | ||
| .args(args) | ||
| .envs(env) | ||
| .current_dir(current_dir) | ||
| .spawn() | ||
| .map_err(|error| format!("Failed to spawn command `{bin}`: {error:?}"))? | ||
| .wait() | ||
| .map_err(|error| format!("Failed to wait command `{bin}`: {error:?}"))?; | ||
| if exit_status.success() { | ||
| Ok(()) | ||
| } else { | ||
| Err(format!("Command `{bin}` failed")) | ||
| } | ||
| } | ||
|
|
||
| pub fn run_command<I, S>(bin: &str, args: I, current_dir: &str) -> Result<(), String> | ||
| where | ||
| I: IntoIterator<Item = S>, | ||
| S: AsRef<OsStr>, | ||
| { | ||
| run_command_with_env(bin, args, current_dir, &HashMap::new()) | ||
| } | ||
|
|
||
| pub struct CommandOutput { | ||
| pub output: String, | ||
| pub exited_successfully: bool, | ||
| } | ||
|
|
||
| pub fn run_command_with_output_and_env<I, S>( | ||
| bin: &str, | ||
| args: I, | ||
| current_dir: &str, | ||
| env: &HashMap<&str, &str>, | ||
| ) -> Result<CommandOutput, String> | ||
| where | ||
| I: IntoIterator<Item = S>, | ||
| S: AsRef<OsStr>, | ||
| { | ||
| let cmd_output = Command::new(bin) | ||
| .args(args) | ||
| .envs(env) | ||
| .current_dir(current_dir) | ||
| .output() | ||
| .map_err(|error| format!("Failed to spawn command `{bin}`: {error:?}"))?; | ||
| let mut output = String::from_utf8_lossy(&cmd_output.stdout).into_owned(); | ||
| output.push_str(&String::from_utf8_lossy(&cmd_output.stderr)); | ||
| Ok(CommandOutput { | ||
| output, | ||
| exited_successfully: cmd_output.status.success(), | ||
| }) | ||
| } | ||
|
|
||
| pub fn run_command_with_output<I, S>( | ||
| bin: &str, | ||
| args: I, | ||
| current_dir: &str, | ||
| ) -> Result<CommandOutput, String> | ||
| where | ||
| I: IntoIterator<Item = S>, | ||
| S: AsRef<OsStr>, | ||
| { | ||
| run_command_with_output_and_env(bin, args, current_dir, &HashMap::new()) | ||
| } |
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
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.
Uh oh!
There was an error while loading. Please reload this page.