From 6a2c5e899b327bfae3b359c0592bd48bbe77fccb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=BCller?= Date: Thu, 5 Oct 2023 14:52:37 +0200 Subject: [PATCH] Added more complex removing of the TagV to support mono-repositories with tag folders --- NetRevisionTask/RevisionFormatter.cs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/NetRevisionTask/RevisionFormatter.cs b/NetRevisionTask/RevisionFormatter.cs index e74f364..404db63 100644 --- a/NetRevisionTask/RevisionFormatter.cs +++ b/NetRevisionTask/RevisionFormatter.cs @@ -102,8 +102,15 @@ public string Resolve(string format) } string tagName = RevisionData.Tag; - if (RemoveTagV && Regex.IsMatch(tagName, "^v[0-9]")) - { + // This detects any pattern of v1 to v1.2.3-foo. + // It is way more complex, but can also trim tags like "project-one/v1.2.3-alpha2". + // These tag-types are often used by mono-repositories. + string versionPattern = @"v([0-9]+(?:\.[0-9]+(?:\.[0-9]+)?)?)(?:-(.+))?$"; + if (RemoveTagV && Regex.IsMatch(tagName, versionPattern)) + { + // Replace anything around the pattern. + tagName = tagName.Replace(Regex.Replace(tagName, versionPattern, ""), ""); + // Remove the "v" at the start. tagName = tagName.Substring(1); } format = format.Replace("{semvertag}", GetSemVerTagSpec(tagName));