Skip to content

Commit

Permalink
Setup a release task to make it easier to release a new version
Browse files Browse the repository at this point in the history
  • Loading branch information
Antoine Aubry committed Mar 15, 2019
1 parent a66b0d5 commit 0341198
Show file tree
Hide file tree
Showing 40 changed files with 581 additions and 423 deletions.
8 changes: 7 additions & 1 deletion GitVersion.yml
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
mode: Mainline
mode: Mainline
increment: None
commit-message-incrementing: MergeMessageOnly
branches:
master:
commit-message-incrementing: MergeMessageOnly
increment: None
384 changes: 2 additions & 382 deletions README.md

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions YamlDotNet.sln
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ Global
{689D2A30-C52E-4CF8-8BA1-3178F4EB245A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{689D2A30-C52E-4CF8-8BA1-3178F4EB245A}.Debug-AOT|Any CPU.ActiveCfg = Debug|Any CPU
{689D2A30-C52E-4CF8-8BA1-3178F4EB245A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{689D2A30-C52E-4CF8-8BA1-3178F4EB245A}.Release|Any CPU.Build.0 = Release|Any CPU
{A9F67018-0240-4D16-A4EA-BCB780D0AF05}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A9F67018-0240-4D16-A4EA-BCB780D0AF05}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A9F67018-0240-4D16-A4EA-BCB780D0AF05}.Debug-AOT|Any CPU.ActiveCfg = Debug|Any CPU
Expand Down
38 changes: 28 additions & 10 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
version: 0.0.{build}

branches:
only:
# Releases must be built from a release tag
- /^(?!master).+$/
- /^master.+$/

image: Visual Studio 2017

test: off

build:
publish_nuget: true

Expand All @@ -12,21 +20,31 @@ build_script:
- ps: .\build.ps1 -Target Package # -Verbosity Diagnostic -buildVerbosity=Verbose

artifacts:
- path: YamlDotNet\bin\Release\net45
name: Release-Net45

- path: YamlDotNet\bin\Release\netstandard1.3
name: Release-NetStandard

- path: YamlDotNet\bin\Release\net45
name: Release-Net45

- path: YamlDotNet\bin\Release\net35
name: Release-Net35

- path: YamlDotNet\bin\Release\net20
name: Release-Net20

- path: YamlDotNet\bin\Release\net40
name: Release-UnitySubset-v35

- path: YamlDotNet\bin\*.nupkg

deploy:
- provider: NuGet
api_key:
secure: GMc0xUTASI8qTPK1/eN/GFs6PBhPFBin1TT1hE5N8NlkU7VSBx3z4zQinSv/ICmx
artifact: /.*\.nupkg/

test: off
for:
- branches:
only:
- master
skip_non_tags: true

deploy:
- provider: NuGet
api_key:
secure: GMc0xUTASI8qTPK1/eN/GFs6PBhPFBin1TT1hE5N8NlkU7VSBx3z4zQinSv/ICmx
artifact: /.*\.nupkg/
192 changes: 162 additions & 30 deletions build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@
#tool "nuget:?package=Mono.TextTransform&version=1.0.0"
#tool "nuget:?package=GitVersion.CommandLine&version=4.0.0"
#addin "nuget:?package=Cake.Incubator&version=4.0.1"
#addin "nuget:?package=Cake.SemVer&version=3.0.0"
#addin "nuget:?package=semver&version=2.0.4"
#addin "nuget:?package=ConsoleMenuLib&version=3.2.1"
#addin "nuget:?package=System.Interactive.Async&version=3.2.0"

using System.Reflection;
using System.Text.RegularExpressions;
using System.Xml.Linq;
using Cake.Incubator.LoggingExtensions;
using ConsoleUi;

//////////////////////////////////////////////////////////////////////
// ARGUMENTS
Expand All @@ -33,7 +38,7 @@ if (!IsRunningOnWindows())
releaseConfigurations.Add("Debug-AOT");
}

var nugetVersion = "0.0.1";
GitVersion version = null;

//////////////////////////////////////////////////////////////////////
// TASKS
Expand Down Expand Up @@ -62,42 +67,37 @@ Task("Restore-NuGet-Packages")
NuGetRestore(solutionPath);
});

Task("Show-Version")
Task("Get-Version")
.Does(() =>
{
var version = GitVersion(new GitVersionSettings
version = GitVersion(new GitVersionSettings
{
UpdateAssemblyInfo = false,
});
Information("Version:\n{0}", version.Dump());
if (AppVeyor.IsRunningOnAppVeyor)
{
if (!string.IsNullOrEmpty(version.PreReleaseTag))
{
version.NuGetVersion = string.Format("{0}-{1}{2}", version.MajorMinorPatch, version.PreReleaseLabel, AppVeyor.Environment.Build.Version.Replace("0.0.", "").PadLeft(4, '0'));
}
AppVeyor.UpdateBuildVersion(version.NuGetVersion);
}
Information("Building release:\n{0}", version.Dump());
});

Task("Set-Build-Version")
.IsDependentOn("Get-Version")
.Does(() =>
{
var version = GitVersion(new GitVersionSettings
{
UpdateAssemblyInfo = false,
});
nugetVersion = version.NuGetVersion;
var assemblyInfo = TransformTextFile("YamlDotNet/Properties/AssemblyInfo.template")
.WithToken("assemblyVersion", $"{version.Major}.0.0.0")
.WithToken("assemblyFileVersion", $"{version.MajorMinorPatch}.0")
.WithToken("assemblyInformationalVersion", nugetVersion)
.WithToken("assemblyInformationalVersion", version.NuGetVersion)
.ToString();
System.IO.File.WriteAllText("YamlDotNet/Properties/AssemblyInfo.cs", assemblyInfo);
if (AppVeyor.IsRunningOnAppVeyor)
{
if (!string.IsNullOrEmpty(version.PreReleaseTag))
{
nugetVersion = string.Format("{0}-{1}{2}", version.MajorMinorPatch, version.PreReleaseLabel, AppVeyor.Environment.Build.Version.Replace("0.0.", "").PadLeft(4, '0'));
}
AppVeyor.UpdateBuildVersion(nugetVersion);
}
});

Task("Build")
Expand Down Expand Up @@ -168,11 +168,132 @@ Task("Package")
NuGetPack(finalNuspecFile, new NuGetPackSettings
{
Version = nugetVersion,
Version = version.NuGetVersion,
OutputDirectory = Directory("YamlDotNet/bin"),
});
});

Task("Release")
.IsDependentOn("Get-Version")
.WithCriteria(() => version.BranchName == "master", "Releases must be created from the master branch")
.Does(() =>
{
// Find previous release
var releases = RunProcess("git", "tag", "--list", "--merged", "master", "--format=\"%(refname:short)\"", "v*")
.Select(tag => new
{
Tag = tag,
Version = ParseSemVer(tag.TrimStart('v')),
})
.OrderByDescending(v => v.Version)
.ToList();
var previousVersion = releases.First();
Information("The previous release was {0}", previousVersion.Version);
var releaseNotesPath = Directory("releases").Path.CombineWithFilePath($"{version.NuGetVersion}.md").FullPath;
Action scaffoldReleaseNotes = () =>
{
// Get the git log to scaffold the release notes
string currentHash = null;
var commits = RunProcess("git", "rev-list", $"{previousVersion.Tag}..HEAD", "--first-parent", "--reverse", "--pretty=tformat:%B")
.Select(l =>
{
var match = Regex.Match(l, "^commit (?<hash>[a-f0-9]+)$");
if (match.Success)
{
currentHash = match.Groups["hash"].Value;
}
return new
{
message = l,
commit = currentHash
};
})
.GroupBy(l => l.commit, (k, list) => new
{
commit = k,
message = list
.Skip(1)
.Select(l => l.message.Trim())
.Where(l => !string.IsNullOrEmpty(l))
.ToList()
});
var log = commits
.Select(c => c.message.Select((l, i) => $"{(i == 0 ? '-' : ' ')} {l}"))
.Select(c => string.Join(" \n", c));
var releaseNotes = $"# Release {version.NuGetVersion}\n\n{string.Join("\n\n", log)}";
System.IO.File.WriteAllText(releaseNotesPath, releaseNotes);
};
if (!FileExists(releaseNotesPath))
{
scaffoldReleaseNotes();
}
// Show release menu
Menu menu = null;
Action updateMenuDescription = () => menu.Description = System.IO.File.ReadAllText(releaseNotesPath);
menu = new Menu(
"Release",
new ActionMenuItem("Edit release notes", ctx =>
{
ctx.SuppressPause();
RunProcess(IsRunningOnWindows() ? "notepad" : "nano", releaseNotesPath);
updateMenuDescription();
}),
new ActionMenuItem("Scaffold release notes", async ctx =>
{
ctx.SuppressPause();
if (await ctx.UserInterface.Confirm(true, "This will erase the current draft. Are you sure ?"))
{
scaffoldReleaseNotes();
updateMenuDescription();
}
}),
new ActionMenuItem("Release", async ctx =>
{
ctx.SuppressPause();
if (await ctx.UserInterface.Confirm(true, "This will publish a new release. Are you sure ?"))
{
menu.ShouldExit = true;
var previousReleases = releases
.Select(r => new
{
r.Version,
Path = $"releases/{r.Version}.md"
})
.Where(r => FileExists(r.Path))
.Select(r => $"- [{r.Version}]({r.Path})");
var releaseNotesFile = string.Join("\n",
"# Release notes",
menu.Description.Replace("# Release", "## Release"),
"# Previous releases",
string.Join("\n", previousReleases)
);
System.IO.File.WriteAllText("RELEASE_NOTES.md", releaseNotesFile);
RunProcess("git", "add", $"\"{releaseNotesPath}\"", "RELEASE_NOTES.md");
RunProcess("git", "commit", "-m", $"\"Prepare release {version.NuGetVersion}\"");
RunProcess("git", "tag", $"v{version.NuGetVersion}");
ctx.UserInterface.Info($"Your release is ready. Remember to push it using the following commands:\n\n git push && git push origin v{version.NuGetVersion}");
}
})
);
updateMenuDescription();
new ConsoleUi.Console.ConsoleMenuRunner().Run(menu).Wait();
});

Task("Document")
.IsDependentOn("Build")
.Does(() =>
Expand Down Expand Up @@ -297,23 +418,34 @@ void BuildSolution(string solutionPath, string configuration, Verbosity verbosit
settings
.SetVerbosity(verbosity)
.SetConfiguration(configuration)
.WithProperty("Version", nugetVersion);
.WithProperty("Version", version.NuGetVersion);
});
}

void RunProcess(string processName, params string[] arguments)
IEnumerable<string> RunProcess(string processName, params string[] arguments)
{
var exitCode = StartProcess(processName, new ProcessSettings().WithArguments(a =>
var settings = new ProcessSettings()
.SetRedirectStandardOutput(true)
.WithArguments(a =>
{
foreach (var argument in arguments)
{
a.Append(argument);
}
});

using (var process = StartAndReturnProcess(processName, settings))
{
foreach (var argument in arguments)
var output = new List<string>(process.GetStandardOutput());
process.WaitForExit();

var exitCode = process.GetExitCode();
if (exitCode != 0)
{
a.Append(argument);
throw new Exception(string.Format("{0} failed with exit code {1}", processName, exitCode));
}
}));

if (exitCode != 0)
{
throw new Exception(string.Format("{0} failed with exit code {1}", processName, exitCode));
return output;
}
}

Expand Down
12 changes: 12 additions & 0 deletions releases/2.0.0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Release 2.0.0

* YamlSerializer has been replaced by the Deserializer class. It offer the same functionality of YamlSerializer but is easier to maintain and extend.
* **Breaking change:** DeserializationOverrides is no longer supported. If you need this, please file a bug and we will analyze it.
* **Breaking change:** IDeserializationContext is no longer supported. If you need this, please file a bug and we will analyze it.
* Tag mappings are registered directly on the Deserializer using RegisterTagMapping()
* ObjectFactory is specified in the constructor, if required.

* Bug fixes to the Serializer:
* Fix bug when serializing lists with nulls inside. e9019d5f224f266e88d9882502f83f0c6865ec24

* Adds a YAML editor add-in for Visual Studio 2012. Available on the [Visual Studio Gallery](http://visualstudiogallery.msdn.microsoft.com/34423c06-f756-4721-8394-bc3d23b91ca7).
4 changes: 4 additions & 0 deletions releases/2.1.0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Release 2.1.0

TODO

4 changes: 4 additions & 0 deletions releases/2.2.0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Release 2.2.0

TODO

10 changes: 10 additions & 0 deletions releases/3.0.0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Release 3.0.0

* Fix issue #26: Use the actual type of the objects instead of the statically detected one.
* Merged the Core, Converters and RepresentationModel assemblies. **The NuGet packages YamlDotNet.Core and YamlDotNet.RepresentationModel are now a single package, named YamlDotNet**.
* Removed YamlDotNet.Configuration and YamlDotNet.Converters.
* Line numbers in error messages now start at one.
* TypeConverter is now used to cast list items.
* Various code improvements.
* More and better unit tests.

4 changes: 4 additions & 0 deletions releases/3.1.0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Release 3.1.0

* Add a parameter to the deserializer to ignore unmapped properties in YAML.

4 changes: 4 additions & 0 deletions releases/3.1.1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Release 3.1.1

This is a bugfix release that fixes issue #90.

11 changes: 11 additions & 0 deletions releases/3.2.0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Release 3.2.0

This release adds merge key support: http://yaml.org/type/merge.html

Example from BackreferencesAreMergedWithMappings unit test:

```C#
var reader = new EventReader(new MergingParser(new Parser(stream)));
var result = Deserializer.Deserialize<Dictionary<string, Dictionary<string, string>>>(parser);
```

4 changes: 4 additions & 0 deletions releases/3.2.1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Release 3.2.1

* Fix AnchorNotFoundException when another exception occurs during deserialization.

0 comments on commit 0341198

Please sign in to comment.