Skip to content

Commit

Permalink
feat: add benchmark to workflow (#97)
Browse files Browse the repository at this point in the history
  • Loading branch information
mehul-m-prajapati authored Dec 10, 2024
1 parent df3caa1 commit edc5edb
Showing 1 changed file with 46 additions and 32 deletions.
78 changes: 46 additions & 32 deletions crates/gh-workflow-tailcall/src/workflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,14 @@ pub struct Workflow {

/// Name of the workflow.
pub name: String,

/// When enabled, a benchmark job is added to the workflow.
pub benchmarks: bool,
}

impl Default for Workflow {
fn default() -> Self {
Self { auto_release: false, name: "CI".into() }
Self { auto_release: false, name: "CI".into(), benchmarks: false }
}
}

Expand All @@ -40,6 +43,47 @@ impl Workflow {
pub fn to_github_workflow(&self) -> GHWorkflow {
self.clone().into()
}

/// Creates the "Build and Test" job for the workflow.
pub fn build_and_test(&self) -> Job {
let mut job = Job::new("Build and Test")
.permissions(Permissions::default().contents(Level::Read))
.add_step(Step::checkout())
.add_step(
Toolchain::default()
.add_stable()
.add_nightly()
.add_clippy()
.add_fmt(),
)
.add_step(
Cargo::new("test")
.args("--all-features --workspace")
.name("Cargo Test"),
)
.add_step(
Cargo::new("fmt")
.nightly()
.args("--check")
.name("Cargo Fmt"),
)
.add_step(
Cargo::new("clippy")
.nightly()
.args("--all-features --workspace -- -D warnings")
.name("Cargo Clippy"),
);

Check warning on line 75 in crates/gh-workflow-tailcall/src/workflow.rs

View workflow job for this annotation

GitHub Actions / Build and Test

Diff in /home/runner/work/gh-workflow/gh-workflow/crates/gh-workflow-tailcall/src/workflow.rs

if self.benchmarks {
job = job.add_step(
Cargo::new("bench")
.args("--workspace")
.name("Cargo Bench"),
);
}

job
}
}

impl From<Workflow> for GHWorkflow {
Expand All @@ -61,7 +105,7 @@ impl From<Workflow> for GHWorkflow {
let cond = is_main.and(is_push);

// Jobs
let build = build_and_test();
let build = value.build_and_test();
let mut workflow = GHWorkflow::new(value.name)
.add_env(flags)
.on(event)
Expand Down Expand Up @@ -114,33 +158,3 @@ fn release_job(cond: &Context<bool>, build: &Job, permissions: &Permissions) ->
.add_step(Step::checkout())
.add_step(Release::default().command(Command::Release))
}

fn build_and_test() -> Job {
Job::new("Build and Test")
.permissions(Permissions::default().contents(Level::Read))
.add_step(Step::checkout())
.add_step(
Toolchain::default()
.add_stable()
.add_nightly()
.add_clippy()
.add_fmt(),
)
.add_step(
Cargo::new("test")
.args("--all-features --workspace")
.name("Cargo Test"),
)
.add_step(
Cargo::new("fmt")
.nightly()
.args("--check")
.name("Cargo Fmt"),
)
.add_step(
Cargo::new("clippy")
.nightly()
.args("--all-features --workspace -- -D warnings")
.name("Cargo Clippy"),
)
}

0 comments on commit edc5edb

Please sign in to comment.