From a88dc1a7d8e106dd5484f946e1f781e1c7884be1 Mon Sep 17 00:00:00 2001 From: Tushar Mathur Date: Wed, 6 Nov 2024 19:48:36 +0530 Subject: [PATCH] rename traits --- workspace/gh-workflow-gen/src/main.rs | 1 + workspace/gh-workflow/src/workflow.rs | 20 +++++++++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/workspace/gh-workflow-gen/src/main.rs b/workspace/gh-workflow-gen/src/main.rs index 0f52977..b68b054 100644 --- a/workspace/gh-workflow-gen/src/main.rs +++ b/workspace/gh-workflow-gen/src/main.rs @@ -20,6 +20,7 @@ fn main() { let nightly = Job::new("Nightly") .add_step(Step::uses("actions", "checkout", 4).name("Checkout Code")) .add_step( + // TODO: Rust Tool Chain can be a separate struct Step::uses("actions-rust-lang", "setup-rust-toolchain", 1) .name("Setup Rust Toolchain") .with(("toolchain", Version::Nightly)), diff --git a/workspace/gh-workflow/src/workflow.rs b/workspace/gh-workflow/src/workflow.rs index fef6bae..f8a53f2 100644 --- a/workspace/gh-workflow/src/workflow.rs +++ b/workspace/gh-workflow/src/workflow.rs @@ -342,7 +342,7 @@ pub struct Step { pub uses: Option, #[serde(skip_serializing_if = "Option::is_none")] #[setters(skip)] - pub with: Option>, + with: Option>, #[serde(skip_serializing_if = "Option::is_none")] #[setters(skip)] pub run: Option, @@ -394,7 +394,7 @@ impl Step { } } - pub fn with>(self, item: K) -> Self { + pub fn with(self, item: K) -> Self { item.apply(self) } @@ -403,7 +403,7 @@ impl Step { } } -impl SetEnv> for IndexMap { +impl SetInput for IndexMap { fn apply(self, mut step: Step) -> Step { let mut with = step.with.unwrap_or_default(); with.extend(self); @@ -412,6 +412,15 @@ impl SetEnv> for IndexMap { } } +impl SetInput for (S1, S2) { + fn apply(self, mut step: Step) -> Step { + let mut with = step.with.unwrap_or_default(); + with.insert(self.0.to_string(), Value::String(self.1.to_string())); + step.with = Some(with); + step + } +} + impl SetEnv for (S1, S2) { fn apply(self, mut value: Job) -> Job { let mut index_map: IndexMap = value.env.unwrap_or_default(); @@ -476,6 +485,11 @@ pub trait SetEvent { fn apply(self, workflow: Workflow) -> Workflow; } +/// Sets the input for a Step that uses another action +pub trait SetInput { + fn apply(self, step: Step) -> Step; +} + impl SetEnv> for (S1, S2) { fn apply(self, mut step: Step) -> Step { let mut index_map: IndexMap = step.with.unwrap_or_default();