From 1b91773c7cdac2998ba433055160a42cc95c4d5c Mon Sep 17 00:00:00 2001 From: Conrad Irwin Date: Thu, 30 Oct 2025 21:18:56 -0600 Subject: [PATCH] Add inputs? --- .github/workflows/compare_perf.yml | 15 +++++++-- Cargo.lock | 4 +-- Cargo.toml | 2 +- .../xtask/src/tasks/workflows/compare_perf.rs | 18 +++++++--- tooling/xtask/src/tasks/workflows/vars.rs | 33 +++++++++++++++++-- 5 files changed, 60 insertions(+), 12 deletions(-) diff --git a/.github/workflows/compare_perf.yml b/.github/workflows/compare_perf.yml index c9884c68f17ac21a42b2438eab1816229ef4bf56..b6f900c4179c106859cd6dce103c5cc2aedd9b24 100644 --- a/.github/workflows/compare_perf.yml +++ b/.github/workflows/compare_perf.yml @@ -2,7 +2,16 @@ # Rebuild with `cargo xtask workflows`. name: compare_perf on: - workflow_dispatch: {} + workflow_dispatch: + inputs: + head: + description: head + required: true + type: string + base: + description: base + required: true + type: string jobs: run_perf: runs-on: namespace-profile-2x4-ubuntu-2404 @@ -11,6 +20,6 @@ jobs: uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 with: clean: false - - name: steps::cargo_fmt - run: cargo fmt --all -- --check + - name: compare_perf::run_perf::echo_inputs + run: echo ${ inputs.base } ${ inputs.head } shell: bash -euxo pipefail {0} diff --git a/Cargo.lock b/Cargo.lock index ebcdd881a2921e28e0d1c32d8625793d2ef58f52..e1dd90ccf3b5b91c6836e6caf84e34e74ee87f12 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6962,7 +6962,7 @@ dependencies = [ [[package]] name = "gh-workflow" version = "0.8.0" -source = "git+https://github.com/zed-industries/gh-workflow?rev=0090c6b6ef82fff02bc8616645953e778d1acc08#0090c6b6ef82fff02bc8616645953e778d1acc08" +source = "git+https://github.com/zed-industries/gh-workflow?rev=3eaa84abca0778eb54272f45a312cb24f9a0b435#3eaa84abca0778eb54272f45a312cb24f9a0b435" dependencies = [ "async-trait", "derive_more 2.0.1", @@ -6979,7 +6979,7 @@ dependencies = [ [[package]] name = "gh-workflow-macros" version = "0.8.0" -source = "git+https://github.com/zed-industries/gh-workflow?rev=0090c6b6ef82fff02bc8616645953e778d1acc08#0090c6b6ef82fff02bc8616645953e778d1acc08" +source = "git+https://github.com/zed-industries/gh-workflow?rev=3eaa84abca0778eb54272f45a312cb24f9a0b435#3eaa84abca0778eb54272f45a312cb24f9a0b435" dependencies = [ "heck 0.5.0", "quote", diff --git a/Cargo.toml b/Cargo.toml index 7674b0bacc12e9f9ae78a3f299dc0f538e26bd35..ac6e310fe7d899486c5b5287f4ac07762751d9a1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -508,7 +508,7 @@ fork = "0.2.0" futures = "0.3" futures-batch = "0.6.1" futures-lite = "1.13" -gh-workflow = { git = "https://github.com/zed-industries/gh-workflow", rev = "0090c6b6ef82fff02bc8616645953e778d1acc08" } +gh-workflow = { git = "https://github.com/zed-industries/gh-workflow", rev = "3eaa84abca0778eb54272f45a312cb24f9a0b435" } git2 = { version = "0.20.1", default-features = false } globset = "0.4" handlebars = "4.3" diff --git a/tooling/xtask/src/tasks/workflows/compare_perf.rs b/tooling/xtask/src/tasks/workflows/compare_perf.rs index 98d755881e74b7d68b613b4edda2345bdeaf2c28..46f8bd1c59c9242e98d0dfd6ac427a5b48afc24a 100644 --- a/tooling/xtask/src/tasks/workflows/compare_perf.rs +++ b/tooling/xtask/src/tasks/workflows/compare_perf.rs @@ -3,21 +3,31 @@ use gh_workflow::*; use crate::tasks::workflows::{ runners, steps::{self, NamedJob, named}, + vars::Input, }; /// Generates the danger.yml workflow pub fn compare_perf() -> Workflow { - let run_perf = run_perf(); + let head = Input::string("head", None); + let base = Input::string("base", None); + let run_perf = run_perf(&base, &head); named::workflow() - .on(Event::default().workflow_dispatch(WorkflowDispatch::default())) + .on(Event::default().workflow_dispatch( + WorkflowDispatch::default() + .add_input(head.name, head.input()) + .add_input(base.name, base.input()), + )) .add_job(run_perf.name, run_perf.job) } -pub fn run_perf() -> NamedJob { +pub fn run_perf(base: &Input, head: &Input) -> NamedJob { + fn echo_inputs(base: &Input, head: &Input) -> Step { + named::bash(&format!("echo {} {}", base.var(), head.var())) + } named::job( Job::default() .runs_on(runners::LINUX_SMALL) .add_step(steps::checkout_repo()) - .add_step(steps::cargo_fmt()), + .add_step(echo_inputs(base, head)), ) } diff --git a/tooling/xtask/src/tasks/workflows/vars.rs b/tooling/xtask/src/tasks/workflows/vars.rs index b852e12400098c3d49f806c0010458d123ad24fa..f0e0c9c170ba01be86b0ab3a910e5d600785ffe7 100644 --- a/tooling/xtask/src/tasks/workflows/vars.rs +++ b/tooling/xtask/src/tasks/workflows/vars.rs @@ -1,6 +1,6 @@ use std::cell::RefCell; -use gh_workflow::{Concurrency, Env, Expression}; +use gh_workflow::{Concurrency, Env, Expression, WorkflowDispatchInput}; use crate::tasks::workflows::steps::NamedJob; @@ -102,7 +102,7 @@ impl PathCondition { name: job.name, job: job .job - .add_needs(set_by_step.clone()) + .add_need(set_by_step.clone()) .cond(Expression::new(format!( "needs.{}.outputs.{} == 'true'", &set_by_step, self.name @@ -110,3 +110,32 @@ impl PathCondition { } } } + +pub(crate) struct Input { + pub input_type: &'static str, + pub name: &'static str, + pub default: Option, +} + +impl Input { + pub fn string(name: &'static str, default: Option) -> Self { + Self { + input_type: "string", + name, + default, + } + } + + pub fn var(&self) -> String { + format!("${{{{ inputs.{} }}}}", self.name) + } + + pub fn input(&self) -> WorkflowDispatchInput { + WorkflowDispatchInput { + description: self.name.to_owned(), + required: self.default.is_none(), + input_type: self.input_type.to_owned(), + default: self.default.clone(), + } + } +}