Skip to content

flowey: add ADO trigger for tags #1272

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 37 additions & 7 deletions flowey/flowey_cli/src/pipeline_resolver/ado_yaml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -571,18 +571,48 @@ EOF
let flowey_core::pipeline::AdoCiTriggers {
branches,
exclude_branches,
tags,
exclude_tags,
batch,
} = t;

if branches.is_empty() && tags.is_empty() {
anyhow::bail!("branches and tags cannot both be empty")
}

schema_ado_yaml::CiTrigger::Some {
batch,
branches: schema_ado_yaml::TriggerBranches {
include: branches,
exclude: if exclude_branches.is_empty() {
None
} else {
Some(exclude_branches)
},
branches: if branches.is_empty() {
if !exclude_branches.is_empty() {
anyhow::bail!("empty branch trigger with non-empty exclude")
}

None
} else {
Some(schema_ado_yaml::TriggerBranches {
include: branches,
exclude: if exclude_branches.is_empty() {
None
} else {
Some(exclude_branches)
},
})
},
tags: if tags.is_empty() {
if !exclude_tags.is_empty() {
anyhow::bail!("empty tags trigger with non-empty exclude")
}

None
} else {
Some(schema_ado_yaml::TriggerTags {
include: tags,
exclude: if exclude_tags.is_empty() {
None
} else {
Some(exclude_tags)
},
})
},
}
}
Expand Down
14 changes: 10 additions & 4 deletions flowey/flowey_core/src/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,18 @@ pub struct AdoPrTriggers {
/// Trigger ADO pipelines per PR
#[derive(Debug, Default)]
pub struct AdoCiTriggers {
/// Run the pipeline whenever there is a PR to these specified branches
/// Run the pipeline whenever there is a change to these specified branches
/// (supports glob syntax)
pub branches: Vec<String>,
/// Specify any branches which should be filtered out from the list of
/// `branches` (supports glob syntax)
pub exclude_branches: Vec<String>,
/// Run the pipeline whenever a matching tag is created (supports glob
/// syntax)
pub tags: Vec<String>,
/// Specify any tags which should be filtered out from the list of `tags`
/// (supports glob syntax)
pub exclude_tags: Vec<String>,
/// Whether to batch changes per branch.
pub batch: bool,
}
Expand Down Expand Up @@ -238,14 +244,14 @@ pub struct GhPrTriggers {
/// Trigger Github Actions pipelines per PR
#[derive(Debug, Default)]
pub struct GhCiTriggers {
/// Run the pipeline whenever there is a PR to these specified branches
/// Run the pipeline whenever there is a change to these specified branches
/// (supports glob syntax)
pub branches: Vec<String>,
/// Specify any branches which should be filtered out from the list of
/// `branches` (supports glob syntax)
pub exclude_branches: Vec<String>,
/// Run the pipeline whenever there is a PR to these specified tags
/// (supports glob syntax)
/// Run the pipeline whenever a matching tag is created (supports glob
/// syntax)
pub tags: Vec<String>,
/// Specify any tags which should be filtered out from the list of `tags`
/// (supports glob syntax)
Expand Down
15 changes: 14 additions & 1 deletion flowey/schema_ado_yaml/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,16 @@ pub struct TriggerBranches {
pub exclude: Option<Vec<String>>,
}

#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct TriggerTags {
#[serde(skip_serializing_if = "Vec::is_empty")]
pub include: Vec<String>,
// Wrapping this in an Option is necessary to prevent problems when deserializing and exclude isn't present
#[serde(skip_serializing_if = "Option::is_none")]
pub exclude: Option<Vec<String>>,
}

#[derive(Debug, Serialize, Deserialize)]
#[serde(untagged)]
#[serde(rename_all = "camelCase")]
Expand All @@ -87,7 +97,10 @@ pub enum CiTrigger {
#[serde(rename_all = "camelCase")]
Some {
batch: bool,
branches: TriggerBranches,
#[serde(skip_serializing_if = "Option::is_none")]
branches: Option<TriggerBranches>,
Copy link
Member Author

@benhillis benhillis May 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue here was if branches was empty, the generated yml would get an entry that looked like

trigger:
  branches: {}

which is not valid yml.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be worth investigating if that's an issue with the yaml crate being used. Sounds like a upstream bug

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this is an issue with the yaml crate, seems like this is a valid fix to omit empty elements.

#[serde(skip_serializing_if = "Option::is_none")]
tags: Option<TriggerTags>,
},
// serde has a bug with untagged and `with` during deserialization
NoneWorkaround(String),
Expand Down