Skip to content

Commit 4347d62

Browse files
benhillisBen Hillis
andauthored
flowey: add ADO trigger for tags (#1272)
This change introduces the ability to trigger pipelines when tags are created. While developing this change I also noticed that the current ADO CI triggers functionality did not generate correct yaml when an empty vector of trigger branches is specified, so a fix for that issue is included as well. --------- Co-authored-by: Ben Hillis <benhill@ntdev.microsoft.com>
1 parent 777b393 commit 4347d62

File tree

3 files changed

+61
-12
lines changed

3 files changed

+61
-12
lines changed

flowey/flowey_cli/src/pipeline_resolver/ado_yaml.rs

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -567,18 +567,48 @@ EOF
567567
let flowey_core::pipeline::AdoCiTriggers {
568568
branches,
569569
exclude_branches,
570+
tags,
571+
exclude_tags,
570572
batch,
571573
} = t;
572574

575+
if branches.is_empty() && tags.is_empty() {
576+
anyhow::bail!("branches and tags cannot both be empty")
577+
}
578+
573579
schema_ado_yaml::CiTrigger::Some {
574580
batch,
575-
branches: schema_ado_yaml::TriggerBranches {
576-
include: branches,
577-
exclude: if exclude_branches.is_empty() {
578-
None
579-
} else {
580-
Some(exclude_branches)
581-
},
581+
branches: if branches.is_empty() {
582+
if !exclude_branches.is_empty() {
583+
anyhow::bail!("empty branch trigger with non-empty exclude")
584+
}
585+
586+
None
587+
} else {
588+
Some(schema_ado_yaml::TriggerBranches {
589+
include: branches,
590+
exclude: if exclude_branches.is_empty() {
591+
None
592+
} else {
593+
Some(exclude_branches)
594+
},
595+
})
596+
},
597+
tags: if tags.is_empty() {
598+
if !exclude_tags.is_empty() {
599+
anyhow::bail!("empty tags trigger with non-empty exclude")
600+
}
601+
602+
None
603+
} else {
604+
Some(schema_ado_yaml::TriggerTags {
605+
include: tags,
606+
exclude: if exclude_tags.is_empty() {
607+
None
608+
} else {
609+
Some(exclude_tags)
610+
},
611+
})
582612
},
583613
}
584614
}

flowey/flowey_core/src/pipeline.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,12 +157,18 @@ pub struct AdoPrTriggers {
157157
/// Trigger ADO pipelines per PR
158158
#[derive(Debug, Default)]
159159
pub struct AdoCiTriggers {
160-
/// Run the pipeline whenever there is a PR to these specified branches
160+
/// Run the pipeline whenever there is a change to these specified branches
161161
/// (supports glob syntax)
162162
pub branches: Vec<String>,
163163
/// Specify any branches which should be filtered out from the list of
164164
/// `branches` (supports glob syntax)
165165
pub exclude_branches: Vec<String>,
166+
/// Run the pipeline whenever a matching tag is created (supports glob
167+
/// syntax)
168+
pub tags: Vec<String>,
169+
/// Specify any tags which should be filtered out from the list of `tags`
170+
/// (supports glob syntax)
171+
pub exclude_tags: Vec<String>,
166172
/// Whether to batch changes per branch.
167173
pub batch: bool,
168174
}
@@ -238,14 +244,14 @@ pub struct GhPrTriggers {
238244
/// Trigger Github Actions pipelines per PR
239245
#[derive(Debug, Default)]
240246
pub struct GhCiTriggers {
241-
/// Run the pipeline whenever there is a PR to these specified branches
247+
/// Run the pipeline whenever there is a change to these specified branches
242248
/// (supports glob syntax)
243249
pub branches: Vec<String>,
244250
/// Specify any branches which should be filtered out from the list of
245251
/// `branches` (supports glob syntax)
246252
pub exclude_branches: Vec<String>,
247-
/// Run the pipeline whenever there is a PR to these specified tags
248-
/// (supports glob syntax)
253+
/// Run the pipeline whenever a matching tag is created (supports glob
254+
/// syntax)
249255
pub tags: Vec<String>,
250256
/// Specify any tags which should be filtered out from the list of `tags`
251257
/// (supports glob syntax)

flowey/schema_ado_yaml/src/lib.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,16 @@ pub struct TriggerBranches {
6565
pub exclude: Option<Vec<String>>,
6666
}
6767

68+
#[derive(Debug, Serialize, Deserialize)]
69+
#[serde(rename_all = "camelCase")]
70+
pub struct TriggerTags {
71+
#[serde(skip_serializing_if = "Vec::is_empty")]
72+
pub include: Vec<String>,
73+
// Wrapping this in an Option is necessary to prevent problems when deserializing and exclude isn't present
74+
#[serde(skip_serializing_if = "Option::is_none")]
75+
pub exclude: Option<Vec<String>>,
76+
}
77+
6878
#[derive(Debug, Serialize, Deserialize)]
6979
#[serde(untagged)]
7080
#[serde(rename_all = "camelCase")]
@@ -88,7 +98,10 @@ pub enum CiTrigger {
8898
#[serde(rename_all = "camelCase")]
8999
Some {
90100
batch: bool,
91-
branches: TriggerBranches,
101+
#[serde(skip_serializing_if = "Option::is_none")]
102+
branches: Option<TriggerBranches>,
103+
#[serde(skip_serializing_if = "Option::is_none")]
104+
tags: Option<TriggerTags>,
92105
},
93106
// serde has a bug with untagged and `with` during deserialization
94107
NoneWorkaround(String),

0 commit comments

Comments
 (0)