Add CI metadata to bootstrap metrics
This will allow us to provide links to CI workflows, jobs and summaries in the post-merge analysis report.
This commit is contained in:
parent
a37cef9ee6
commit
27cca0a161
5 changed files with 38 additions and 5 deletions
2
.github/workflows/ci.yml
vendored
2
.github/workflows/ci.yml
vendored
|
@ -69,6 +69,8 @@ jobs:
|
|||
env:
|
||||
CI_JOB_NAME: ${{ matrix.name }}
|
||||
CI_JOB_DOC_URL: ${{ matrix.doc_url }}
|
||||
GITHUB_WORKFLOW_RUN_ID: ${{ github.run_id }}
|
||||
GITHUB_REPOSITORY: ${{ github.repository }}
|
||||
CARGO_REGISTRIES_CRATES_IO_PROTOCOL: sparse
|
||||
# commit of PR sha or commit sha. `GITHUB_SHA` is not accurate for PRs.
|
||||
HEAD_SHA: ${{ github.event.pull_request.head.sha || github.sha }}
|
||||
|
|
|
@ -9,9 +9,10 @@ use std::fs::File;
|
|||
use std::io::BufWriter;
|
||||
use std::time::{Duration, Instant, SystemTime};
|
||||
|
||||
use build_helper::ci::CiEnv;
|
||||
use build_helper::metrics::{
|
||||
JsonInvocation, JsonInvocationSystemStats, JsonNode, JsonRoot, JsonStepSystemStats, Test,
|
||||
TestOutcome, TestSuite, TestSuiteMetadata,
|
||||
CiMetadata, JsonInvocation, JsonInvocationSystemStats, JsonNode, JsonRoot, JsonStepSystemStats,
|
||||
Test, TestOutcome, TestSuite, TestSuiteMetadata,
|
||||
};
|
||||
use sysinfo::{CpuRefreshKind, RefreshKind, System};
|
||||
|
||||
|
@ -217,7 +218,12 @@ impl BuildMetrics {
|
|||
children: steps.into_iter().map(|step| self.prepare_json_step(step)).collect(),
|
||||
});
|
||||
|
||||
let json = JsonRoot { format_version: CURRENT_FORMAT_VERSION, system_stats, invocations };
|
||||
let json = JsonRoot {
|
||||
format_version: CURRENT_FORMAT_VERSION,
|
||||
system_stats,
|
||||
invocations,
|
||||
ci_metadata: get_ci_metadata(CiEnv::current()),
|
||||
};
|
||||
|
||||
t!(std::fs::create_dir_all(dest.parent().unwrap()));
|
||||
let mut file = BufWriter::new(t!(File::create(&dest)));
|
||||
|
@ -245,6 +251,16 @@ impl BuildMetrics {
|
|||
}
|
||||
}
|
||||
|
||||
fn get_ci_metadata(ci_env: CiEnv) -> Option<CiMetadata> {
|
||||
if ci_env != CiEnv::GitHubActions {
|
||||
return None;
|
||||
}
|
||||
let workflow_run_id =
|
||||
std::env::var("GITHUB_WORKFLOW_RUN_ID").ok().and_then(|id| id.parse::<u64>().ok())?;
|
||||
let repository = std::env::var("GITHUB_REPOSITORY").ok()?;
|
||||
Some(CiMetadata { workflow_run_id, repository })
|
||||
}
|
||||
|
||||
struct MetricsState {
|
||||
finished_steps: Vec<StepMetrics>,
|
||||
running_steps: Vec<StepMetrics>,
|
||||
|
|
|
@ -9,6 +9,19 @@ pub struct JsonRoot {
|
|||
pub format_version: usize,
|
||||
pub system_stats: JsonInvocationSystemStats,
|
||||
pub invocations: Vec<JsonInvocation>,
|
||||
#[serde(default)]
|
||||
pub ci_metadata: Option<CiMetadata>,
|
||||
}
|
||||
|
||||
/// Represents metadata about bootstrap's execution in CI.
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct CiMetadata {
|
||||
/// GitHub run ID of the workflow where bootstrap was executed.
|
||||
/// Note that the run ID will be shared amongst all jobs executed in that workflow.
|
||||
pub workflow_run_id: u64,
|
||||
/// Full name of a GitHub repository where bootstrap was executed in CI.
|
||||
/// e.g. `rust-lang-ci/rust`.
|
||||
pub repository: String,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
use std::collections::{BTreeMap, HashMap, HashSet};
|
||||
use std::fmt::Debug;
|
||||
use std::time::Duration;
|
||||
|
||||
use build_helper::metrics::{
|
||||
BuildStep, JsonRoot, TestOutcome, TestSuite, TestSuiteMetadata, escape_step_name,
|
||||
format_build_steps,
|
||||
};
|
||||
use std::collections::{BTreeMap, HashMap, HashSet};
|
||||
use std::time::Duration;
|
||||
|
||||
use crate::metrics;
|
||||
use crate::metrics::{JobMetrics, JobName, get_test_suites};
|
||||
|
|
|
@ -355,6 +355,8 @@ docker \
|
|||
--env GITHUB_ACTIONS \
|
||||
--env GITHUB_REF \
|
||||
--env GITHUB_STEP_SUMMARY="/checkout/obj/${SUMMARY_FILE}" \
|
||||
--env GITHUB_WORKFLOW_RUN_ID \
|
||||
--env GITHUB_REPOSITORY \
|
||||
--env RUST_BACKTRACE \
|
||||
--env TOOLSTATE_REPO_ACCESS_TOKEN \
|
||||
--env TOOLSTATE_REPO \
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue