From daef5fc46ddc42a841a6a2182eebcc6e5fe8f867 Mon Sep 17 00:00:00 2001 From: Charlie Poole Date: Tue, 28 Sep 2021 15:09:24 -0700 Subject: [PATCH] Draft and Production Release targets --- GitReleaseManager.yaml | 56 ++++++++++++++++++++++++++++ appveyor.yml | 4 +- build.cake | 82 +++++++++++++++++++++++++++++++++++------ cake/local-targets.cake | 42 +++++++++++++++++++++ cake/parameters.cake | 1 + nunit.v2.driver.sln | 2 + 6 files changed, 175 insertions(+), 12 deletions(-) create mode 100644 GitReleaseManager.yaml create mode 100644 cake/local-targets.cake diff --git a/GitReleaseManager.yaml b/GitReleaseManager.yaml new file mode 100644 index 0000000..beb3f4e --- /dev/null +++ b/GitReleaseManager.yaml @@ -0,0 +1,56 @@ +# The labels that will be used to include issues in release notes. +issue-labels-include: +- Feature +- Enhancement +- Bug +- Build +- Documentation +# The labels that will NOT be used when including issues in release notes. +issue-labels-exclude: +- Refactor +# Overrides default pluralization and header names for specific labels. +issue-labels-alias: +- name: Build + header: Build + plural: Build +- name: Documentation + header: Documentation + plural: Documentation +# Configuration values used when creating new releases +create: + include-footer: true + footer-heading: Packages + footer-content: >- + There are two different packages available for the extension. + + You may also download the extension from + [chocolatey.org](https://chocolatey.org/packages/nunit-extension-nunit-v2-result-writer/) + or [nuget.org](https://nuget.org/packages/NUnit.Extension.NUnitV2ResultWriter/). + footer-includes-milestone: true + milestone-replace-text: '{milestone}' + include-sha-section: true + sha-section-heading: "SHA256 Hashes of the release artifacts" + sha-section-line-format: "- `{1}\t{0}`" + allow-update-to-published: false +# Configuration values used when exporting release notes +export: + include-created-date-in-title: true + created-date-string-format: MMMM dd, yyyy + perform-regex-removal: false +# regex-text: '### Where to get it(\r\n)*You can .*\.' +# multiline-regex: false +# Configuration values used when closing a milestone +close: +# Whether to add comments to issues closed with the published milestone release. + use-issue-comments: true + issue-comment: |- + :tada: This issue has been resolved in version {milestone} :tada: + + The release is available on: + + - [GitHub Release](https://github.com/{owner}/{repository}/releases/tag/{milestone}) + - [NuGet Package](https://www.nuget.org/packages/NUnit.Extension.NUnitV2ResultWriter/{milestone}) + - [Chocolatey Package](https://chocolatey.org/packages/nunit-extension-nunit-v2-result-writer/{milestone}) diff --git a/appveyor.yml b/appveyor.yml index 88ac5a0..1de6c6d 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -14,6 +14,8 @@ environment: MYGET_API_KEY: secure: wtAvJDVl2tfwiVcyLExFHLvZVfUWiQRHsfdHBFCNEATeCHo1Nd8JP642PfY8xhji NUGET_API_KEY: - secure: 3ojZLs9hiHk/7047hiirFk/qG2RxUACmA8DAUk+8AoILr5R7c4tDGXeTsBjjhq5h + secure: PVHROoT0SmGkr9CHgrKapuA0/CcJGHSP63M3fZaNLvcEVbBnzYLeCwpc0PZHhdvD CHOCO_API_KEY: secure: aDsu1U+umVYFVybjkBVtVQsatSj3QKbD7VkGQci9mNF3493g9Giao/GABISIaHjT + GITHUB_ACCESS_TOKEN: + secure: xmGXWrw5Nj3CI3fPxhw/DWIU5YL/1mM06pSmjpkd9LpKs3t3EYXbECbEQs62lU/O diff --git a/build.cake b/build.cake index 4cc71e7..123ebda 100644 --- a/build.cake +++ b/build.cake @@ -1,4 +1,5 @@ #tool nuget:?package=GitVersion.CommandLine&version=5.0.0 +#tool nuget:?package=GitReleaseManager&version=0.11.0 #tool nuget:?package=NUnit.ConsoleRunner&version=3.12.0 #tool nuget:?package=NUnit.ConsoleRunner&version=3.11.1 #tool nuget:?package=NUnit.ConsoleRunner&version=3.10.0 @@ -10,6 +11,8 @@ const string SOLUTION_FILE = "nunit.v2.driver.sln"; const string NUGET_ID = "NUnit.Extension.NUnitV2Driver"; const string CHOCO_ID = "nunit-extension-nunit-v2-driver"; +const string GITHUB_OWNER = "nunit"; +const string GITHUB_REPO = "nunit-v2-framework-driver"; const string DEFAULT_VERSION = "3.9.0"; const string DEFAULT_CONFIGURATION = "Release"; @@ -63,16 +66,6 @@ Task("Clean") CleanDirectory(parameters.OutputDirectory); }); -Task("CleanAll") - .Does((parameters) => - { - Information("Cleaning all output directories"); - CleanDirectory(parameters.ProjectDirectory + "bin/"); - - Information("Deleting object directories"); - DeleteObjectDirectories(parameters); - }); - ////////////////////////////////////////////////////////////////////// // INITIALIZE FOR BUILD ////////////////////////////////////////////////////////////////////// @@ -313,6 +306,71 @@ Task("PublishToChocolatey") } }); +////////////////////////////////////////////////////////////////////// +// CREATE A DRAFT RELEASE +////////////////////////////////////////////////////////////////////// + +Task("CreateDraftRelease") + .Does((parameters) => + { + if (parameters.IsReleaseBranch) + { + // NOTE: Since this is a release branch, the pre-release label + // is "pre", which we don't want to use for the draft release. + // The branch name contains the full information to be used + // for both the name of the draft release and the milestone, + // i.e. release-2.0.0, release-2.0.0-beta2, etc. + string milestone = parameters.BranchName.Substring(8); + string releaseName = $"Visual Studio Project Loader Extension {milestone}"; + + Information($"Creating draft release..."); + + try + { + GitReleaseManagerCreate(parameters.GitHubAccessToken, GITHUB_OWNER, GITHUB_REPO, new GitReleaseManagerCreateSettings() + { + Name = releaseName, + Milestone = milestone + }); + } + catch + { + Error($"Unable to create draft release for {releaseName}."); + Error($"Check that there is a {milestone} milestone with at least one closed issue."); + Error(""); + throw; + } + } + else + { + Information("Skipping Release creation because this is not a release branch"); + } + }); + +////////////////////////////////////////////////////////////////////// +// CREATE A PRODUCTION RELEASE +////////////////////////////////////////////////////////////////////// + +Task("CreateProductionRelease") + .Does((parameters) => + { + if (parameters.IsProductionRelease) + { + string token = parameters.GitHubAccessToken; + string tagName = parameters.PackageVersion; + string assets = $"\"{parameters.NuGetPackage},{parameters.ChocolateyPackage}\""; + + Information($"Publishing release {tagName} to GitHub"); + + GitReleaseManagerAddAssets(token, GITHUB_OWNER, GITHUB_REPO, tagName, assets); + GitReleaseManagerClose(token, GITHUB_OWNER, GITHUB_REPO, tagName); + } + else + { + Information("Skipping CreateProductionRelease because this is not a production release"); + } + }); + ////////////////////////////////////////////////////////////////////// // TASK TARGETS ////////////////////////////////////////////////////////////////////// @@ -336,7 +394,9 @@ Task("Appveyor") .IsDependentOn("Build") .IsDependentOn("Test") .IsDependentOn("Package") - .IsDependentOn("PublishPackages"); + .IsDependentOn("PublishPackages") + .IsDependentOn("CreateDraftRelease") + .IsDependentOn("CreateProductionRelease"); Task("Travis") .IsDependentOn("Build") diff --git a/cake/local-targets.cake b/cake/local-targets.cake new file mode 100644 index 0000000..0d522da --- /dev/null +++ b/cake/local-targets.cake @@ -0,0 +1,42 @@ +//////////////////////////////////////////////////////////////////// +// TARGETS FOR DEVELOPER USE ON LOCAL MACHINE +////////////////////////////////////////////////////////////////////// + +using System; + +// Dependent task for all local targets +Task("MustBeLocalBuild") + .Does((parameters) => + { + if (!parameters.IsLocalBuild) + throw new Exception($"{parameters.Target} may only be run locally!"); + }); + +Task("CleanAll") + .Description("Clean both configs and all obj directories") + .IsDependentOn("MustBeLocalBuild") + .Does((parameters) => + { + Information("Cleaning all output directories"); + CleanDirectory(parameters.ProjectDirectory + "bin/"); + + Information("Deleting object directories"); + DeleteObjectDirectories(parameters); + }); + +// Download existing draft release for modification or for use in +// updating the CHANGES.md file. +Task("DownloadDraftRelease") + .Description("Download draft release for local use") + .IsDependentOn("MustBeLocalBuild") + .Does((parameters) => + { + if (!parameters.IsReleaseBranch) + throw new Exception("DownloadDraftRelease requires a release branch!"); + + string milestone = parameters.BranchName.Substring(8); + + GitReleaseManagerExport(parameters.GitHubAccessToken, GITHUB_OWNER, GITHUB_REPO, "DraftRelease.md", + new GitReleaseManagerExportSettings() { TagName = milestone }); + }); + diff --git a/cake/parameters.cake b/cake/parameters.cake index a2de0cf..2b38588 100644 --- a/cake/parameters.cake +++ b/cake/parameters.cake @@ -5,6 +5,7 @@ #load "./test-results.cake" #load "./test-reports.cake" #load "./utilities.cake" +#load "./local-targets.cake" using System; diff --git a/nunit.v2.driver.sln b/nunit.v2.driver.sln index 8374401..49f8092 100644 --- a/nunit.v2.driver.sln +++ b/nunit.v2.driver.sln @@ -14,6 +14,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution build.ps1 = build.ps1 build.sh = build.sh CHANGES.txt = CHANGES.txt + GitReleaseManager.yaml = GitReleaseManager.yaml GitVersion.yml = GitVersion.yml LICENSE.txt = LICENSE.txt nunit.v2.driver.nuspec = nunit.v2.driver.nuspec @@ -26,6 +27,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "nunit.v2.driver.tests", "sr EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "cake", "cake", "{0E1320F6-992A-48FA-871B-5FD018BD8BE8}" ProjectSection(SolutionItems) = preProject + cake\local-targets.cake = cake\local-targets.cake cake\package-checks.cake = cake\package-checks.cake cake\package-tests.cake = cake\package-tests.cake cake\packaging.cake = cake\packaging.cake