Skip to content

Commit

Permalink
refactor: use gh-workflow-tailcall in the test
Browse files Browse the repository at this point in the history
  • Loading branch information
tusharmath committed Nov 29, 2024
1 parent d1efcbf commit 8298219
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 90 deletions.
16 changes: 15 additions & 1 deletion crates/gh-workflow-tailcall/src/workflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

use ctx::Context;
use derive_setters::Setters;
use gh_workflow::error::Result;
use gh_workflow::{Workflow as GHWorkflow, *};
use release_plz::{Command, Release};
use toolchain::Toolchain;
Expand All @@ -24,7 +25,20 @@ pub struct Workflow {

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

impl Workflow {
/// Generates and tests the workflow file.
pub fn generate(self) -> Result<()> {
let workflow: GHWorkflow = self.into();
workflow.generate()
}

/// Converts the workflow into a Github workflow.
pub fn to_github_workflow(&self) -> GHWorkflow {
self.clone().into()
}
}

Expand Down
90 changes: 2 additions & 88 deletions crates/gh-workflow-tailcall/tests/ci.rs
Original file line number Diff line number Diff line change
@@ -1,92 +1,6 @@
use ctx::Context;
use gh_workflow::*;
use release_plz::{Command, Release};
use toolchain::Toolchain;
use gh_workflow_tailcall::Workflow;

#[test]
fn generate() {
let flags = RustFlags::deny("warnings");

let build = 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"),
);

let event = Event::default()
.push(Push::default().add_branch("main"))
.pull_request(
PullRequest::default()
.add_type(PullRequestType::Opened)
.add_type(PullRequestType::Synchronize)
.add_type(PullRequestType::Reopened)
.add_branch("main"),
);

let permissions = Permissions::default()
.pull_requests(Level::Write)
.packages(Level::Write)
.contents(Level::Write);

let is_main = Context::github().ref_().eq("refs/heads/main".into());
let is_push = Context::github().event_name().eq("push".into());
let cond = is_main.and(is_push);

let release = Job::new("Release")
.cond(cond.clone())
.add_needs(build.clone())
.add_env(Env::github())
.add_env(Env::new(
"CARGO_REGISTRY_TOKEN",
"${{ secrets.CARGO_REGISTRY_TOKEN }}",
))
.permissions(permissions.clone())
.add_step(Step::checkout())
.add_step(Release::default().command(Command::Release));

let release_pr = Job::new("Release PR")
.cond(cond.clone())
.concurrency(
Concurrency::new(Expression::new("release-${{github.ref}}")).cancel_in_progress(false),
)
.add_needs(build.clone())
.add_env(Env::github())
.add_env(Env::new(
"CARGO_REGISTRY_TOKEN",
"${{ secrets.CARGO_REGISTRY_TOKEN }}",
))
.permissions(permissions)
.add_step(Step::checkout())
.add_step(Release::default().command(Command::ReleasePR));

Workflow::new("CI")
.add_env(flags)
.on(event)
.add_job("build", build)
.add_job("release", release)
.add_job("release-pr", release_pr)
.generate()
.unwrap();
Workflow::default().auto_release(true).generate().unwrap();
}
2 changes: 1 addition & 1 deletion crates/gh-workflow/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ pub enum Error {
MissingWorkflowFile(std::path::PathBuf),
}

pub(crate) type Result<T> = std::result::Result<T, Error>;
pub type Result<T> = std::result::Result<T, Error>;

0 comments on commit 8298219

Please sign in to comment.