-
Notifications
You must be signed in to change notification settings - Fork 361
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
MSBuild Task for Semantic Versioning & Tests #137
Conversation
|
||
namespace Microsoft.DotNet.Build.Tasks.SemVer | ||
{ | ||
public class SemVer : Task |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
} | ||
|
||
// So far we know that these first four fields aren't empty | ||
Version = $"{Major}.{Minor}.{Patch}-{Prerelease}.{ShortDate:00000}.{Builds}+{ShortSHA}"; |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
{ | ||
private Dictionary<string, string> formats = new Dictionary<string, string> { | ||
{"dev", "{major}.{minor}.{patch}-{prerelease}.{shortdate}.{builds}+{shortsha}"}, | ||
{"stable", "{major}.{minor}.{patch}-{prerelease}"}, |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
<ItemGroup Condition="'$(TargetFramework)' == '$(NetFxTfm)'"> | ||
<Reference Include="Microsoft.Build.Tasks.v4.0" /> | ||
<Reference Include="Microsoft.Build.Framework" /> | ||
<Reference Include="Microsoft.Build.Utilities.v4.0" /> |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
VersionString = VersionString.Replace("{builds}", Builds.ToString()); | ||
VersionString = VersionString.Replace("{shortsha}", ShortSHA); | ||
|
||
return true; |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
{ | ||
public class SemVer : Task | ||
{ | ||
private Dictionary<string, string> formats = new Dictionary<string, string> { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
VersionString = formats[VersionString]; | ||
} | ||
|
||
if ((VersionString.Contains("{major}") && Major == 0) || |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
{ | ||
VersionString = FormatString.ToLower(); | ||
|
||
if (formats.ContainsKey(VersionString)) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few comments.
I'm still very much interested in why this is a task instead of just done in a targets file? All we are doing is appending strings. |
Talked with @weshaggard and @mmitche ; I am going to work on the changes they suggested. |
… need some kind of date manipulation eventually.
Hi guys, I've applied the changes. PTAL |
=============================== | ||
|
||
Task package which handles generation of version strings. | ||
The format that we use is described here: Documentation/Versioning.md |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
ShortSha | string | SHA of the repo last commit. | ||
FormatName | string | The name of the format string you want to use. Defaults are "dev", "stable" and "final". | ||
FormatStrings | ItemGroup | Your custom format strings. | ||
ExitCode | integer | **Output** Indicate whether an error happened (1) or not (0). |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
<PropertyGroup> | ||
<VersionString Condition="'%(FormatStrings.Identity)'=='$(FormatName)'">%(FormatStrings.Format)</VersionString> | ||
|
||
<ExitCode Condition="'$(VersionString)'!=''">0</ExitCode> |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
if (months > 0) //only allow dates after comparedate | ||
{ | ||
return string.Format("{0}{1}", months.ToString("D" + (Padding - 2)), seedDate.Day.ToString("D2")); | ||
} |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
|
||
<Target Name="Versioning"> | ||
|
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Are those TestCase01.xml files csproj's? If so then that is similar to what I had in mind. Having some sample test projects that we call msbuild on and capture the output of the version in some way, or asserting it in the projects themselves by having them fail to build if the versions don't match what is expected. |
Yes, that's exactly it. |
@joperezr given your experience doing this in Buildtools could you also review this PR? |
Sure, I’ll take a look at this later today |
@@ -0,0 +1,134 @@ | |||
# Microsoft.DotNet.Build.Tasks.Versioning | |||
|
|||
Task package which handles generation of version strings. The versioning format that we use is described [here](../../Documentation/Versioning). See ["Task Packages"](../../Documentation/TaskPackages.md#usage) for guidance on installing this package. |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Hi @mmitche, @weshaggard / all; I believe we have sufficient material here to call this a minimal working version. Please, let me know what else I should work to get an approval for the merge :-) |
} | ||
|
||
// Leading zeros are only allowed in SemVer 1.0 | ||
if (IncludePadding) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Factoring reference to Buildtools framework. Some typos / minor fixes here and there.
|
||
dateFromBuildId = dateFromBuildId.ToUniversalTime(); | ||
GeneratedShortDate = CreateShortDate(dateFromBuildId, ComparisonDate); | ||
GeneratedRevision = match.Groups[2].Value; |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Yeah, 2. Semver1 only.
From: Divino César <notifications@github.com>
Sent: Tuesday, May 15, 2018 2:58 PM
To: dotnet/arcade <arcade@noreply.github.com>
Cc: Matt Mitchell <mmitche@microsoft.com>; Mention <mention@noreply.github.com>
Subject: Re: [dotnet/arcade] MSBuild Task for Semantic Versioning & Tests (#137)
@JohnTortugo commented on this pull request.
________________________________
In src/Microsoft.DotNet.Build.Tasks.Versioning/src/GenerateVersioningDate.cs<https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fdotnet%2Farcade%2Fpull%2F137%23discussion_r188449173&data=02%7C01%7Cmmitche%40microsoft.com%7C95a6f0be6e5c4966a89608d5baaedd0c%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C636620182555783776&sdata=P9hm9ttICt%2Fl8mxSg282HtjwzhB%2FytxTXcsGo0Eetis%3D&reserved=0>:
+ Match match = regex.Match(buildId);
+
+ if (match.Success && match.Groups.Count > 2)
+ {
+ string dateFormat = "yyyyMMdd";
+ DateTime dateFromBuildId;
+
+ if (!DateTime.TryParseExact(match.Groups[1].Value, dateFormat, enUS, DateTimeStyles.AssumeLocal, out dateFromBuildId))
+ {
+ Log.LogError("The OfficialBuildId doesn't follow the expected({0}.rr) format: '{1}'", dateFormat, match.Groups[1].Value);
+ return false;
+ }
+
+ dateFromBuildId = dateFromBuildId.ToUniversalTime();
+ GeneratedShortDate = CreateShortDate(dateFromBuildId, ComparisonDate);
+ GeneratedRevision = match.Groups[2].Value;
Actually I wasn't aware that we needed padding for the Revision. How much should it be? Two digits?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub<https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fdotnet%2Farcade%2Fpull%2F137%23discussion_r188449173&data=02%7C01%7Cmmitche%40microsoft.com%7C95a6f0be6e5c4966a89608d5baaedd0c%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C636620182555793784&sdata=vYiC8Vcq1tot0qxgwRPCL9vPGzcBbtiwoiEua1sdajE%3D&reserved=0>, or mute the thread<https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAIUisvh4gsE5jlcBuwVmvVyAskpT4woLks5ty09MgaJpZM4TnxL1&data=02%7C01%7Cmmitche%40microsoft.com%7C95a6f0be6e5c4966a89608d5baaedd0c%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C636620182555803793&sdata=TYUk%2Fx6Ae7LJMF4ummYnZ%2FbTy8h5sbTPifoWvss1h8g%3D&reserved=0>.
|
Thanks. Pushed new update. |
@@ -60,7 +60,7 @@ public override bool Execute() | |||
// If OfficialBuildId is passed in, then use that to calculate the version and revision. | |||
if (string.IsNullOrEmpty(OfficialBuildId)) | |||
{ | |||
GeneratedRevision = "0"; | |||
GeneratedRevision = (IncludePadding) ? "00" : "0"; |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
@@ -123,6 +124,11 @@ private bool SetVersionAndRevisionFromBuildId(string buildId) | |||
GeneratedShortDate = CreateShortDate(dateFromBuildId, ComparisonDate); | |||
GeneratedRevision = match.Groups[2].Value; | |||
|
|||
if (!IncludePadding) | |||
{ | |||
GeneratedRevision = int.Parse(GeneratedRevision).ToString(); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
</Target> | ||
|
||
|
||
<Target Name="CreateVersioningCacheFile" AfterTargets="GenerateVersions" Condition="'$(ShouldCreateVersionFileDuringBuild)'=='true'"> |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
<!-- If VersioningCacheFile exists already then import it; If it doesn't we are going to create it. --> | ||
<Import Condition="Exists('$(VersioningCacheFile)')" Project="$(VersioningCacheFile)" /> | ||
|
||
<Target Name="GenerateVersions"> |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Any objection on merging this PR once currently running checks pass? |
@@ -0,0 +1,91 @@ | |||
<!-- Copyright (c) .NET Foundation. All rights reserved. --> |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
MSBuild/nuget will only automatically import `sdk\Sdk.props` and `sdk\Sdk.targets` from packages used in Sdk elements, and `build\<PackageName>.props` and `build\<PackageName>.targets` for packages referenced via PackageReference.
From: Wes Haggard <notifications@github.com>
Sent: Wednesday, May 16, 2018 2:12 PM
To: dotnet/arcade <arcade@noreply.github.com>
Cc: Subscribed <subscribed@noreply.github.com>
Subject: Re: [dotnet/arcade] MSBuild Task for Semantic Versioning & Tests (#137)
@weshaggard commented on this pull request.
________________________________
In src/Microsoft.DotNet.Build.Tasks.Versioning/targets/Versioning.targets<https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fdotnet%2Farcade%2Fpull%2F137%23discussion_r188774366&data=02%7C01%7CAlex.Perovich%40microsoft.com%7Ce7406b67c8804338f37908d5bb71b808%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C636621019449206149&sdata=W24Uoe%2Bm00ekD4FKEfN9W1Wuy20ycPIttlHJervTsVA%3D&reserved=0>:
@@ -0,0 +1,91 @@
+<!-- Copyright (c) .NET Foundation. All rights reserved. -->
Following the conventions of all our other tools packages this targets/props file should be called Microsoft.DotNet.Build.Tasks.Versioning.props/targets. In fact I think it might be needed to have nuget automatically reference theses files for projects that reference the package.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub<https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fdotnet%2Farcade%2Fpull%2F137%23pullrequestreview-120822207&data=02%7C01%7CAlex.Perovich%40microsoft.com%7Ce7406b67c8804338f37908d5bb71b808%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C636621019449216153&sdata=dJlYYwCX4bxaACApDSRdg8B%2BbW0r0GCTX%2FO5dj82a3k%3D&reserved=0>, or mute the thread<https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAKE3IlGh-BdkVOzj8_EEM4a535A5Zr2Kks5tzJY3gaJpZM4TnxL1&data=02%7C01%7CAlex.Perovich%40microsoft.com%7Ce7406b67c8804338f37908d5bb71b808%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C636621019449216153&sdata=ZW54ytxI9HiOeZDOVI7%2B2JbFKUi7K5cggqnIawCVZcY%3D&reserved=0>.
|
Implementation of generation of Versioning Strings as described in the plan.
Suggestions are welcome.