Skip to content

Commit

Permalink
Merge pull request #614 from TestCentric/issue-612
Browse files Browse the repository at this point in the history
Create Draft Release on GitHub for Release branch builds
  • Loading branch information
CharliePoole authored Dec 8, 2020
2 parents e31e6b9 + 00e29fd commit 77a0c95
Show file tree
Hide file tree
Showing 8 changed files with 219 additions and 69 deletions.
61 changes: 61 additions & 0 deletions GitReleaseManager.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
## Configuration values used when creating new releases
#create:
# include-footer: true
# footer-heading: Where to get it
# footer-content: >-
# You can download this release from
#
# [chocolatey](https://chocolatey.org/packages/chocolateyGUI/{milestone})
# footer-includes-milestone: false
# milestone-replace-text: '{milestone}'
# include-sha-section: false
# sha-section-heading: SHA256 Hashes of the release artifacts
# sha-section-line-format: '- `{1} {0}`'
# allow-update-to-published: false
## Configuration values used when exporting release notes
#export:
# include-created-date-in-title: false
# 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 and with the published milestone release.
# use-issue-comments: false
# issue-comment: |-
# :tada: This issue has been resolved in version {milestone} :tada:
#
# The release is available on:
#
# - [NuGet package(@{milestone})](https://nuget.org/packages/{repository}/{milestone})
# - [GitHub release](https://github.com/{owner}/{repository}/releases/tag/{milestone})
#
# Your **[GitReleaseManager](https://github.com/GitTools/GitReleaseManager)** bot :package::rocket:
## The labels that will be used to include issues in release notes.
issue-labels-include:
- Feature
- Enhancement
- Bug
- Build
#- Duplicate
#- Help Wanted
#- Improvement
#- Invalid
#- Question
#- WontFix
## The labels that will NOT be used when including issues in release notes.
#issue-labels-exclude:
#- Internal Refactoring
## Overrides default pluralization and header names for specific labels.
issue-labels-alias:
- name: Build
header: Build
plural: Build
#- name: Documentation
# header: Documentation
# plural: Documentation
## The labels that will NOT be used when including issues in release notes.
#issue-labels-exclude:
#- Internal Refactoring
#
2 changes: 2 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ environment:
secure: aDsu1U+umVYFVybjkBVtVQsatSj3QKbD7VkGQci9mNF3493g9Giao/GABISIaHjT
GITHUB_PASSWORD:
secure: 2eNz23Eb1L40g2LPmlPqog==
GITHUB_ACCESS_TOKEN:
secure: pxZJzzwCBB46Ey3tRoJI90RC10KnK1pgucafZagYsLL8JNJz6RwcHf0DIH01nWnL
85 changes: 72 additions & 13 deletions build.cake
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#tool nuget:?package=NUnit.ConsoleRunner&version=3.10.0
#tool nuget:?package=GitVersion.CommandLine&version=5.0.0
#tool nuget:?package=GitReleaseManager&version=0.11.0
#tool "nuget:https://api.nuget.org/v3/index.json?package=nuget.commandline&version=5.3.1"
#tool nuget:?package=Wyam&version=2.2.9

Expand Down Expand Up @@ -116,8 +117,8 @@ Task("UpdateAssemblyInfo")
.Does<BuildParameters>((parameters) =>
{
var major = new Version(parameters.AssemblyVersion).Major;
parameters.Versions.PatchAssemblyInfo("src/CommonAssemblyInfo.cs");
parameters.Versions.PatchAssemblyInfo("src/TestEngine/CommonEngineAssemblyInfo.cs");
parameters.BuildVersion.PatchAssemblyInfo("src/CommonAssemblyInfo.cs");
parameters.BuildVersion.PatchAssemblyInfo("src/TestEngine/CommonEngineAssemblyInfo.cs");
});

//////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -295,6 +296,7 @@ Task("TestNuGetPackage")

Task("BuildChocolateyPackage")
.IsDependentOn("CreateImage")
.WithCriteria(IsRunningOnWindows())
.Does<BuildParameters>((parameters) =>
{
Information("Creating package " + parameters.ChocolateyPackageName);
Expand Down Expand Up @@ -340,6 +342,7 @@ Task("BuildChocolateyPackage")

Task("TestChocolateyPackage")
.IsDependentOn("BuildChocolateyPackage")
.WithCriteria(IsRunningOnWindows())
.Does<BuildParameters>((parameters) =>
{
new ChocolateyPackageTester(parameters).RunAllTests();
Expand Down Expand Up @@ -400,6 +403,56 @@ Task("PublishPackages")
Information("Nothing to publish from this run.");
});

//////////////////////////////////////////////////////////////////////
// CREATE A DRAFT RELEASE
//////////////////////////////////////////////////////////////////////

Task("CreateDraftRelease")
.IsDependentOn("BuildPackages")
.WithCriteria<BuildParameters>((context, parameters) => parameters.IsReleaseBranch)
.Does<BuildParameters>((parameters) =>
{
// Exit if any PackageTests failed
CheckTestErrors(ref ErrorDetail);

string releaseName = $"TestCentric {parameters.BuildVersion.SemVer}";
string milestone = GetMilestoneFromBranchName(parameters.BranchName);
string assets = IsRunningOnWindows()
? $"\"{parameters.ZipPackage},{parameters.NuGetPackage},{parameters.ChocolateyPackage},{parameters.MetadataPackage}\""
: $"\"{parameters.ZipPackage},{parameters.NuGetPackage}\"";

Information($"Creating draft release {releaseName} from milestone {milestone}");

GitReleaseManagerCreate(parameters.GitHubAccessToken, "TestCentric", "testcentric-gui", new GitReleaseManagerCreateSettings()
{
Name = releaseName,
Milestone = milestone,
Assets = assets
});
});

private static string GetMilestoneFromBranchName(string branchName)
{
Version versionFromBranch;
if (!Version.TryParse(branchName.Substring(8), out versionFromBranch))
{ string msg = $"Branch name {branchName} incorporates an invalid version format. ";
if (branchName.IndexOf("-") >0)
msg += "Note that pre-release versions are not yet supported for release branches.";
throw new InvalidOperationException(msg);
}

if (versionFromBranch.Build < 0)
throw new InvalidOperationException("Release branch must specify three version components.");

string milestone = versionFromBranch.Build <= 0
? versionFromBranch.ToString(2)
: versionFromBranch.ToString(3);
// if (_parameters.IsPreRelease)
// milestone += $"-{_parameters.BuildVersion.PreReleaseSuffix}";

return milestone;
}

//////////////////////////////////////////////////////////////////////
// INTERACTIVE TESTS FOR USE IN DEVELOPMENT
//////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -454,13 +507,19 @@ Task("Test")
.IsDependentOn("TestEngine")
.IsDependentOn("TestGui");

Task("Package")
Task("BuildPackages")
.IsDependentOn("CheckTestErrors")
.IsDependentOn("PackageZip")
.IsDependentOn("PackageNuget")
.IsDependentOn("PackageChocolatey")
.IsDependentOn("BuildZipPackage")
.IsDependentOn("BuildNuGetPackage")
.IsDependentOn("BuildChocolateyPackage")
.IsDependentOn("BuildMetadataPackage");

Task("TestPackages")
.IsDependentOn("BuildPackages")
.IsDependentOn("TestZipPackage")
.IsDependentOn("TestNuGetPackage")
.IsDependentOn("TestChocolateyPackage");

Task("PackageZip")
.IsDependentOn("BuildZipPackage")
.IsDependentOn("TestZipPackage");
Expand All @@ -473,16 +532,15 @@ Task("PackageChocolatey")
.IsDependentOn("BuildChocolateyPackage")
.IsDependentOn("TestChocolateyPackage");

Task("Publish")
.IsDependentOn("PublishPackages")
.IsDependentOn("UpdateWebsite");

Task("AppVeyor")
.IsDependentOn("DumpSettings")
.IsDependentOn("Build")
.IsDependentOn("Test")
.IsDependentOn("Package")
.IsDependentOn("Publish");
.IsDependentOn("BuildPackages")
.IsDependentOn("TestPackages")
.IsDependentOn("PublishPackages")
.IsDependentOn("CreateDraftRelease")
.IsDependentOn("UpdateWebsite");

Task("Travis")
.IsDependentOn("Build")
Expand All @@ -492,7 +550,8 @@ Task("All")
.IsDependentOn("DumpSettings")
.IsDependentOn("Build")
.IsDependentOn("Test")
.IsDependentOn("Package");
.IsDependentOn("BuildPackages")
.IsDependentOn("TestPackages");

Task("Default")
.IsDependentOn("Test");
Expand Down
79 changes: 48 additions & 31 deletions build/parameters.cake
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ public class BuildParameters

// Environment Variable names holding GitHub identity of user
// These are only used to publish the website when running locally
// private const string GITHUB_USER_ID = "GITHUB_USER_ID";
// private const string GITHUB_USER_EMAIL = "GITHUB_USER_EMAIL";
private const string GITHUB_PASSWORD = "GITHUB_PASSWORD";
// Access token is used by GitReleaseManager
private const string GITHUB_ACCESS_TOKEN = "GITHUB_ACCESS_TOKEN";

// Pre-release labels that we publish
private static readonly string[] LABELS_WE_PUBLISH_ON_MYGET = { "dev", "pre" };
Expand Down Expand Up @@ -49,13 +49,23 @@ public class BuildParameters
Configuration = context.Argument("configuration", DEFAULT_CONFIGURATION);
ProjectDirectory = context.Environment.WorkingDirectory.FullPath + "/";

Versions = new BuildVersion(context, this);
MyGetApiKey = _context.EnvironmentVariable(MYGET_API_KEY);
NuGetApiKey = _context.EnvironmentVariable(NUGET_API_KEY);
ChocolateyApiKey = _context.EnvironmentVariable(CHOCO_API_KEY);

UsingXBuild = context.EnvironmentVariable("USE_XBUILD") != null;

GitHubPassword = _context.EnvironmentVariable(GITHUB_PASSWORD);
GitHubAccessToken = _context.EnvironmentVariable(GITHUB_ACCESS_TOKEN);

BuildVersion = new BuildVersion(context, this);
//ReleaseManager = new ReleaseManager(context, this);

if (context.HasArgument("testLevel"))
PackageTestLevel = context.Argument("testLevel", 1);
else if (!Versions.IsPreRelease)
else if (!BuildVersion.IsPreRelease)
PackageTestLevel = 3;
else switch (Versions.PreReleaseLabel)
else switch (BuildVersion.PreReleaseLabel)
{
case "pre":
case "rc":
Expand All @@ -73,16 +83,6 @@ public class BuildParameters
break;
}

MyGetApiKey = _context.EnvironmentVariable(MYGET_API_KEY);
NuGetApiKey = _context.EnvironmentVariable(NUGET_API_KEY);
ChocolateyApiKey = _context.EnvironmentVariable(CHOCO_API_KEY);

// GitHubUserId = _context.EnvironmentVariable(GITHUB_USER_ID);
// GitHubUserEmail = _context.EnvironmentVariable(GITHUB_USER_EMAIL);
GitHubPassword = _context.EnvironmentVariable(GITHUB_PASSWORD);

UsingXBuild = context.EnvironmentVariable("USE_XBUILD") != null;

MSBuildSettings = new MSBuildSettings {
Verbosity = Verbosity.Minimal,
ToolVersion = MSBuildToolVersion.Default,//The highest available MSBuild tool version//VS2017
Expand Down Expand Up @@ -119,11 +119,13 @@ public class BuildParameters

public string Configuration { get; }

public BuildVersion Versions { get; }
public string PackageVersion => Versions.PackageVersion;
public string AssemblyVersion => Versions.AssemblyVersion;
public string AssemblyFileVersion => Versions.AssemblyFileVersion;
public string AssemblyInformationalVersion => Versions.AssemblyInformationalVersion;
public BuildVersion BuildVersion { get; }
public string PackageVersion => BuildVersion.PackageVersion;
public string AssemblyVersion => BuildVersion.AssemblyVersion;
public string AssemblyFileVersion => BuildVersion.AssemblyFileVersion;
public string AssemblyInformationalVersion => BuildVersion.AssemblyInformationalVersion;

//public ReleaseManager ReleaseManager { get; }

public int PackageTestLevel { get; }

Expand Down Expand Up @@ -170,11 +172,16 @@ public class BuildParameters
public bool IsNuGetApiKeyAvailable => !string.IsNullOrEmpty(NuGetApiKey);
public bool IsChocolateyApiKeyAvailable => !string.IsNullOrEmpty(ChocolateyApiKey);

public bool IsPreRelease => Versions.IsPreRelease;
public bool IsFinalRelease => !IsPreRelease;
public bool ShouldPublishToMyGet => IsFinalRelease || LABELS_WE_PUBLISH_ON_MYGET.Contains(Versions.PreReleaseLabel);
public bool ShouldPublishToNuGet => IsFinalRelease || LABELS_WE_PUBLISH_ON_NUGET.Contains(Versions.PreReleaseLabel);
public bool ShouldPublishToChocolatey => IsFinalRelease || LABELS_WE_PUBLISH_ON_CHOCOLATEY.Contains(Versions.PreReleaseLabel);
public string BranchName => BuildVersion.BranchName;
public bool IsReleaseBranch => BuildVersion.IsReleaseBranch;

public bool IsPreRelease => BuildVersion.IsPreRelease;
public bool ShouldPublishToMyGet => !IsPreRelease && !IsReleaseBranch ||
LABELS_WE_PUBLISH_ON_MYGET.Contains(BuildVersion.PreReleaseLabel);
public bool ShouldPublishToNuGet => !IsPreRelease && !IsReleaseBranch ||
LABELS_WE_PUBLISH_ON_NUGET.Contains(BuildVersion.PreReleaseLabel);
public bool ShouldPublishToChocolatey => !IsPreRelease && !IsReleaseBranch ||
LABELS_WE_PUBLISH_ON_CHOCOLATEY.Contains(BuildVersion.PreReleaseLabel);
public bool IsProductionRelease => ShouldPublishToNuGet || ShouldPublishToChocolatey;

public bool UsingXBuild { get; }
Expand All @@ -193,6 +200,7 @@ public class BuildParameters
public string GitHubUserId => "charliepoole";
public string GitHubUserEmail => "[email protected]";
public string GitHubPassword { get; }
public string GitHubAccessToken { get; }

private void Validate()
{
Expand All @@ -208,6 +216,12 @@ public class BuildParameters
errors.Add("Chocolatey ApiKey was not set.");
}

if (TasksToExecute.Contains("CreateDraftRelease"))
{
if (IsReleaseBranch && string.IsNullOrEmpty(GitHubAccessToken))
errors.Add("GitHub Access Token was not set.");
}

if (TasksToExecute.Contains("DeployWebsite"))
{
if (string.IsNullOrEmpty(GitHubUserId))
Expand Down Expand Up @@ -242,17 +256,20 @@ public class BuildParameters
Console.WriteLine("IsRunningOnUnix: " + IsRunningOnUnix);
Console.WriteLine("IsRunningOnAppVeyor: " + IsRunningOnAppVeyor);

Console.WriteLine("\nGIT");

Console.WriteLine("\nVERSIONING");
Console.WriteLine("PackageVersion: " + PackageVersion);
Console.WriteLine("AssemblyVersion: " + AssemblyVersion);
Console.WriteLine("AssemblyFileVersion: " + AssemblyFileVersion);
Console.WriteLine("AssemblyInformationalVersion: " + AssemblyInformationalVersion);
Console.WriteLine("SemVer: " + Versions.SemVer);
Console.WriteLine("IsPreRelease: " + Versions.IsPreRelease);
Console.WriteLine("PreReleaseLabel: " + Versions.PreReleaseLabel);
Console.WriteLine("PreReleaseSuffix: " + Versions.PreReleaseSuffix);
Console.WriteLine("SemVer: " + BuildVersion.SemVer);
Console.WriteLine("IsPreRelease: " + BuildVersion.IsPreRelease);
Console.WriteLine("PreReleaseLabel: " + BuildVersion.PreReleaseLabel);
Console.WriteLine("PreReleaseSuffix: " + BuildVersion.PreReleaseSuffix);

Console.WriteLine("\nRELEASING");
Console.WriteLine("BranchName: " + BranchName);
Console.WriteLine("IsReleaseBranch: " + IsReleaseBranch);
//Console.WriteLine("ReleaseMilestone: " + ReleaseMilestone);

Console.WriteLine("\nDIRECTORIES");
Console.WriteLine("Project: " + ProjectDirectory);
Expand Down
Loading

0 comments on commit 77a0c95

Please sign in to comment.