diff --git a/.gitignore b/.gitignore index a61926c..08133aa 100644 --- a/.gitignore +++ b/.gitignore @@ -108,6 +108,9 @@ _UpgradeReport_Files/ Backup*/ UpgradeLog*.XML +# VsCode +.vscode + # NUnit Files TestResult.xml *.VisualState.xml diff --git a/.travis.yml b/.travis.yml index 3bfb1d8..29e6f23 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,5 +4,5 @@ mono: - latest - 4.6.2 script: - - ./build.sh -target="Travis" -configuration="Release" -verbosity="verbose" - + - git fetch --unshallow + - ./build.sh --target=Travis diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..ba3415c --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,14 @@ + { + // See https://go.microsoft.com/fwlink/?LinkId=733558 + // for the documentation about the tasks.json format + "version": "2.0.0", + "tasks": [ + { + "type": "cake", + "script": "Package", + "problemMatcher": [ + "$eslint-stylish" + ] + } + ] +} \ No newline at end of file diff --git a/GitVersion.yml b/GitVersion.yml new file mode 100644 index 0000000..4e91cf3 --- /dev/null +++ b/GitVersion.yml @@ -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: [] \ No newline at end of file diff --git a/build.cake b/build.cake index e41978f..5127451 100644 --- a/build.cake +++ b/build.cake @@ -1,4 +1,7 @@ #tool nuget:?package=NUnit.ConsoleRunner&version=3.7.0 +#tool nuget:?package=GitVersion.CommandLine + +using System.Text.RegularExpressions; ////////////////////////////////////////////////////////////////////// // 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,10 +52,10 @@ Task("Clean") ////////////////////////////////////////////////////////////////////// -// INITIALIZE FOR BUILD +// RESTORE NUGET PACKAGES ////////////////////////////////////////////////////////////////////// -Task("InitializeBuild") +Task("RestorePackages") .Does(() => { NuGetRestore(GUI_SOLUTION, new NuGetRestoreSettings @@ -68,44 +63,23 @@ Task("InitializeBuild") 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); }); ////////////////////////////////////////////////////////////////////// @@ -113,7 +87,9 @@ Task("InitializeBuild") ////////////////////////////////////////////////////////////////////// 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", 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"); diff --git a/src/CommonAssemblyInfo.cs b/src/CommonAssemblyInfo.cs index fbc9f6b..7a12eef 100644 --- a/src/CommonAssemblyInfo.cs +++ b/src/CommonAssemblyInfo.cs @@ -39,7 +39,8 @@ // COM, set the ComVisible attribute to true on that type. [assembly: ComVisible(false)] -// Common version information for all assemblies. +// Common version information for local developer builds. // Should be set to the NEXT planned version between releases. +// For CI builds, this info will be updated by GitVersion. [assembly: AssemblyVersion("0.6.0.0")] [assembly: AssemblyFileVersion("0.6.0.0")]