-
Notifications
You must be signed in to change notification settings - Fork 49
Initial use of GitVersion #226
Changes from 12 commits
aa54405
975875c
b486c27
10abbd8
d261fec
87bb6ca
a0ef16a
d9606c0
e08bac4
c3e8757
68781f8
924e2f5
62a1cfd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
// See https://go.microsoft.com/fwlink/?LinkId=733558 | ||
// for the documentation about the tasks.json format | ||
"version": "2.0.0", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this file included on purpose? I can google that it defines a vscode task, but I cannot find the script Package that is mentioned. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's because I executed tasks in the script under VsCode. File should be in .gitignore. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The script is build.cake, Package is a target. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok. The |
||
"tasks": [ | ||
{ | ||
"type": "cake", | ||
"script": "Package", | ||
"problemMatcher": [ | ||
"$eslint-stylish" | ||
] | ||
} | ||
] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
mode: ContinuousDelivery | ||
branches: | ||
master: | ||
tag: dev | ||
increment: Minor | ||
releases?[/-]: | ||
tag: ci | ||
increment: Minor | ||
features?[/-]: | ||
tag: ci | ||
increment: Minor | ||
issues?[/-]: | ||
tag: ci | ||
increment: Minor | ||
(pull|pull\-requests|pr)[/-]: | ||
tag: pr | ||
increment: Minor | ||
ignore: | ||
sha: [] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
#tool nuget:?package=NUnit.ConsoleRunner&version=3.7.0 | ||
#tool nuget:?package=GitVersion.CommandLine | ||
|
||
using System.Text.RegularExpressions; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this necessary ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I had a regular expression at one point but it's gone now. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The regex is back for parsing whether it is a PR or not, so we should keep this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Exactly. |
||
|
||
////////////////////////////////////////////////////////////////////// | ||
// ARGUMENTS | ||
|
@@ -8,15 +11,11 @@ var target = Argument("target", "Default"); | |
var configuration = Argument("configuration", "Debug"); | ||
|
||
////////////////////////////////////////////////////////////////////// | ||
// SET PACKAGE VERSION | ||
// SET PACKAGE VERSION DEFAULTS | ||
////////////////////////////////////////////////////////////////////// | ||
|
||
var version = "0.5"; | ||
var modifier = ""; | ||
|
||
var isAppveyor = BuildSystem.IsRunningOnAppVeyor; | ||
var dbgSuffix = configuration == "Debug" ? "-dbg" : ""; | ||
var packageVersion = version + modifier + dbgSuffix; | ||
GitVersion GitVersionInfo { get; set; } | ||
BuildInfo Build { get; set;} | ||
|
||
////////////////////////////////////////////////////////////////////// | ||
// DEFINE RUN CONSTANTS | ||
|
@@ -41,10 +40,6 @@ var PACKAGE_SOURCE = new string[] | |
"https://www.myget.org/F/nunit-gui-team/api/v2" | ||
}; | ||
|
||
// Packages | ||
var SRC_PACKAGE = PACKAGE_DIR + "NUnit-Gui-" + version + modifier + "-src.zip"; | ||
var ZIP_PACKAGE = PACKAGE_DIR + "NUnit-Gui-" + packageVersion + ".zip"; | ||
|
||
////////////////////////////////////////////////////////////////////// | ||
// CLEAN | ||
////////////////////////////////////////////////////////////////////// | ||
|
@@ -57,63 +52,44 @@ Task("Clean") | |
|
||
|
||
////////////////////////////////////////////////////////////////////// | ||
// INITIALIZE FOR BUILD | ||
// RESTORE NUGET PACKAGES | ||
////////////////////////////////////////////////////////////////////// | ||
|
||
Task("InitializeBuild") | ||
Task("RestorePackages") | ||
.Does(() => | ||
{ | ||
NuGetRestore(GUI_SOLUTION, new NuGetRestoreSettings | ||
{ | ||
Source = PACKAGE_SOURCE, | ||
Verbosity = NuGetVerbosity.Detailed | ||
}); | ||
}); | ||
|
||
if (BuildSystem.IsRunningOnAppVeyor) | ||
////////////////////////////////////////////////////////////////////// | ||
// SET BUILD INFO | ||
////////////////////////////////////////////////////////////////////// | ||
Task("SetBuildInfo") | ||
.Does(() => | ||
{ | ||
var settings = new GitVersionSettings(); | ||
if (!BuildSystem.IsLocalBuild) | ||
{ | ||
var tag = AppVeyor.Environment.Repository.Tag; | ||
|
||
if (tag.IsTag) | ||
{ | ||
packageVersion = tag.Name; | ||
} | ||
else | ||
{ | ||
var buildNumber = AppVeyor.Environment.Build.Number.ToString("00000"); | ||
var branch = AppVeyor.Environment.Repository.Branch; | ||
var isPullRequest = AppVeyor.Environment.PullRequest.IsPullRequest; | ||
|
||
if (branch == "master" && !isPullRequest) | ||
{ | ||
packageVersion = version + "-dev-" + buildNumber + dbgSuffix; | ||
} | ||
else | ||
{ | ||
var suffix = "-ci-" + buildNumber + dbgSuffix; | ||
|
||
if (isPullRequest) | ||
suffix += "-pr-" + AppVeyor.Environment.PullRequest.Number; | ||
else | ||
suffix += "-" + branch; | ||
|
||
// Nuget limits "special version part" to 20 chars. Add one for the hyphen. | ||
if (suffix.Length > 21) | ||
suffix = suffix.Substring(0, 21); | ||
|
||
packageVersion = version + suffix; | ||
} | ||
} | ||
|
||
AppVeyor.UpdateBuildVersion(packageVersion); | ||
settings.UpdateAssemblyInfo = true; | ||
settings.UpdateAssemblyInfoFilePath = "src/CommonAssemblyInfo.cs"; | ||
} | ||
|
||
GitVersionInfo = GitVersion(settings); | ||
Build = new BuildInfo(GitVersionInfo); | ||
}); | ||
|
||
////////////////////////////////////////////////////////////////////// | ||
// BUILD | ||
////////////////////////////////////////////////////////////////////// | ||
|
||
Task("Build") | ||
.IsDependentOn("InitializeBuild") | ||
.IsDependentOn("Clean") | ||
.IsDependentOn("RestorePackages") | ||
.IsDependentOn("SetBuildInfo") | ||
.Does(() => | ||
{ | ||
if(IsRunningOnWindows()) | ||
|
@@ -167,9 +143,7 @@ Task("PackageZip") | |
BIN_DIR + "CHANGES.txt", | ||
BIN_DIR + "nunit-gui.exe", | ||
BIN_DIR + "nunit-gui.exe.config", | ||
BIN_DIR + "nunit-gui.pdb", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the motivation for not providing pdbs ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. They break the build under Mono 4.6.2, which doesn't produce them. We could put them back if we used logic to include them only when they actually are present. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok. Let us just leave them out to begin with. Then we can always include them later. |
||
BIN_DIR + "nunit.uikit.dll", | ||
BIN_DIR + "nunit.uikit.pdb", | ||
BIN_DIR + "nunit.engine.api.dll", | ||
BIN_DIR + "nunit.engine.dll", | ||
BIN_DIR + "Mono.Cecil.dll", | ||
|
@@ -179,7 +153,7 @@ Task("PackageZip") | |
BIN_DIR + "nunit-agent-x86.exe.config" | ||
}; | ||
|
||
Zip(BIN_DIR, File(ZIP_PACKAGE), zipFiles); | ||
Zip(BIN_DIR, File(PACKAGE_DIR + "NUnit-Gui-" + Build.PackageVersion + ".zip"), zipFiles); | ||
}); | ||
|
||
Task("PackageChocolatey") | ||
|
@@ -188,12 +162,12 @@ Task("PackageChocolatey") | |
{ | ||
CreateDirectory(PACKAGE_DIR); | ||
|
||
ChocolateyPack("choco/nunit-gui.nuspec", | ||
new ChocolateyPackSettings() | ||
{ | ||
Version = packageVersion, | ||
OutputDirectory = PACKAGE_DIR, | ||
Files = new ChocolateyNuSpecContent[] | ||
ChocolateyPack("choco/nunit-gui.nuspec", | ||
new ChocolateyPackSettings() | ||
{ | ||
Version = Build.PackageVersion, | ||
OutputDirectory = PACKAGE_DIR, | ||
Files = new ChocolateyNuSpecContent[] | ||
{ | ||
new ChocolateyNuSpecContent() { Source = "../LICENSE" }, | ||
new ChocolateyNuSpecContent() { Source = "../CHANGES.txt" }, | ||
|
@@ -211,16 +185,86 @@ Task("PackageChocolatey") | |
new ChocolateyNuSpecContent() { Source = "nunit-agent-x86.exe.ignore", Target="tools" }, | ||
new ChocolateyNuSpecContent() { Source = "nunit.choco.addins", Target="tools" } | ||
} | ||
}); | ||
}); | ||
}); | ||
|
||
////////////////////////////////////////////////////////////////////// | ||
// TASK TARGETS | ||
// BUILD INFO | ||
////////////////////////////////////////////////////////////////////// | ||
|
||
Task("Rebuild") | ||
.IsDependentOn("Clean") | ||
.IsDependentOn("Build"); | ||
class BuildInfo | ||
{ | ||
public BuildInfo(GitVersion gitVersion) | ||
{ | ||
Version = gitVersion.MajorMinorPatch; | ||
BranchName = gitVersion.BranchName; | ||
BuildNumber = gitVersion.CommitsSinceVersionSourcePadded; | ||
|
||
// Initially assume it's neither master nor a PR | ||
IsMaster = false; | ||
IsPullRequest = false; | ||
PullRequestNumber = string.Empty; | ||
|
||
if (BranchName == "master") | ||
{ | ||
IsMaster = true; | ||
PreReleaseSuffix = "dev-" + BuildNumber; | ||
} | ||
else | ||
{ | ||
var re = new Regex(@"(pull|pull\-requests?|pr)[/-](\d*)[/-]"); | ||
var match = re.Match(BranchName); | ||
|
||
if (match.Success) | ||
{ | ||
IsPullRequest = true; | ||
PullRequestNumber = match.Groups[2].Value; | ||
PreReleaseSuffix = "pr-" + PullRequestNumber + "-" + BuildNumber; | ||
} | ||
else | ||
{ | ||
PreReleaseSuffix = "ci-" + BuildNumber + "-" + Regex.Replace(BranchName, "[^0-9A-Za-z-]+", "-"); | ||
// Nuget limits "special version part" to 20 chars. | ||
if (PreReleaseSuffix.Length > 20) | ||
PreReleaseSuffix = PreReleaseSuffix.Substring(0, 20); | ||
} | ||
} | ||
|
||
PackageVersion = Version + "-" + PreReleaseSuffix; | ||
|
||
AssemblyVersion = gitVersion.AssemblySemVer; | ||
AssemblyFileVersion = PackageVersion; | ||
} | ||
|
||
public string BranchName { get; private set; } | ||
public string Version { get; private set; } | ||
public bool IsMaster { get; private set; } | ||
public bool IsPullRequest { get; private set; } | ||
public string PullRequestNumber { get; private set; } | ||
public string BuildNumber { get; private set; } | ||
public string PreReleaseSuffix { get; private set; } | ||
public string PackageVersion { get; private set; } | ||
|
||
public string AssemblyVersion { get; private set; } | ||
public string AssemblyFileVersion { get; private set; } | ||
|
||
public string Dump() | ||
{ | ||
var NL = Environment.NewLine; | ||
return " BranchName: " + BranchName + NL + | ||
" Version: " + Version + NL + | ||
" PreReleaseSuffix: " + PreReleaseSuffix + NL + | ||
" IsPullRequest: " + IsPullRequest.ToString() + NL + | ||
" PullRequestNumber: " + PullRequestNumber + NL + | ||
" AssemblyVersion: " + AssemblyVersion + NL + | ||
" AssemblyFileVersion: " + AssemblyFileVersion + NL + | ||
" Package Version: " + PackageVersion + NL; | ||
} | ||
} | ||
|
||
////////////////////////////////////////////////////////////////////// | ||
// TASK TARGETS | ||
////////////////////////////////////////////////////////////////////// | ||
|
||
Task("Package") | ||
.IsDependentOn("PackageZip") | ||
|
@@ -232,7 +276,8 @@ Task("Appveyor") | |
.IsDependentOn("Package"); | ||
|
||
Task("Travis") | ||
.IsDependentOn("Build"); | ||
.IsDependentOn("Build") | ||
.IsDependentOn("PackageZip"); | ||
|
||
Task("Default") | ||
.IsDependentOn("Build"); | ||
|
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.
I've pushed a commit b758c79 to correct the error from the merge (the error made Travis fail every time).