Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add benchmark to workflow #97

Merged
merged 2 commits into from
Dec 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@

/// 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 @@
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 @@
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 @@
.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"),
)
}
Loading