Skip to content

Commit

Permalink
chore: add concurrency in release
Browse files Browse the repository at this point in the history
  • Loading branch information
tusharmath committed Nov 28, 2024
1 parent bfc4d0f commit c597a32
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,6 @@ jobs:
uses: MarcoIeni/[email protected]
with:
command: release-pr
concurrency:
group: release-${{github.ref}}
cancel-in-progress: false
19 changes: 19 additions & 0 deletions crates/gh-workflow/src/ctx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ enum Step {
right: Box<Step>,
},
Literal(String),
Concat {
left: Box<Step>,
right: Box<Step>,
},
}

impl<A> Context<A> {
Expand Down Expand Up @@ -83,6 +87,18 @@ impl<A> Context<A> {
}
}

impl Context<String> {
pub fn concat(&self, other: Context<String>) -> Context<String> {
Context {
marker: Default::default(),
step: Step::Concat {
left: Box::new(self.step.clone()),
right: Box::new(other.step),
},
}
}
}

#[allow(unused)]
#[derive(Context)]
pub struct Github {
Expand Down Expand Up @@ -203,6 +219,9 @@ impl fmt::Display for Step {
Step::Literal(value) => {
write!(f, "'{}'", value)
}
Step::Concat { left, right } => {
write!(f, "{}{}", left, right)
}
}
}
}
Expand Down
7 changes: 7 additions & 0 deletions crates/gh-workflow/src/workflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,13 @@ pub struct Concurrency {
pub limit: Option<u32>,
}

impl Concurrency {
pub fn new(group: impl Into<Expression>) -> Self {
let expr: Expression = group.into();
Self { group: expr.0, ..Default::default() }
}
}

/// Represents permissions for the `GITHUB_TOKEN`.
#[derive(Debug, Setters, Serialize, Deserialize, Clone, Default, PartialEq, Eq)]
#[serde(rename_all = "kebab-case")]
Expand Down
3 changes: 3 additions & 0 deletions crates/gh-workflow/tests/ci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ fn generate() {
.add_step(Release::default().command(Command::Release));

let release_pr = Job::new("Release PR")
.concurrency(
Concurrency::new(Expression::new("release-${{github.ref}}")).cancel_in_progress(false),
)
.add_needs(build.clone())
.add_env(Env::github())
.add_env(Env::new(
Expand Down

0 comments on commit c597a32

Please sign in to comment.