forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#114623 - Kobzol:opt-dist-gha-summaries, r=<try>
Print some information from try builds to GitHub summary This PR adds some logs from `opt-dist` (the duration of the individual steps of the build pipeline, and the size of the resulting artifacts) to GitHub [job summaries](https://github.blog/2022-05-09-supercharging-github-actions-with-job-summaries/), in order to quickly show useful information right in the GHA CI job page, without needing to read the full log. [This](https://github.com/rust-lang-ci/rust/actions/runs/5810621086) is how the summary currently looks like. r? `@ghost`
- Loading branch information
Showing
6 changed files
with
160 additions
and
28 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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,61 @@ | ||
use std::io::Write; | ||
|
||
use tabled::builder::Builder; | ||
use tabled::settings::object::Columns; | ||
use tabled::settings::style::{BorderChar, Offset}; | ||
use tabled::settings::{Modify, Style}; | ||
|
||
use crate::environment::Environment; | ||
use crate::utils::io::get_files_from_dir; | ||
|
||
pub fn print_binary_sizes(env: &Environment) -> anyhow::Result<()> { | ||
use humansize::format_size; | ||
use humansize::BINARY; | ||
use std::fmt::Write; | ||
|
||
let root = env.build_artifacts().join("stage2"); | ||
|
||
let mut files = get_files_from_dir(&root.join("bin"), None)?; | ||
files.extend(get_files_from_dir(&root.join("lib"), Some(".so"))?); | ||
files.sort_unstable(); | ||
|
||
let items: Vec<_> = files | ||
.into_iter() | ||
.map(|file| { | ||
let size = std::fs::metadata(file.as_std_path()).map(|m| m.len()).unwrap_or(0); | ||
let size_formatted = format_size(size, BINARY); | ||
let name = file.file_name().unwrap().to_string(); | ||
(name, size_formatted) | ||
}) | ||
.collect(); | ||
|
||
// Write to log | ||
let mut output = String::new(); | ||
for (name, size_formatted) in items.iter() { | ||
let name = format!("{}:", name); | ||
writeln!(output, "{name:<50}{size_formatted:>10}")?; | ||
} | ||
log::info!("Rustc artifact size\n{output}"); | ||
|
||
// Write to GitHub summary | ||
if let Ok(summary_path) = std::env::var("GITHUB_STEP_SUMMARY") { | ||
let mut builder = Builder::default(); | ||
for (name, size_formatted) in items { | ||
builder.push_record(vec![name, size_formatted]); | ||
} | ||
|
||
builder.set_header(vec!["Artifact", "Size"]); | ||
let mut table = builder.build(); | ||
|
||
let mut file = std::fs::File::options().append(true).create(true).open(summary_path)?; | ||
writeln!( | ||
file, | ||
"# Artifact size\n{}\n", | ||
table.with(Style::markdown()).with( | ||
Modify::new(Columns::single(1)).with(BorderChar::horizontal(':', Offset::End(0))), | ||
) | ||
)?; | ||
} | ||
|
||
Ok(()) | ||
} |
This file contains 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