Skip to content

Commit e9addfd

Browse files
committed
Auto merge of rust-lang#114623 - Kobzol:opt-dist-gha-summaries, r=Mark-Simulacrum
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`
2 parents 97c81e1 + 209789e commit e9addfd

File tree

6 files changed

+160
-28
lines changed

6 files changed

+160
-28
lines changed

Cargo.lock

+60
Original file line numberDiff line numberDiff line change
@@ -2684,6 +2684,7 @@ dependencies = [
26842684
"serde",
26852685
"serde_json",
26862686
"sysinfo",
2687+
"tabled",
26872688
"tar",
26882689
"tempfile",
26892690
"xz",
@@ -2750,6 +2751,17 @@ dependencies = [
27502751
"unwind",
27512752
]
27522753

2754+
[[package]]
2755+
name = "papergrid"
2756+
version = "0.10.0"
2757+
source = "registry+https://github.com/rust-lang/crates.io-index"
2758+
checksum = "a2ccbe15f2b6db62f9a9871642746427e297b0ceb85f9a7f1ee5ff47d184d0c8"
2759+
dependencies = [
2760+
"bytecount",
2761+
"fnv",
2762+
"unicode-width",
2763+
]
2764+
27532765
[[package]]
27542766
name = "parking_lot"
27552767
version = "0.11.2"
@@ -2958,6 +2970,30 @@ dependencies = [
29582970
"pad",
29592971
]
29602972

2973+
[[package]]
2974+
name = "proc-macro-error"
2975+
version = "1.0.4"
2976+
source = "registry+https://github.com/rust-lang/crates.io-index"
2977+
checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c"
2978+
dependencies = [
2979+
"proc-macro-error-attr",
2980+
"proc-macro2",
2981+
"quote",
2982+
"syn 1.0.109",
2983+
"version_check",
2984+
]
2985+
2986+
[[package]]
2987+
name = "proc-macro-error-attr"
2988+
version = "1.0.4"
2989+
source = "registry+https://github.com/rust-lang/crates.io-index"
2990+
checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869"
2991+
dependencies = [
2992+
"proc-macro2",
2993+
"quote",
2994+
"version_check",
2995+
]
2996+
29612997
[[package]]
29622998
name = "proc-macro-hack"
29632999
version = "0.5.20+deprecated"
@@ -5209,6 +5245,30 @@ dependencies = [
52095245
"test",
52105246
]
52115247

5248+
[[package]]
5249+
name = "tabled"
5250+
version = "0.13.0"
5251+
source = "registry+https://github.com/rust-lang/crates.io-index"
5252+
checksum = "4d38d39c754ae037a9bc3ca1580a985db7371cd14f1229172d1db9093feb6739"
5253+
dependencies = [
5254+
"papergrid",
5255+
"tabled_derive",
5256+
"unicode-width",
5257+
]
5258+
5259+
[[package]]
5260+
name = "tabled_derive"
5261+
version = "0.6.0"
5262+
source = "registry+https://github.com/rust-lang/crates.io-index"
5263+
checksum = "99f688a08b54f4f02f0a3c382aefdb7884d3d69609f785bd253dc033243e3fe4"
5264+
dependencies = [
5265+
"heck",
5266+
"proc-macro-error",
5267+
"proc-macro2",
5268+
"quote",
5269+
"syn 1.0.109",
5270+
]
5271+
52125272
[[package]]
52135273
name = "tar"
52145274
version = "0.4.38"

src/ci/docker/run.sh

+6
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,9 @@ else
264264
BASE_COMMIT=""
265265
fi
266266

267+
SUMMARY_FILE=github-summary.md
268+
touch $objdir/${SUMMARY_FILE}
269+
267270
docker \
268271
run \
269272
--workdir /checkout/obj \
@@ -275,6 +278,7 @@ docker \
275278
--env CI \
276279
--env GITHUB_ACTIONS \
277280
--env GITHUB_REF \
281+
--env GITHUB_STEP_SUMMARY="/checkout/obj/${SUMMARY_FILE}" \
278282
--env TOOLSTATE_REPO_ACCESS_TOKEN \
279283
--env TOOLSTATE_REPO \
280284
--env TOOLSTATE_PUBLISH \
@@ -289,6 +293,8 @@ docker \
289293
rust-ci \
290294
$command
291295

296+
cat $objdir/${SUMMARY_FILE} >> "${GITHUB_STEP_SUMMARY}"
297+
292298
if [ -f /.dockerenv ]; then
293299
rm -rf $objdir
294300
docker cp checkout:/checkout/obj $objdir

src/tools/opt-dist/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,4 @@ glob = "0.3"
2323
tempfile = "3.5"
2424
derive_builder = "0.12"
2525
clap = { version = "4", features = ["derive"] }
26+
tabled = "0.13"

src/tools/opt-dist/src/main.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@ use crate::exec::{cmd, Bootstrap};
1313
use crate::tests::run_tests;
1414
use crate::timer::Timer;
1515
use crate::training::{gather_llvm_bolt_profiles, gather_llvm_profiles, gather_rustc_profiles};
16+
use crate::utils::artifact_size::print_binary_sizes;
1617
use crate::utils::io::{copy_directory, move_directory, reset_directory};
1718
use crate::utils::{
18-
clear_llvm_files, format_env_variables, print_binary_sizes, print_free_disk_space,
19-
retry_action, with_log_group,
19+
clear_llvm_files, format_env_variables, print_free_disk_space, retry_action, with_log_group,
20+
write_timer_to_summary,
2021
};
2122

2223
mod bolt;
@@ -359,6 +360,10 @@ fn main() -> anyhow::Result<()> {
359360
let result = execute_pipeline(&env, &mut timer, build_args);
360361
log::info!("Timer results\n{}", timer.format_stats());
361362

363+
if let Ok(summary_path) = std::env::var("GITHUB_STEP_SUMMARY") {
364+
write_timer_to_summary(&summary_path, &timer)?;
365+
}
366+
362367
print_free_disk_space()?;
363368
result.context("Optimized build pipeline has failed")?;
364369
print_binary_sizes(&env)?;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
use std::io::Write;
2+
3+
use tabled::builder::Builder;
4+
use tabled::settings::object::Columns;
5+
use tabled::settings::style::{BorderChar, Offset};
6+
use tabled::settings::{Modify, Style};
7+
8+
use crate::environment::Environment;
9+
use crate::utils::io::get_files_from_dir;
10+
11+
pub fn print_binary_sizes(env: &Environment) -> anyhow::Result<()> {
12+
use humansize::format_size;
13+
use humansize::BINARY;
14+
use std::fmt::Write;
15+
16+
let root = env.build_artifacts().join("stage2");
17+
18+
let mut files = get_files_from_dir(&root.join("bin"), None)?;
19+
files.extend(get_files_from_dir(&root.join("lib"), Some(".so"))?);
20+
files.sort_unstable();
21+
22+
let items: Vec<_> = files
23+
.into_iter()
24+
.map(|file| {
25+
let size = std::fs::metadata(file.as_std_path()).map(|m| m.len()).unwrap_or(0);
26+
let size_formatted = format_size(size, BINARY);
27+
let name = file.file_name().unwrap().to_string();
28+
(name, size_formatted)
29+
})
30+
.collect();
31+
32+
// Write to log
33+
let mut output = String::new();
34+
for (name, size_formatted) in items.iter() {
35+
let name = format!("{}:", name);
36+
writeln!(output, "{name:<50}{size_formatted:>10}")?;
37+
}
38+
log::info!("Rustc artifact size\n{output}");
39+
40+
// Write to GitHub summary
41+
if let Ok(summary_path) = std::env::var("GITHUB_STEP_SUMMARY") {
42+
let mut builder = Builder::default();
43+
for (name, size_formatted) in items {
44+
builder.push_record(vec![name, size_formatted]);
45+
}
46+
47+
builder.set_header(vec!["Artifact", "Size"]);
48+
let mut table = builder.build();
49+
50+
let mut file = std::fs::File::options().append(true).create(true).open(summary_path)?;
51+
writeln!(
52+
file,
53+
"# Artifact size\n{}\n",
54+
table.with(Style::markdown()).with(
55+
Modify::new(Columns::single(1)).with(BorderChar::horizontal(':', Offset::End(0))),
56+
)
57+
)?;
58+
}
59+
60+
Ok(())
61+
}

src/tools/opt-dist/src/utils/mod.rs

+25-26
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
pub mod io;
1+
use sysinfo::{DiskExt, RefreshKind, System, SystemExt};
22

33
use crate::environment::Environment;
4-
use crate::utils::io::{delete_directory, get_files_from_dir};
5-
use humansize::{format_size, BINARY};
4+
use crate::timer::Timer;
5+
use crate::utils::io::delete_directory;
6+
use humansize::BINARY;
67
use std::time::Duration;
7-
use sysinfo::{DiskExt, RefreshKind, System, SystemExt};
8+
9+
pub mod artifact_size;
10+
pub mod io;
811

912
pub fn format_env_variables() -> String {
1013
let vars = std::env::vars().map(|(key, value)| format!("{key}={value}")).collect::<Vec<_>>();
@@ -26,28 +29,6 @@ pub fn print_free_disk_space() -> anyhow::Result<()> {
2629
Ok(())
2730
}
2831

29-
pub fn print_binary_sizes(env: &Environment) -> anyhow::Result<()> {
30-
use std::fmt::Write;
31-
32-
let root = env.build_artifacts().join("stage2");
33-
34-
let mut files = get_files_from_dir(&root.join("bin"), None)?;
35-
files.extend(get_files_from_dir(&root.join("lib"), Some(".so"))?);
36-
files.sort_unstable();
37-
38-
let mut output = String::new();
39-
for file in files {
40-
let size = std::fs::metadata(file.as_std_path())?.len();
41-
let size_formatted = format_size(size, BINARY);
42-
let name = format!("{}:", file.file_name().unwrap());
43-
writeln!(output, "{name:<50}{size_formatted:>10}")?;
44-
}
45-
46-
log::info!("Rustc artifact size\n{output}");
47-
48-
Ok(())
49-
}
50-
5132
pub fn clear_llvm_files(env: &Environment) -> anyhow::Result<()> {
5233
// Bootstrap currently doesn't support rebuilding LLVM when PGO options
5334
// change (or any other llvm-related options); so just clear out the relevant
@@ -58,6 +39,24 @@ pub fn clear_llvm_files(env: &Environment) -> anyhow::Result<()> {
5839
Ok(())
5940
}
6041

42+
/// Write the formatted statistics of the timer to a Github Actions summary.
43+
pub fn write_timer_to_summary(path: &str, timer: &Timer) -> anyhow::Result<()> {
44+
use std::io::Write;
45+
46+
let mut file = std::fs::File::options().append(true).create(true).open(path)?;
47+
writeln!(
48+
file,
49+
r#"# Step durations
50+
51+
```
52+
{}
53+
```
54+
"#,
55+
timer.format_stats()
56+
)?;
57+
Ok(())
58+
}
59+
6160
/// Wraps all output produced within the `func` closure in a CI output group, if we're running in
6261
/// CI.
6362
pub fn with_log_group<F: FnOnce() -> R, R>(group: &str, func: F) -> R {

0 commit comments

Comments
 (0)