Skip to content

Commit 27cca0a

Browse files
committed
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.
1 parent a37cef9 commit 27cca0a

File tree

5 files changed

+38
-5
lines changed

5 files changed

+38
-5
lines changed

Diff for: .github/workflows/ci.yml

+2
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ jobs:
6969
env:
7070
CI_JOB_NAME: ${{ matrix.name }}
7171
CI_JOB_DOC_URL: ${{ matrix.doc_url }}
72+
GITHUB_WORKFLOW_RUN_ID: ${{ github.run_id }}
73+
GITHUB_REPOSITORY: ${{ github.repository }}
7274
CARGO_REGISTRIES_CRATES_IO_PROTOCOL: sparse
7375
# commit of PR sha or commit sha. `GITHUB_SHA` is not accurate for PRs.
7476
HEAD_SHA: ${{ github.event.pull_request.head.sha || github.sha }}

Diff for: src/bootstrap/src/utils/metrics.rs

+19-3
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ use std::fs::File;
99
use std::io::BufWriter;
1010
use std::time::{Duration, Instant, SystemTime};
1111

12+
use build_helper::ci::CiEnv;
1213
use build_helper::metrics::{
13-
JsonInvocation, JsonInvocationSystemStats, JsonNode, JsonRoot, JsonStepSystemStats, Test,
14-
TestOutcome, TestSuite, TestSuiteMetadata,
14+
CiMetadata, JsonInvocation, JsonInvocationSystemStats, JsonNode, JsonRoot, JsonStepSystemStats,
15+
Test, TestOutcome, TestSuite, TestSuiteMetadata,
1516
};
1617
use sysinfo::{CpuRefreshKind, RefreshKind, System};
1718

@@ -217,7 +218,12 @@ impl BuildMetrics {
217218
children: steps.into_iter().map(|step| self.prepare_json_step(step)).collect(),
218219
});
219220

220-
let json = JsonRoot { format_version: CURRENT_FORMAT_VERSION, system_stats, invocations };
221+
let json = JsonRoot {
222+
format_version: CURRENT_FORMAT_VERSION,
223+
system_stats,
224+
invocations,
225+
ci_metadata: get_ci_metadata(CiEnv::current()),
226+
};
221227

222228
t!(std::fs::create_dir_all(dest.parent().unwrap()));
223229
let mut file = BufWriter::new(t!(File::create(&dest)));
@@ -245,6 +251,16 @@ impl BuildMetrics {
245251
}
246252
}
247253

254+
fn get_ci_metadata(ci_env: CiEnv) -> Option<CiMetadata> {
255+
if ci_env != CiEnv::GitHubActions {
256+
return None;
257+
}
258+
let workflow_run_id =
259+
std::env::var("GITHUB_WORKFLOW_RUN_ID").ok().and_then(|id| id.parse::<u64>().ok())?;
260+
let repository = std::env::var("GITHUB_REPOSITORY").ok()?;
261+
Some(CiMetadata { workflow_run_id, repository })
262+
}
263+
248264
struct MetricsState {
249265
finished_steps: Vec<StepMetrics>,
250266
running_steps: Vec<StepMetrics>,

Diff for: src/build_helper/src/metrics.rs

+13
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,19 @@ pub struct JsonRoot {
99
pub format_version: usize,
1010
pub system_stats: JsonInvocationSystemStats,
1111
pub invocations: Vec<JsonInvocation>,
12+
#[serde(default)]
13+
pub ci_metadata: Option<CiMetadata>,
14+
}
15+
16+
/// Represents metadata about bootstrap's execution in CI.
17+
#[derive(Serialize, Deserialize)]
18+
pub struct CiMetadata {
19+
/// GitHub run ID of the workflow where bootstrap was executed.
20+
/// Note that the run ID will be shared amongst all jobs executed in that workflow.
21+
pub workflow_run_id: u64,
22+
/// Full name of a GitHub repository where bootstrap was executed in CI.
23+
/// e.g. `rust-lang-ci/rust`.
24+
pub repository: String,
1225
}
1326

1427
#[derive(Serialize, Deserialize)]

Diff for: src/ci/citool/src/analysis.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1+
use std::collections::{BTreeMap, HashMap, HashSet};
12
use std::fmt::Debug;
3+
use std::time::Duration;
24

35
use build_helper::metrics::{
46
BuildStep, JsonRoot, TestOutcome, TestSuite, TestSuiteMetadata, escape_step_name,
57
format_build_steps,
68
};
7-
use std::collections::{BTreeMap, HashMap, HashSet};
8-
use std::time::Duration;
99

1010
use crate::metrics;
1111
use crate::metrics::{JobMetrics, JobName, get_test_suites};

Diff for: src/ci/docker/run.sh

+2
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,8 @@ docker \
355355
--env GITHUB_ACTIONS \
356356
--env GITHUB_REF \
357357
--env GITHUB_STEP_SUMMARY="/checkout/obj/${SUMMARY_FILE}" \
358+
--env GITHUB_WORKFLOW_RUN_ID \
359+
--env GITHUB_REPOSITORY \
358360
--env RUST_BACKTRACE \
359361
--env TOOLSTATE_REPO_ACCESS_TOKEN \
360362
--env TOOLSTATE_REPO \

0 commit comments

Comments
 (0)