From 807ae858d9ac4447a628bf0c4ad2b25fcb1d2bda Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Mon, 2 Oct 2023 16:35:28 +0200 Subject: [PATCH] Use a regex to detect a release branch. (#13106) Using the suggested regex from semver.org. --- nukebuild/BuildParameters.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/nukebuild/BuildParameters.cs b/nukebuild/BuildParameters.cs index 897fdc84f12..45cbf007983 100644 --- a/nukebuild/BuildParameters.cs +++ b/nukebuild/BuildParameters.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Runtime.InteropServices; +using System.Text.RegularExpressions; using System.Xml.Linq; using Nuke.Common; using Nuke.Common.CI.AzurePipelines; @@ -38,7 +39,7 @@ public class BuildParameters public string RepositoryName { get; } public string RepositoryBranch { get; } public string ReleaseConfiguration { get; } - public string ReleaseBranchPrefix { get; } + public Regex ReleaseBranchRegex { get; } public string MSBuildSolution { get; } public bool IsLocalBuild { get; } public bool IsRunningOnUnix { get; } @@ -77,7 +78,7 @@ public BuildParameters(Build b) // CONFIGURATION MainRepo = "https://github.com/AvaloniaUI/Avalonia"; MasterBranch = "refs/heads/master"; - ReleaseBranchPrefix = "refs/heads/release/"; + ReleaseBranchRegex = new("^refs/heads/release/(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?$"); ReleaseConfiguration = "Release"; MSBuildSolution = RootDirectory / "dirs.proj"; @@ -101,8 +102,7 @@ public BuildParameters(Build b) RepositoryName); IsMasterBranch = StringComparer.OrdinalIgnoreCase.Equals(MasterBranch, RepositoryBranch); - IsReleaseBranch = RepositoryBranch?.StartsWith(ReleaseBranchPrefix, StringComparison.OrdinalIgnoreCase) == - true; + IsReleaseBranch = RepositoryBranch is not null && ReleaseBranchRegex.IsMatch(RepositoryBranch); IsReleasable = StringComparer.OrdinalIgnoreCase.Equals(ReleaseConfiguration, Configuration); IsMyGetRelease = IsReleasable;