Skip to content

Commit 26ef5f9

Browse files
feat(event): add tags filter to Push struct for event handling (#157)
* feat(event): add tags filter to Push struct for event handling * refactor: simplify string formatting in various display implementations * feat(workflow): add tag filter to Push event for versioning * feat(workflow): add tag support for push events in CI configuration * feat(workflow): add tag support for push events in autofix CI configuration
1 parent e6b797b commit 26ef5f9

File tree

9 files changed

+41
-29
lines changed

9 files changed

+41
-29
lines changed

.github/workflows/autofix.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ on:
2929
push:
3030
branches:
3131
- main
32+
tags:
33+
- v*
3234
jobs:
3335
lint:
3436
name: Lint Fix

.github/workflows/ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ on:
2929
push:
3030
branches:
3131
- main
32+
tags:
33+
- v*
3234
jobs:
3335
build:
3436
name: Build and Test

crates/gh-workflow-tailcall/src/standard.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ impl StandardWorkflow {
239239

240240
fn workflow_event(&self) -> Event {
241241
Event::default()
242-
.push(Push::default().add_branch("main"))
242+
.push(Push::default().add_branch("main").add_tag("v*"))
243243
.pull_request(
244244
PullRequest::default()
245245
.add_type(PullRequestType::Opened)

crates/gh-workflow/src/cargo.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ impl From<Cargo> for Step<Run> {
7474
let mut command = vec!["cargo".to_string()];
7575

7676
if let Some(toolchain) = value.toolchain {
77-
command.push(format!("+{}", toolchain));
77+
command.push(format!("+{toolchain}"));
7878
}
7979

8080
command.push(value.command);

crates/gh-workflow/src/ctx.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -202,25 +202,25 @@ impl fmt::Display for Step {
202202
Step::Root => write!(f, ""),
203203
Step::Select { name, object } => {
204204
if matches!(**object, Step::Root) {
205-
write!(f, "{}", name)
205+
write!(f, "{name}")
206206
} else {
207-
write!(f, "{}.{}", object, name)
207+
write!(f, "{object}.{name}")
208208
}
209209
}
210210
Step::Eq { left, right } => {
211-
write!(f, "{} == {}", left, right)
211+
write!(f, "{left} == {right}")
212212
}
213213
Step::And { left, right } => {
214-
write!(f, "{} && {}", left, right)
214+
write!(f, "{left} && {right}")
215215
}
216216
Step::Or { left, right } => {
217-
write!(f, "{} || {}", left, right)
217+
write!(f, "{left} || {right}")
218218
}
219219
Step::Literal(value) => {
220-
write!(f, "'{}'", value)
220+
write!(f, "'{value}'")
221221
}
222222
Step::Concat { left, right } => {
223-
write!(f, "{}{}", left, right)
223+
write!(f, "{left}{right}")
224224
}
225225
}
226226
}

crates/gh-workflow/src/event.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,9 @@ pub struct Push {
643643
/// Filter on specific file paths
644644
#[serde(default, skip_serializing_if = "Vec::is_empty")]
645645
pub paths: Vec<String>,
646+
/// Filter on specific tags
647+
#[serde(default, skip_serializing_if = "Vec::is_empty")]
648+
pub tags: Vec<String>,
646649
}
647650

648651
impl Push {
@@ -657,6 +660,12 @@ impl Push {
657660
self.paths.push(path.into());
658661
self
659662
}
663+
664+
/// Adds a tag name to filter on
665+
pub fn add_tag<S: Into<String>>(mut self, tag: S) -> Self {
666+
self.tags.push(tag.into());
667+
self
668+
}
660669
}
661670

662671
/// Types of registry package events

crates/gh-workflow/src/generate.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
//! This module provides functionality to customize generation of the GitHub
22
//! Actions workflow files.
33
4-
use std::io::ErrorKind;
54
use std::path::PathBuf;
65
use std::process::Command;
76

@@ -70,7 +69,7 @@ impl Generate {
7069
}
7170
Err(Error::MissingWorkflowFile(path)) => {
7271
std::fs::create_dir_all(path.parent().ok_or(Error::IO(
73-
std::io::Error::new(ErrorKind::Other, "Invalid parent dir(s) path"),
72+
std::io::Error::other("Invalid parent dir(s) path"),
7473
))?)?;
7574
std::fs::write(path.clone(), content)?;
7675
println!("Generated workflow file: {}", path.display());
@@ -113,13 +112,13 @@ fn organize_job_dependency(mut workflow: Workflow) -> Workflow {
113112
job_ids.push(id.to_owned());
114113
} else {
115114
// Create a job-id for the job
116-
let id = format!("job-{}", job_id);
115+
let id = format!("job-{job_id}");
117116

118117
// Add job id as the dependency
119118
job_ids.push(id.clone());
120119

121120
// Insert the missing job into the new_jobs
122-
new_jobs.insert(format!("job-{}", job_id), job.clone());
121+
new_jobs.insert(format!("job-{job_id}"), job.clone());
123122

124123
job_id += 1;
125124
}

crates/gh-workflow/src/rust_flag.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,14 @@ impl Display for RustFlags {
5656
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
5757
match self {
5858
RustFlags::Lint(name, lint) => match lint {
59-
Lint::Allow => write!(f, "-A{}", name),
60-
Lint::Warn => write!(f, "-W{}", name),
61-
Lint::Deny => write!(f, "-D{}", name),
62-
Lint::Forbid => write!(f, "-F{}", name),
63-
Lint::Codegen => write!(f, "-C{}", name),
64-
Lint::Experiment => write!(f, "-Z{}", name),
59+
Lint::Allow => write!(f, "-A{name}"),
60+
Lint::Warn => write!(f, "-W{name}"),
61+
Lint::Deny => write!(f, "-D{name}"),
62+
Lint::Forbid => write!(f, "-F{name}"),
63+
Lint::Codegen => write!(f, "-C{name}"),
64+
Lint::Experiment => write!(f, "-Z{name}"),
6565
},
66-
RustFlags::Combine(lhs, rhs) => write!(f, "{} {}", lhs, rhs),
66+
RustFlags::Combine(lhs, rhs) => write!(f, "{lhs} {rhs}"),
6767
}
6868
}
6969
}

crates/gh-workflow/src/toolchain.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ impl Display for Component {
4444
Component::Rustfmt => "rustfmt",
4545
Component::RustDoc => "rust-doc",
4646
};
47-
write!(f, "{}", val)
47+
write!(f, "{val}")
4848
}
4949
}
5050

@@ -64,7 +64,7 @@ impl Display for Arch {
6464
Arch::Arm => "arm",
6565
Arch::Wasm32 => "wasm32",
6666
};
67-
write!(f, "{}", val)
67+
write!(f, "{val}")
6868
}
6969
}
7070

@@ -82,7 +82,7 @@ impl Display for Vendor {
8282
Vendor::Apple => "apple",
8383
Vendor::PC => "pc",
8484
};
85-
write!(f, "{}", val)
85+
write!(f, "{val}")
8686
}
8787
}
8888

@@ -102,7 +102,7 @@ impl Display for System {
102102
System::Linux => "linux",
103103
System::Darwin => "darwin",
104104
};
105-
write!(f, "{}", val)
105+
write!(f, "{val}")
106106
}
107107
}
108108

@@ -122,7 +122,7 @@ impl Display for Abi {
122122
Abi::Msvc => "msvc",
123123
Abi::Musl => "musl",
124124
};
125-
write!(f, "{}", val)
125+
write!(f, "{val}")
126126
}
127127
}
128128

@@ -205,10 +205,10 @@ impl From<Toolchain> for Step<Use> {
205205
Version::Stable => "stable".to_string(),
206206
Version::Nightly => "nightly".to_string(),
207207
Version::Custom((major, minor, patch)) => {
208-
format!("{}.{}.{}", major, minor, patch)
208+
format!("{major}.{minor}.{patch}")
209209
}
210210
})
211-
.reduce(|acc, a| format!("{}, {}", acc, a));
211+
.reduce(|acc, a| format!("{acc}, {a}"));
212212

213213
let mut input = Input::default();
214214

@@ -233,7 +233,7 @@ impl From<Toolchain> for Step<Use> {
233233
.components
234234
.iter()
235235
.map(|c| c.to_string())
236-
.reduce(|acc, a| format!("{}, {}", acc, a))
236+
.reduce(|acc, a| format!("{acc}, {a}"))
237237
.unwrap_or_default();
238238

239239
input = input.add("components", components);
@@ -252,7 +252,7 @@ impl From<Toolchain> for Step<Use> {
252252
let cache_workspaces = value
253253
.cache_workspaces
254254
.iter()
255-
.fold("".to_string(), |acc, a| format!("{}\n{}", acc, a));
255+
.fold("".to_string(), |acc, a| format!("{acc}\n{a}"));
256256

257257
input = input.add("cache-workspaces", cache_workspaces);
258258
}

0 commit comments

Comments
 (0)