diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4d5541457..5be8a2de4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -449,5 +449,5 @@ jobs: ./codecov -F $name ${pr:+-P ${pr}} -f $file --sha ${sha_rev} -n $name; done env: - pr: ${{ steps.pr-number.outputs.pr || '' }} + pr: ${{ steps.pr-number.outputs.pr }} artifacts: ${{ runner.temp }}/artifacts diff --git a/xtask/src/ci/target_matrix.rs b/xtask/src/ci/target_matrix.rs index 7e1bc1aad..cc6779c55 100644 --- a/xtask/src/ci/target_matrix.rs +++ b/xtask/src/ci/target_matrix.rs @@ -35,6 +35,7 @@ impl TargetMatrix { pub(crate) fn run(&self) -> Result<(), color_eyre::Report> { let mut matrix: Vec = get_matrix().clone(); let mut is_default_try = false; + let pr: Option; let (prs, mut app) = match self { TargetMatrix { merge_group: Some(ref_), @@ -72,7 +73,13 @@ impl TargetMatrix { is_default_try = process_try_comment.0; (vec![pr.as_ref()], process_try_comment.1) } - _ => (vec![], TargetMatrixArgs::default()), + _ => { + pr = current_pr(); + ( + pr.iter().map(|s| s.as_str()).collect(), + TargetMatrixArgs::default(), + ) + } }; // only apply ci labels on prs and `/ci try`, @@ -147,7 +154,7 @@ fn apply_has_no_ci_tests(prs: &[&str], app: &mut TargetMatrixArgs) -> Result<(), })? { app.none = true; - app.tests.push("none".to_owned()); + app.tests = vec!["none".to_owned()]; } Ok(()) } @@ -205,6 +212,16 @@ fn process_merge_group(ref_: &str) -> cross::Result<&str> { .ok_or_else(|| eyre::eyre!("merge group ref must include \"pr--\"")) } +fn current_pr() -> Option { + // gh pr view --json number --template "{{.number}}" + let stdout = Command::new("gh") + .args(["pr", "view", "--json", "number"]) + .run_and_get_stdout(&mut Verbosity::Quiet.into()) + .ok()?; + let pr_info: serde_json::Value = serde_json::from_str(&stdout).ok()?; + pr_info.get("number").map(|n| n.to_string()) +} + /// Returns app to use for matrix on try comment, boolean is used to determine if its a try without arguments fn process_try_comment(message: &str) -> cross::Result<(bool, TargetMatrixArgs)> { for line in message.lines() { @@ -384,7 +401,6 @@ impl TargetMatrixArgs { _ => self.tests.clone(), }; tests.retain(|p| p != "all"); - tests.retain(|p| p != "none"); serde_json::to_value(Ser(tests)) } }