From 47ae7a417cd1960cb80eaa4f432273993ddb3b69 Mon Sep 17 00:00:00 2001 From: Rasmus Mikkelsen Date: Thu, 24 Nov 2022 19:22:12 +0100 Subject: [PATCH] Write release notes --- .../BakeTests/EmptyDirectory.cs | 55 +++++++++++++++++++ .../BakeTests/HelmChartTests.cs | 2 +- Source/Bake/Commands/Run/RunCommand.cs | 15 +++++ TestProjects/EmptyDirectory/.keep-me | 0 4 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 Source/Bake.Tests/IntegrationTests/BakeTests/EmptyDirectory.cs create mode 100644 TestProjects/EmptyDirectory/.keep-me diff --git a/Source/Bake.Tests/IntegrationTests/BakeTests/EmptyDirectory.cs b/Source/Bake.Tests/IntegrationTests/BakeTests/EmptyDirectory.cs new file mode 100644 index 00000000..82c0f984 --- /dev/null +++ b/Source/Bake.Tests/IntegrationTests/BakeTests/EmptyDirectory.cs @@ -0,0 +1,55 @@ +// MIT License +// +// Copyright (c) 2021-2022 Rasmus Mikkelsen +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +using System.Threading.Tasks; +using Bake.Core; +using Bake.Tests.Helpers; +using FluentAssertions; +using NUnit.Framework; + +// ReSharper disable StringLiteralTypo + +namespace Bake.Tests.IntegrationTests.BakeTests +{ + public class EmptyDirectory : BakeTest + { + public EmptyDirectory() : base("EmptyDirectory") + { + } + + [Test] + public async Task Run() + { + // Arrange + var version = SemVer.Random.ToString(); + + // Act + var returnCode = await ExecuteAsync(TestState.New( + "run", + "--log-level=Verbose", + "--build-version", version)); + + // Assert + returnCode.Should().Be(3); + } + } +} diff --git a/Source/Bake.Tests/IntegrationTests/BakeTests/HelmChartTests.cs b/Source/Bake.Tests/IntegrationTests/BakeTests/HelmChartTests.cs index 14d00bc0..037a7638 100644 --- a/Source/Bake.Tests/IntegrationTests/BakeTests/HelmChartTests.cs +++ b/Source/Bake.Tests/IntegrationTests/BakeTests/HelmChartTests.cs @@ -85,7 +85,7 @@ public async Task PushToChartMuseum() var returnCode = await ExecuteAsync(TestState.New( "run", "--convention=Release", - $"--destination=helm-chart>chart-museum@http://localhost:5556", + "--destination=helm-chart>chart-museum@http://localhost:5556", "--build-version", version)); // Assert diff --git a/Source/Bake/Commands/Run/RunCommand.cs b/Source/Bake/Commands/Run/RunCommand.cs index 044df7b6..37ea8935 100644 --- a/Source/Bake/Commands/Run/RunCommand.cs +++ b/Source/Bake/Commands/Run/RunCommand.cs @@ -32,6 +32,7 @@ using Bake.ValueObjects.Destinations; using Microsoft.Extensions.Logging; using Serilog.Events; +using File = Bake.Core.File; namespace Bake.Commands.Run { @@ -68,6 +69,7 @@ public async Task ExecuteAsync( Destination[] destination = null, LogEventLevel logLevel = LogEventLevel.Information, bool printPlan = true, + string releaseNotesOutputPath = null, Platform[] targetPlatform = null) { _logCollector.LogLevel = logLevel; @@ -106,6 +108,19 @@ public async Task ExecuteAsync( book, cancellationToken); + if (success && + !string.IsNullOrEmpty(releaseNotesOutputPath) && + !string.IsNullOrEmpty(content.Ingredients.ReleaseNotes?.Notes)) + { + _logger.LogInformation("Writing release notes to {FilePath}", releaseNotesOutputPath); + var directoryPath = Path.GetDirectoryName(releaseNotesOutputPath); + Directory.CreateDirectory(directoryPath); + await System.IO.File.WriteAllTextAsync( + releaseNotesOutputPath, + content.Ingredients.ReleaseNotes.Notes, + cancellationToken); + } + return success ? 0 : ExitCodes.Core.CookingFailed; diff --git a/TestProjects/EmptyDirectory/.keep-me b/TestProjects/EmptyDirectory/.keep-me new file mode 100644 index 00000000..e69de29b