Skip to content

Commit

Permalink
feat: add gh-workflow-tailcall
Browse files Browse the repository at this point in the history
  • Loading branch information
tusharmath committed Nov 29, 2024
1 parent 8aa50a2 commit f8f0d58
Show file tree
Hide file tree
Showing 6 changed files with 150 additions and 1 deletion.
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
[workspace]
edition = "2021"
resolver = "2"
members = ["crates/*"]
20 changes: 20 additions & 0 deletions crates/gh-workflow-tailcall/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[package]
name = "gh-workflow-tailcall"
version = "0.1.0"
edition = "2021"


description = "macros for gh-workflow"
license = "Apache-2.0"
documentation = "https://docs.rs/gh-workflow"
homepage = "https://github.com/tailcallhq/gh-workflow"
repository = "https://github.com/tailcallhq/gh-workflow"
keywords = ["github", "actions", "workflow", "generator"]

[dependencies]
derive_setters = { version = "0.1.6" }
gh-workflow = { path = "../gh-workflow", version = "0.5.1" }

[dev-dependencies]
insta = "1.40.0"
pretty_assertions = "1.4.1"
3 changes: 3 additions & 0 deletions crates/gh-workflow-tailcall/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
mod workflow;

pub use workflow::*;
117 changes: 117 additions & 0 deletions crates/gh-workflow-tailcall/src/workflow.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
//! Workflow for all tailcall projects free and open source for everyone.

use ctx::Context;
use derive_setters::Setters;
use gh_workflow::*;
use release_plz::{Command, Release};
use toolchain::Toolchain;

#[derive(Default, Debug, Clone, Setters)]

Check failure on line 9 in crates/gh-workflow-tailcall/src/workflow.rs

View workflow job for this annotation

GitHub Actions / Build and Test

struct update has no effect, all the fields in the struct have already been specified
pub struct TailcallWorkflow {
pub release: bool,
}

impl TailcallWorkflow {}

impl From<TailcallWorkflow> for Workflow {
fn from(value: TailcallWorkflow) -> Self {
let flags = RustFlags::deny("warnings");

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 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);

// Jobs
let build = build_and_test();
let mut workflow = Workflow::new("CI")
.add_env(flags)
.on(event)
.add_job("build", build.clone());

if value.release {
let permissions = Permissions::default()
.pull_requests(Level::Write)
.packages(Level::Write)
.contents(Level::Write);

let release = release_job(&cond, &build, &permissions);
let release_pr = release_pr_job(cond, &build, permissions);
workflow = workflow
.add_job("release", release)
.add_job("release-pr", release_pr);
}

workflow
}
}

fn release_pr_job(cond: Context<bool>, build: &Job, permissions: Permissions) -> Job {
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))
}

fn release_job(cond: &Context<bool>, build: &Job, permissions: &Permissions) -> Job {
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))
}

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"),
)
}
File renamed without changes.

0 comments on commit f8f0d58

Please sign in to comment.