From ac0683f21cd80b07e7556a054ac01199cb1600a4 Mon Sep 17 00:00:00 2001 From: Simon Baynes Date: Thu, 21 Mar 2024 07:14:59 +0000 Subject: [PATCH 01/15] Add initial skeleton - Working program ready to be converted to an action Closes #1 --- .gitignore | 97 +++++++++++++++++++ .idea/.idea.SemVer.Action/.idea/.gitignore | 18 ++++ .idea/.idea.SemVer.Action/.idea/encodings.xml | 4 + .../.idea.SemVer.Action/.idea/indexLayout.xml | 8 ++ .idea/.idea.SemVer.Action/.idea/sonarlint.xml | 8 ++ .idea/.idea.SemVer.Action/.idea/vcs.xml | 6 ++ SemVer.Action.sln | 35 +++++++ src/SemVer.Json/App.cs | 28 ++++++ .../Features/ReadJsonFile/ReadJsonCommand.cs | 39 ++++++++ .../Features/ReadJsonFile/ReadJsonOptions.cs | 13 +++ .../WriteJsonFile/WriteJsonCommand.cs | 33 +++++++ .../WriteJsonFile/WriteJsonOptions.cs | 33 +++++++ .../Output/GitHubActionOutputWriter.cs | 26 +++++ src/SemVer.Json/Output/IOutputWriter.cs | 6 ++ src/SemVer.Json/Persistence/FileWriter.cs | 9 ++ src/SemVer.Json/Persistence/IFileWriter.cs | 6 ++ src/SemVer.Json/Program.cs | 35 +++++++ src/SemVer.Json/SemVer.Json.csproj | 16 +++ src/SemVer.Json/SemVer.cs | 14 +++ .../Data/incorrect-schema.json | 7 ++ .../SemVer.Json.UnitTests/Data/malformed.json | 1 + .../Data/semver-0-1-4-5.json | 6 ++ .../Data/semver-6-0-44-3.json | 6 ++ .../ReadJsonFile/ReadJsonCommandTests.cs | 90 +++++++++++++++++ ...nFile_ThenJsonStringIsCorrect.verified.txt | 6 ++ .../WriteJsonFile/WriteJsonCommandTests.cs | 59 +++++++++++ test/SemVer.Json.UnitTests/GlobalUsings.cs | 5 + .../SemVer.Json.UnitTests.csproj | 22 +++++ test/SemVer.Json.UnitTests/SemVerTests.cs | 23 +++++ 29 files changed, 659 insertions(+) create mode 100644 .gitignore create mode 100644 .idea/.idea.SemVer.Action/.idea/.gitignore create mode 100644 .idea/.idea.SemVer.Action/.idea/encodings.xml create mode 100644 .idea/.idea.SemVer.Action/.idea/indexLayout.xml create mode 100644 .idea/.idea.SemVer.Action/.idea/sonarlint.xml create mode 100644 .idea/.idea.SemVer.Action/.idea/vcs.xml create mode 100644 SemVer.Action.sln create mode 100644 src/SemVer.Json/App.cs create mode 100644 src/SemVer.Json/Features/ReadJsonFile/ReadJsonCommand.cs create mode 100644 src/SemVer.Json/Features/ReadJsonFile/ReadJsonOptions.cs create mode 100644 src/SemVer.Json/Features/WriteJsonFile/WriteJsonCommand.cs create mode 100644 src/SemVer.Json/Features/WriteJsonFile/WriteJsonOptions.cs create mode 100644 src/SemVer.Json/Output/GitHubActionOutputWriter.cs create mode 100644 src/SemVer.Json/Output/IOutputWriter.cs create mode 100644 src/SemVer.Json/Persistence/FileWriter.cs create mode 100644 src/SemVer.Json/Persistence/IFileWriter.cs create mode 100644 src/SemVer.Json/Program.cs create mode 100644 src/SemVer.Json/SemVer.Json.csproj create mode 100644 src/SemVer.Json/SemVer.cs create mode 100644 test/SemVer.Json.UnitTests/Data/incorrect-schema.json create mode 100644 test/SemVer.Json.UnitTests/Data/malformed.json create mode 100644 test/SemVer.Json.UnitTests/Data/semver-0-1-4-5.json create mode 100644 test/SemVer.Json.UnitTests/Data/semver-6-0-44-3.json create mode 100644 test/SemVer.Json.UnitTests/Features/ReadJsonFile/ReadJsonCommandTests.cs create mode 100644 test/SemVer.Json.UnitTests/Features/WriteJsonFile/WriteJsonCommandTests.WhenWritingJsonFile_ThenJsonStringIsCorrect.verified.txt create mode 100644 test/SemVer.Json.UnitTests/Features/WriteJsonFile/WriteJsonCommandTests.cs create mode 100644 test/SemVer.Json.UnitTests/GlobalUsings.cs create mode 100644 test/SemVer.Json.UnitTests/SemVer.Json.UnitTests.csproj create mode 100644 test/SemVer.Json.UnitTests/SemVerTests.cs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e3564b8 --- /dev/null +++ b/.gitignore @@ -0,0 +1,97 @@ +# Created by https://www.toptal.com/developers/gitignore/api/rider,dotnetcore +# Edit at https://www.toptal.com/developers/gitignore?templates=rider,dotnetcore + +### DotnetCore ### +# .NET Core build folders +bin/ +obj/ + +# Common node modules locations +/node_modules +/wwwroot/node_modules + +### Rider ### +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/**/usage.statistics.xml +.idea/**/dictionaries +.idea/**/shelf + +# AWS User-specific +.idea/**/aws.xml + +# Generated files +.idea/**/contentModel.xml + +# Sensitive or high-churn files +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml +.idea/**/dbnavigator.xml + +# Gradle +.idea/**/gradle.xml +.idea/**/libraries + +# Gradle and Maven with auto-import +# When using Gradle or Maven with auto-import, you should exclude module files, +# since they will be recreated, and may cause churn. Uncomment if using +# auto-import. +# .idea/artifacts +# .idea/compiler.xml +# .idea/jarRepositories.xml +# .idea/modules.xml +# .idea/*.iml +# .idea/modules +# *.iml +# *.ipr + +# CMake +cmake-build-*/ + +# Mongo Explorer plugin +.idea/**/mongoSettings.xml + +# File-based project format +*.iws + +# IntelliJ +out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# SonarLint plugin +.idea/sonarlint/ + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +# Editor-based Rest Client +.idea/httpRequests + +# Android studio 3.1+ serialized cache file +.idea/caches/build_file_checksums.ser + +# End of https://www.toptal.com/developers/gitignore/api/rider,dotnetcore + +*.DotSettings.user + +#Verify +*.received.txt \ No newline at end of file diff --git a/.idea/.idea.SemVer.Action/.idea/.gitignore b/.idea/.idea.SemVer.Action/.idea/.gitignore new file mode 100644 index 0000000..9ba2980 --- /dev/null +++ b/.idea/.idea.SemVer.Action/.idea/.gitignore @@ -0,0 +1,18 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Rider ignored files +/projectSettingsUpdater.xml +/.idea.SemVer.Action.iml +/modules.xml +/contentModel.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml +# GitHub Copilot persisted chat sessions +/copilot/chatSessions + +# sonarlint +/sonarlint/ \ No newline at end of file diff --git a/.idea/.idea.SemVer.Action/.idea/encodings.xml b/.idea/.idea.SemVer.Action/.idea/encodings.xml new file mode 100644 index 0000000..df87cf9 --- /dev/null +++ b/.idea/.idea.SemVer.Action/.idea/encodings.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/.idea.SemVer.Action/.idea/indexLayout.xml b/.idea/.idea.SemVer.Action/.idea/indexLayout.xml new file mode 100644 index 0000000..7b08163 --- /dev/null +++ b/.idea/.idea.SemVer.Action/.idea/indexLayout.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/.idea.SemVer.Action/.idea/sonarlint.xml b/.idea/.idea.SemVer.Action/.idea/sonarlint.xml new file mode 100644 index 0000000..96a1c17 --- /dev/null +++ b/.idea/.idea.SemVer.Action/.idea/sonarlint.xml @@ -0,0 +1,8 @@ + + + + + \ No newline at end of file diff --git a/.idea/.idea.SemVer.Action/.idea/vcs.xml b/.idea/.idea.SemVer.Action/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/.idea.SemVer.Action/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/SemVer.Action.sln b/SemVer.Action.sln new file mode 100644 index 0000000..99c1e40 --- /dev/null +++ b/SemVer.Action.sln @@ -0,0 +1,35 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{FF63065C-83A2-4267-BBD7-3CE3E8F9D247}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{FAD24DB5-E310-4675-9234-62A77C15D0FE}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{74006CDD-CD53-4AEA-88EF-7E83BB20667F}" + ProjectSection(SolutionItems) = preProject + .gitignore = .gitignore + EndProjectSection +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SemVer.Json", "src\SemVer.Json\SemVer.Json.csproj", "{0DA1B9C2-0F3D-4BE3-99D4-628CCE9E4389}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SemVer.Json.UnitTests", "test\SemVer.Json.UnitTests\SemVer.Json.UnitTests.csproj", "{DE1FAEAE-0E49-4C48-865F-90C44BF9CF67}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {0DA1B9C2-0F3D-4BE3-99D4-628CCE9E4389} = {FF63065C-83A2-4267-BBD7-3CE3E8F9D247} + {DE1FAEAE-0E49-4C48-865F-90C44BF9CF67} = {FAD24DB5-E310-4675-9234-62A77C15D0FE} + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {0DA1B9C2-0F3D-4BE3-99D4-628CCE9E4389}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {0DA1B9C2-0F3D-4BE3-99D4-628CCE9E4389}.Debug|Any CPU.Build.0 = Debug|Any CPU + {0DA1B9C2-0F3D-4BE3-99D4-628CCE9E4389}.Release|Any CPU.ActiveCfg = Release|Any CPU + {0DA1B9C2-0F3D-4BE3-99D4-628CCE9E4389}.Release|Any CPU.Build.0 = Release|Any CPU + {DE1FAEAE-0E49-4C48-865F-90C44BF9CF67}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {DE1FAEAE-0E49-4C48-865F-90C44BF9CF67}.Debug|Any CPU.Build.0 = Debug|Any CPU + {DE1FAEAE-0E49-4C48-865F-90C44BF9CF67}.Release|Any CPU.ActiveCfg = Release|Any CPU + {DE1FAEAE-0E49-4C48-865F-90C44BF9CF67}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal diff --git a/src/SemVer.Json/App.cs b/src/SemVer.Json/App.cs new file mode 100644 index 0000000..e643265 --- /dev/null +++ b/src/SemVer.Json/App.cs @@ -0,0 +1,28 @@ +using CommandLine; +using Microsoft.Extensions.Configuration; +using SemVer.Json.Features.ReadJsonFile; +using SemVer.Json.Features.WriteJsonFile; + +namespace SemVer.Json; + +public class App +{ + private readonly ReadJsonCommand _readJsonCommand; + private readonly WriteJsonCommand _writeJsonCommand; + + public App(IConfiguration configuration, ReadJsonCommand readJsonCommand, WriteJsonCommand writeJsonCommand) + { + _readJsonCommand = readJsonCommand; + _writeJsonCommand = writeJsonCommand; + } + + public void Run(IEnumerable args) + { + Parser.Default.ParseArguments(args) + .MapResult( + (ReadJsonOptions opts) => _readJsonCommand.Read(opts), + (WriteJsonOptions opts) => _writeJsonCommand.Write(opts), + _ => 1 + ); + } +} \ No newline at end of file diff --git a/src/SemVer.Json/Features/ReadJsonFile/ReadJsonCommand.cs b/src/SemVer.Json/Features/ReadJsonFile/ReadJsonCommand.cs new file mode 100644 index 0000000..0cff36c --- /dev/null +++ b/src/SemVer.Json/Features/ReadJsonFile/ReadJsonCommand.cs @@ -0,0 +1,39 @@ +using System.Text.Json; +using Microsoft.Extensions.Logging; +using SemVer.Json.Output; + +namespace SemVer.Json.Features.ReadJsonFile; + +public class ReadJsonCommand(IOutputWriter outputWriter, ILogger logger) +{ + private readonly JsonSerializerOptions _jsonSerializerOptions = new() + { + PropertyNameCaseInsensitive = true + }; + + public int Read(ReadJsonOptions opts) + { + string json; + try + { + json = File.ReadAllText(opts.Path); + } + catch (FileNotFoundException ex) + { + logger.LogError(ex, "Error reading JSON file: {Message}", ex.Message); + return 1; + } + + try + { + var semVer = JsonSerializer.Deserialize(json, _jsonSerializerOptions); + outputWriter.OutputVersion(semVer!); + } + catch (JsonException ex) + { + logger.LogError(ex, "Error deserializing JSON file: {Message}", ex.Message); + return 1; + } + return 0; + } +} \ No newline at end of file diff --git a/src/SemVer.Json/Features/ReadJsonFile/ReadJsonOptions.cs b/src/SemVer.Json/Features/ReadJsonFile/ReadJsonOptions.cs new file mode 100644 index 0000000..f85262a --- /dev/null +++ b/src/SemVer.Json/Features/ReadJsonFile/ReadJsonOptions.cs @@ -0,0 +1,13 @@ +using CommandLine; + +namespace SemVer.Json.Features.ReadJsonFile; + +[Verb("read", HelpText = "Reads a SemVer JSON file, and outputs the version numbers.")] +public class ReadJsonOptions +{ + [Option('p', "path", + Required = true, + Default = "semver.json", + HelpText = "The path to the SemVer JSON file.")] + public string Path { get; set; } = null!; +} \ No newline at end of file diff --git a/src/SemVer.Json/Features/WriteJsonFile/WriteJsonCommand.cs b/src/SemVer.Json/Features/WriteJsonFile/WriteJsonCommand.cs new file mode 100644 index 0000000..a80de77 --- /dev/null +++ b/src/SemVer.Json/Features/WriteJsonFile/WriteJsonCommand.cs @@ -0,0 +1,33 @@ +using System.Text.Json; +using SemVer.Json.Persistence; + +namespace SemVer.Json.Features.WriteJsonFile; + +public class WriteJsonCommand +{ + private readonly IFileWriter _fileWriter; + private readonly JsonSerializerOptions _jsonSerializerOptions = new() + { + PropertyNamingPolicy = JsonNamingPolicy.CamelCase + }; + + public WriteJsonCommand(IFileWriter fileWriter) + { + _fileWriter = fileWriter; + } + + public int Write(WriteJsonOptions options) + { + var semVer = new SemVer + { + Major = options.Major, + Minor = options.Minor, + Patch = options.Patch, + Build = options.Build + }; + var json = JsonSerializer.Serialize(semVer, _jsonSerializerOptions); + _fileWriter.WriteJson(json, options.Path); + + return 0; + } +} \ No newline at end of file diff --git a/src/SemVer.Json/Features/WriteJsonFile/WriteJsonOptions.cs b/src/SemVer.Json/Features/WriteJsonFile/WriteJsonOptions.cs new file mode 100644 index 0000000..e419e85 --- /dev/null +++ b/src/SemVer.Json/Features/WriteJsonFile/WriteJsonOptions.cs @@ -0,0 +1,33 @@ +using CommandLine; + +namespace SemVer.Json.Features.WriteJsonFile; + +[Verb("write", HelpText = "Writes a SemVer JSON file, with the specified version numbers.")] +public class WriteJsonOptions +{ + [Option('p', "path", + Required = true, + Default = "semver.json", + HelpText = "The path to the SemVer JSON file.")] + public string Path { get; set; } = null!; + + [Option('m', "major", + Required = true, + HelpText = "The major version number.")] + public string Major { get; set; } = null!; + + [Option('n', "minor", + Required = true, + HelpText = "The minor version number.")] + public string Minor { get; set; } = null!; + + [Option('h', "patch", + Required = true, + HelpText = "The patch version number.")] + public string Patch { get; set; } = null!; + + [Option('b', "build", + Required = true, + HelpText = "The build version number.")] + public string Build { get; set; } = null!; +} \ No newline at end of file diff --git a/src/SemVer.Json/Output/GitHubActionOutputWriter.cs b/src/SemVer.Json/Output/GitHubActionOutputWriter.cs new file mode 100644 index 0000000..3746b60 --- /dev/null +++ b/src/SemVer.Json/Output/GitHubActionOutputWriter.cs @@ -0,0 +1,26 @@ +using System.Text; + +namespace SemVer.Json.Output; + +public class GitHubActionOutputWriter : IOutputWriter +{ + private const string GitHubOutput = "GITHUB_OUTPUT"; + public void OutputVersion(SemVer semVer) + { + var gitHubOutputFile = Environment.GetEnvironmentVariable(GitHubOutput); + if (string.IsNullOrEmpty(gitHubOutputFile)) return; + + using var textWriter = new StreamWriter(gitHubOutputFile, append: true, Encoding.UTF8); + WriteVariableToGitHubAction(textWriter, "major", semVer.Major); + WriteVariableToGitHubAction(textWriter, "minor", semVer.Minor); + WriteVariableToGitHubAction(textWriter, "patch", semVer.Patch); + WriteVariableToGitHubAction(textWriter, "build", semVer.Build); + WriteVariableToGitHubAction(textWriter, "version", semVer.ToVersion()); + } + + private static void WriteVariableToGitHubAction(TextWriter textWriter, string name, string value) + { + var output = $"{name}={value}"; + textWriter.WriteLine(output); + } +} \ No newline at end of file diff --git a/src/SemVer.Json/Output/IOutputWriter.cs b/src/SemVer.Json/Output/IOutputWriter.cs new file mode 100644 index 0000000..bc2df91 --- /dev/null +++ b/src/SemVer.Json/Output/IOutputWriter.cs @@ -0,0 +1,6 @@ +namespace SemVer.Json.Output; + +public interface IOutputWriter +{ + void OutputVersion(SemVer semVer); +} \ No newline at end of file diff --git a/src/SemVer.Json/Persistence/FileWriter.cs b/src/SemVer.Json/Persistence/FileWriter.cs new file mode 100644 index 0000000..51c04d4 --- /dev/null +++ b/src/SemVer.Json/Persistence/FileWriter.cs @@ -0,0 +1,9 @@ +namespace SemVer.Json.Persistence; + +public class FileWriter : IFileWriter +{ + public void WriteJson(string jsonString, string filePath) + { + File.WriteAllText(filePath, jsonString); + } +} \ No newline at end of file diff --git a/src/SemVer.Json/Persistence/IFileWriter.cs b/src/SemVer.Json/Persistence/IFileWriter.cs new file mode 100644 index 0000000..806988c --- /dev/null +++ b/src/SemVer.Json/Persistence/IFileWriter.cs @@ -0,0 +1,6 @@ +namespace SemVer.Json.Persistence; + +public interface IFileWriter +{ + public void WriteJson(string jsonString, string filePath); +} \ No newline at end of file diff --git a/src/SemVer.Json/Program.cs b/src/SemVer.Json/Program.cs new file mode 100644 index 0000000..677bcf4 --- /dev/null +++ b/src/SemVer.Json/Program.cs @@ -0,0 +1,35 @@ +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using SemVer.Json; +using SemVer.Json.Features.ReadJsonFile; +using SemVer.Json.Features.WriteJsonFile; +using SemVer.Json.Output; +using SemVer.Json.Persistence; + +using var host = CreateHostBuilder(args).Build(); +using var scope = host.Services.CreateScope(); + +var services = scope.ServiceProvider; +try +{ + services.GetRequiredService().Run(args); +} +catch (Exception e) +{ + Console.WriteLine(e.Message); +} + +return; + +IHostBuilder CreateHostBuilder(string[] strings) +{ + return Host.CreateDefaultBuilder() + .ConfigureServices((_, s) => + { + s.AddSingleton(); + s.AddSingleton(); + s.AddSingleton(); + s.AddSingleton(); + s.AddSingleton(); + }); +} \ No newline at end of file diff --git a/src/SemVer.Json/SemVer.Json.csproj b/src/SemVer.Json/SemVer.Json.csproj new file mode 100644 index 0000000..bbcee7c --- /dev/null +++ b/src/SemVer.Json/SemVer.Json.csproj @@ -0,0 +1,16 @@ + + + + Exe + net8.0 + enable + enable + + + + + + + + + diff --git a/src/SemVer.Json/SemVer.cs b/src/SemVer.Json/SemVer.cs new file mode 100644 index 0000000..85b01d0 --- /dev/null +++ b/src/SemVer.Json/SemVer.cs @@ -0,0 +1,14 @@ +namespace SemVer.Json; + +public record SemVer +{ + public required string Major { get; set; } + public required string Minor { get; set; } + public required string Patch { get; set; } + public required string Build { get; set; } + + public string ToVersion() + { + return $"{Major}.{Minor}.{Patch}.{Build}"; + } +} \ No newline at end of file diff --git a/test/SemVer.Json.UnitTests/Data/incorrect-schema.json b/test/SemVer.Json.UnitTests/Data/incorrect-schema.json new file mode 100644 index 0000000..3a8d845 --- /dev/null +++ b/test/SemVer.Json.UnitTests/Data/incorrect-schema.json @@ -0,0 +1,7 @@ +{ + "name": "Terry", + "address": { + "city": "New York", + "state": "NY" + } +} \ No newline at end of file diff --git a/test/SemVer.Json.UnitTests/Data/malformed.json b/test/SemVer.Json.UnitTests/Data/malformed.json new file mode 100644 index 0000000..81750b9 --- /dev/null +++ b/test/SemVer.Json.UnitTests/Data/malformed.json @@ -0,0 +1 @@ +{ \ No newline at end of file diff --git a/test/SemVer.Json.UnitTests/Data/semver-0-1-4-5.json b/test/SemVer.Json.UnitTests/Data/semver-0-1-4-5.json new file mode 100644 index 0000000..170afda --- /dev/null +++ b/test/SemVer.Json.UnitTests/Data/semver-0-1-4-5.json @@ -0,0 +1,6 @@ +{ + "major": "0", + "minor": "1", + "patch": "4", + "build": "5" +} \ No newline at end of file diff --git a/test/SemVer.Json.UnitTests/Data/semver-6-0-44-3.json b/test/SemVer.Json.UnitTests/Data/semver-6-0-44-3.json new file mode 100644 index 0000000..a3d059d --- /dev/null +++ b/test/SemVer.Json.UnitTests/Data/semver-6-0-44-3.json @@ -0,0 +1,6 @@ +{ + "major": "6", + "minor": "0", + "patch": "44", + "build": "3" +} \ No newline at end of file diff --git a/test/SemVer.Json.UnitTests/Features/ReadJsonFile/ReadJsonCommandTests.cs b/test/SemVer.Json.UnitTests/Features/ReadJsonFile/ReadJsonCommandTests.cs new file mode 100644 index 0000000..fa7199f --- /dev/null +++ b/test/SemVer.Json.UnitTests/Features/ReadJsonFile/ReadJsonCommandTests.cs @@ -0,0 +1,90 @@ +using Microsoft.Extensions.Logging; +using SemVer.Json.Features.ReadJsonFile; +using SemVer.Json.Output; + +namespace SemVer.Json.UnitTests.Features.ReadJsonFile; + +public class ReadJsonCommandTests +{ + private readonly IOutputWriter _mockOutputWriter = Substitute.For(); + private readonly ILogger _mockLogger = Substitute.For>(); + private readonly ReadJsonCommand _sut; + + public ReadJsonCommandTests() + { + _sut = new ReadJsonCommand(_mockOutputWriter, _mockLogger); + } + + [Theory] + [InlineData("Data/semver-0-1-4-5.json", "0", "1", "4", "5")] + [InlineData("Data/semver-6-0-44-3.json", "6", "0", "44", "3")] + public void WhenReadingJsonFile_ThenShouldReturnCorrectVersionInformation(string file, string major, string minor, string patch, string build) + { + // arrange + var options = new ReadJsonOptions + { + Path = Path.Combine(Environment.CurrentDirectory, "..", "..", "..", file) + }; + var expectedVersion = new SemVer + { + Major = major, + Minor = minor, + Patch = patch, + Build = build + }; + + // act + _sut.Read(options); + + // assert + _mockOutputWriter.Received(1).OutputVersion(expectedVersion); + } + + [Fact] + public void WhenReadingMalformedJsonFile_ThenShouldReturnErrorCode() + { + // arrange + var options = new ReadJsonOptions + { + Path = Path.Combine(Environment.CurrentDirectory, "..", "..", "..", "Data/malformed.json") + }; + + // act + var result = _sut.Read(options); + + // assert + result.Should().Be(1); + } + + [Fact] + public void WhenReadingAJsonFileWithAnIncorrectSchema_ThenShouldReturnErrorCode() + { + // arrange + var options = new ReadJsonOptions + { + Path = Path.Combine(Environment.CurrentDirectory, "..", "..", "..", "Data/incorrect-schema.json") + }; + + // act + var result = _sut.Read(options); + + // assert + result.Should().Be(1); + } + + [Fact] + public void WhenReadingAJsonFileThatDoesNotExist_ThenShouldReturnErrorCode() + { + // arrange + var options = new ReadJsonOptions + { + Path = Path.Combine(Environment.CurrentDirectory, "..", "..", "..", "Data/does-not-exist.json") + }; + + // act + var result = _sut.Read(options); + + // assert + result.Should().Be(1); + } +} \ No newline at end of file diff --git a/test/SemVer.Json.UnitTests/Features/WriteJsonFile/WriteJsonCommandTests.WhenWritingJsonFile_ThenJsonStringIsCorrect.verified.txt b/test/SemVer.Json.UnitTests/Features/WriteJsonFile/WriteJsonCommandTests.WhenWritingJsonFile_ThenJsonStringIsCorrect.verified.txt new file mode 100644 index 0000000..1125130 --- /dev/null +++ b/test/SemVer.Json.UnitTests/Features/WriteJsonFile/WriteJsonCommandTests.WhenWritingJsonFile_ThenJsonStringIsCorrect.verified.txt @@ -0,0 +1,6 @@ +{ + major: 1, + minor: 2, + patch: 3, + build: 4 +} \ No newline at end of file diff --git a/test/SemVer.Json.UnitTests/Features/WriteJsonFile/WriteJsonCommandTests.cs b/test/SemVer.Json.UnitTests/Features/WriteJsonFile/WriteJsonCommandTests.cs new file mode 100644 index 0000000..c61b92e --- /dev/null +++ b/test/SemVer.Json.UnitTests/Features/WriteJsonFile/WriteJsonCommandTests.cs @@ -0,0 +1,59 @@ +using SemVer.Json.Features.WriteJsonFile; +using SemVer.Json.Persistence; + +namespace SemVer.Json.UnitTests.Features.WriteJsonFile; + +public class WriteJsonCommandTests +{ + private readonly IFileWriter _mockFileWriter = Substitute.For(); + private readonly WriteJsonCommand _sut; + + public WriteJsonCommandTests() + { + _sut = new WriteJsonCommand(_mockFileWriter); + } + + [Fact] + public void WhenWritingJsonFile_ThenFileIsWrittenToCorrectPath() + { + // arrange + var options = new WriteJsonOptions + { + Path = "test.json", + Major = "1", + Minor = "2", + Patch = "3", + Build = "4" + }; + + // act + _sut.Write(options); + + // assert + _mockFileWriter.Received(1).WriteJson(Arg.Any(), Arg.Is(s => s == options.Path)); + } + + [Fact] + public Task WhenWritingJsonFile_ThenJsonStringIsCorrect() + { + // arrange + var options = new WriteJsonOptions + { + Path = "test.json", + Major = "1", + Minor = "2", + Patch = "3", + Build = "4" + }; + + var actualJson = string.Empty; + + _mockFileWriter.WriteJson(Arg.Do(s => actualJson = s), Arg.Any()); + + // act + _sut.Write(options); + + // assert + return VerifyJson(actualJson); + } +} \ No newline at end of file diff --git a/test/SemVer.Json.UnitTests/GlobalUsings.cs b/test/SemVer.Json.UnitTests/GlobalUsings.cs new file mode 100644 index 0000000..eda208e --- /dev/null +++ b/test/SemVer.Json.UnitTests/GlobalUsings.cs @@ -0,0 +1,5 @@ +// Global using directives + +global using FluentAssertions; +global using NSubstitute; +global using Xunit; \ No newline at end of file diff --git a/test/SemVer.Json.UnitTests/SemVer.Json.UnitTests.csproj b/test/SemVer.Json.UnitTests/SemVer.Json.UnitTests.csproj new file mode 100644 index 0000000..a86edbe --- /dev/null +++ b/test/SemVer.Json.UnitTests/SemVer.Json.UnitTests.csproj @@ -0,0 +1,22 @@ + + + + net8.0 + enable + enable + + + + + + + + + + + + + + + + diff --git a/test/SemVer.Json.UnitTests/SemVerTests.cs b/test/SemVer.Json.UnitTests/SemVerTests.cs new file mode 100644 index 0000000..3502c66 --- /dev/null +++ b/test/SemVer.Json.UnitTests/SemVerTests.cs @@ -0,0 +1,23 @@ +using FsCheck; +using FsCheck.Xunit; + +namespace SemVer.Json.UnitTests; + +public class SemVerTests +{ + [Property] + public Property ToVersion_ReturnsAConcatenatedVersionString(string major, string minor, string patch, string build) + { + var semVer = new SemVer + { + Major = major, + Minor = minor, + Patch = patch, + Build = build + }; + + var result = semVer.ToVersion(); + + return (result == $"{major}.{minor}.{patch}.{build}").ToProperty(); + } +} \ No newline at end of file From e739745bbfc93566e69c719a2747f43ba7958a08 Mon Sep 17 00:00:00 2001 From: Simon Baynes Date: Thu, 21 Mar 2024 10:17:43 +0000 Subject: [PATCH 02/15] Add auto labelling workflow Closes #3 --- .github/labels.yml | 42 +++++++++++++++++++ .github/workflows/label-configurer.yml | 20 +++++++++ .../.idea.SemVer.Action/.idea/indexLayout.xml | 4 +- 3 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 .github/labels.yml create mode 100644 .github/workflows/label-configurer.yml diff --git a/.github/labels.yml b/.github/labels.yml new file mode 100644 index 0000000..f3d0315 --- /dev/null +++ b/.github/labels.yml @@ -0,0 +1,42 @@ +- name: "blocked" + color: "ff0000" + description: "This issue is blocked by another issue" +- name: "breaking change" + color: "ff0205" + description: "This change will require a major version bump" +- name: "bug" + color: "d73a4a" + description: "Something isn't working" +- name: "dependencies" + color: "0366d6" + description: "Pull requests that update a dependency file" +- name: "documentation" + color: "0075ca" + description: "Improvements or additions to documentation" +- name: "duplicate" + color: "cfd3d7" + description: "This issue or pull request already exists" +- name: "environment" + color: "703E17" + description: "Improvement, to infra or build environment" +- name: "feature" + color: "fbca04" + description: "A new business feature" +- name: "in progress" + color: "5ae1c2" + description: "In flight work" +- name: "next release" + color: "5319e7" + description: "Completed work that is yet to be deployed" +- name: "security" + color: "000000" + description: "Security related work" +- name: "spike" + color: "65ff00" + description: "Testing if something is possible, or learning a new technology" +- name: "technical debt" + color: "c19337" + description: "An issue describing some technical debt that needs to be addressed in the future" +- name: "to do" + color: "fbca04" + description: "Work that is yet to be started" diff --git a/.github/workflows/label-configurer.yml b/.github/workflows/label-configurer.yml new file mode 100644 index 0000000..1052859 --- /dev/null +++ b/.github/workflows/label-configurer.yml @@ -0,0 +1,20 @@ +name: Configure GitHub Issue Labels + +on: + push: + paths: + - ".github/workflows/label-configurer.yml" + - ".github/labels.yml" + +jobs: + labeler: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Run Labeler + uses: crazy-max/ghaction-github-labeler@v5 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + exclude: | + *min review \ No newline at end of file diff --git a/.idea/.idea.SemVer.Action/.idea/indexLayout.xml b/.idea/.idea.SemVer.Action/.idea/indexLayout.xml index 7b08163..1ead36c 100644 --- a/.idea/.idea.SemVer.Action/.idea/indexLayout.xml +++ b/.idea/.idea.SemVer.Action/.idea/indexLayout.xml @@ -1,7 +1,9 @@ - + + .github + From e4f551de76ae6b28db71543cd162a57a06d286e4 Mon Sep 17 00:00:00 2001 From: Simon Baynes Date: Thu, 21 Mar 2024 10:50:47 +0000 Subject: [PATCH 03/15] Add README Closes #5 --- README.md | 3 +++ SemVer.Action.sln | 1 + 2 files changed, 4 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..58bab1f --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# SemVer Action + +This is a GitHub Action to allow you to use a JSON file to manage your project's Semantic Version Number. \ No newline at end of file diff --git a/SemVer.Action.sln b/SemVer.Action.sln index 99c1e40..3af0437 100644 --- a/SemVer.Action.sln +++ b/SemVer.Action.sln @@ -7,6 +7,7 @@ EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{74006CDD-CD53-4AEA-88EF-7E83BB20667F}" ProjectSection(SolutionItems) = preProject .gitignore = .gitignore + README.md = README.md EndProjectSection EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SemVer.Json", "src\SemVer.Json\SemVer.Json.csproj", "{0DA1B9C2-0F3D-4BE3-99D4-628CCE9E4389}" From b3922e693e6c6e5fb72d4fadf9a19e97503b7b44 Mon Sep 17 00:00:00 2001 From: Simon Baynes Date: Thu, 21 Mar 2024 11:08:45 +0000 Subject: [PATCH 04/15] Add issue workflow Closes #9 --- .../workflows/completed-feature-workflow.yml | 24 +++++++++++++++++++ .../in-progress-feature-workflow.yml | 23 ++++++++++++++++++ .github/workflows/new-issue-workflow.yml | 15 ++++++++++++ 3 files changed, 62 insertions(+) create mode 100644 .github/workflows/completed-feature-workflow.yml create mode 100644 .github/workflows/in-progress-feature-workflow.yml create mode 100644 .github/workflows/new-issue-workflow.yml diff --git a/.github/workflows/completed-feature-workflow.yml b/.github/workflows/completed-feature-workflow.yml new file mode 100644 index 0000000..84c3dc0 --- /dev/null +++ b/.github/workflows/completed-feature-workflow.yml @@ -0,0 +1,24 @@ +name: Completed Feature Workflow + +on: + pull_request: + branches: [ develop ] + types: [closed] + +jobs: + update-merged-issue-issues: + if: github.event.pull_request.merged_by != '' && github.actor != 'dependabot[bot]' && startsWith(github.head_ref, 'feature/issue-') + runs-on: ubuntu-latest + steps: + - name: Checkout repo + uses: actions/checkout@v4 + - name: Extract Issue Number + shell: bash + run: echo "##[set-output name=issue;]$(echo ${{ github.event.pull_request.head.ref }} | sed 's|[^0-9]||g')" + id: extract_issue + - name: Output Issue Number + run: echo "Issue Number- ${{ steps.extract_issue.outputs.issue }}" + - name: Update Labels + run: gh issue edit ${{ steps.extract_issue.outputs.issue }} --add-label "next release" --remove-label "in progress" + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/in-progress-feature-workflow.yml b/.github/workflows/in-progress-feature-workflow.yml new file mode 100644 index 0000000..b1b9126 --- /dev/null +++ b/.github/workflows/in-progress-feature-workflow.yml @@ -0,0 +1,23 @@ +name: In Progress Feature Workflow + +on: + push: + branches: + - feature/issue-* + +jobs: + update-in-progress-issues: + runs-on: ubuntu-latest + steps: + - name: Checkout repo + uses: actions/checkout@v4 + - name: Extract Issue Number + shell: bash + run: echo "##[set-output name=issue;]$(echo ${GITHUB_REF#refs/heads/} | sed 's|[^0-9]||g')" + id: extract_issue + - name: Output Issue Number + run: echo "Issue Number- ${{ steps.extract_issue.outputs.issue }}" + - name: Update Labels + run: gh issue edit ${{ steps.extract_issue.outputs.issue }} --add-label "in progress" --remove-label "to do" + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/new-issue-workflow.yml b/.github/workflows/new-issue-workflow.yml new file mode 100644 index 0000000..feba4ca --- /dev/null +++ b/.github/workflows/new-issue-workflow.yml @@ -0,0 +1,15 @@ +name: New Issue Workflow +on: + issues: + types: + - opened + +jobs: + update-new-issues: + runs-on: ubuntu-latest + steps: + - name: Initialise Labelling + run: gh issue edit $ISSUE --add-label "to do" + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + ISSUE: ${{ github.event.issue.html_url }} \ No newline at end of file From 5c873a3201121c49ce5b85931c26dfa633d25646 Mon Sep 17 00:00:00 2001 From: Simon Baynes Date: Thu, 21 Mar 2024 11:13:20 +0000 Subject: [PATCH 05/15] Add commit template Closes #8 --- .gitmessage | 12 ++++++++++++ CONTRIBUTING.md | 24 ++++++++++++++++++++++++ README.md | 7 ++++++- SemVer.Action.sln | 2 ++ 4 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 .gitmessage create mode 100644 CONTRIBUTING.md diff --git a/.gitmessage b/.gitmessage new file mode 100644 index 0000000..1616fdc --- /dev/null +++ b/.gitmessage @@ -0,0 +1,12 @@ +#<-- Max width of message --># +# If applied, this commit will... + + + +#<-- Max width of message --># +# Explain why this change is being made + + + +# Provide links to any relevant tickets, articles or other resources + diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..e7888c2 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,24 @@ +# Contributing + +## Branch Naming + +Our branch naming convention is as follows: +* `feature/issue--` +* Please add **NO NUMBERS** to the `` part of the branch name. As this will mess up the issue tracking. + +## Pull Requests + +After forking the repository please create a pull request before creating the +fix. This way we can talk about how the fix will be implemented. This will +greatly increase your chance of your patch getting merged into the code base. + +Please create all pull requests from the `develop` branch. + +### Commit Template + +Please run the following to make sure you commit messages conform to the project +standards. + +```bash +git config --local commit.template .gitmessage +``` \ No newline at end of file diff --git a/README.md b/README.md index 58bab1f..37badd1 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,8 @@ # SemVer Action -This is a GitHub Action to allow you to use a JSON file to manage your project's Semantic Version Number. \ No newline at end of file +This is a GitHub Action to allow you to use a JSON file to manage your project's Semantic Version Number. + +## Contributing + +Please read [CONTRIBUTING.md](CONTRIBUTING.md) for details on our code of conduct, and the process for submitting pull +requests to us. \ No newline at end of file diff --git a/SemVer.Action.sln b/SemVer.Action.sln index 3af0437..97a0087 100644 --- a/SemVer.Action.sln +++ b/SemVer.Action.sln @@ -8,6 +8,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution ProjectSection(SolutionItems) = preProject .gitignore = .gitignore README.md = README.md + .gitmessage = .gitmessage + CONTRIBUTING.md = CONTRIBUTING.md EndProjectSection EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SemVer.Json", "src\SemVer.Json\SemVer.Json.csproj", "{0DA1B9C2-0F3D-4BE3-99D4-628CCE9E4389}" From c3578b432d367ccdbc70c4aea0b285d0ac238892 Mon Sep 17 00:00:00 2001 From: Simon Baynes Date: Thu, 21 Mar 2024 11:15:57 +0000 Subject: [PATCH 06/15] Add Gitstream Closes #7 --- .cm/gitstream.cm | 17 ++++++++++++ .github/workflows/gitstream.yml | 47 +++++++++++++++++++++++++++++++++ SemVer.Action.sln | 1 + 3 files changed, 65 insertions(+) create mode 100644 .cm/gitstream.cm create mode 100644 .github/workflows/gitstream.yml diff --git a/.cm/gitstream.cm b/.cm/gitstream.cm new file mode 100644 index 0000000..d25c2b8 --- /dev/null +++ b/.cm/gitstream.cm @@ -0,0 +1,17 @@ +# -*- mode: yaml -*- + +manifest: + version: 1.0 + +automations: + estimated_time_to_review: + if: + - true + run: + - action: add-label@v1 + args: + label: "{{ calc.etr }} min review" + color: {{ 'E94637' if (calc.etr >= 20) else ('FBBD10' if (calc.etr >= 5) else '36A853') }} + +calc: + etr: {{ branch | estimatedReviewTime }} \ No newline at end of file diff --git a/.github/workflows/gitstream.yml b/.github/workflows/gitstream.yml new file mode 100644 index 0000000..7fa77fa --- /dev/null +++ b/.github/workflows/gitstream.yml @@ -0,0 +1,47 @@ +# Code generated by gitStream GitHub app - DO NOT EDIT + +name: gitStream workflow automation + +on: + workflow_dispatch: + inputs: + client_payload: + description: The Client payload + required: true + full_repository: + description: the repository name include the owner in `owner/repo_name` format + required: true + head_ref: + description: the head sha + required: true + base_ref: + description: the base ref + required: true + installation_id: + description: the installation id + required: false + resolver_url: + description: the resolver url to pass results to + required: true + resolver_token: + description: Optional resolver token for resolver service + required: false + default: '' + +jobs: + gitStream: + timeout-minutes: 5 + runs-on: ubuntu-latest + name: gitStream workflow automation + steps: + - name: Evaluate Rules + uses: linear-b/gitstream-github-action@v1 + id: rules-engine + with: + full_repository: ${{ github.event.inputs.full_repository }} + head_ref: ${{ github.event.inputs.head_ref }} + base_ref: ${{ github.event.inputs.base_ref }} + client_payload: ${{ github.event.inputs.client_payload }} + installation_id: ${{ github.event.inputs.installation_id }} + resolver_url: ${{ github.event.inputs.resolver_url }} + resolver_token: ${{ github.event.inputs.resolver_token }} diff --git a/SemVer.Action.sln b/SemVer.Action.sln index 97a0087..668aa03 100644 --- a/SemVer.Action.sln +++ b/SemVer.Action.sln @@ -10,6 +10,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution README.md = README.md .gitmessage = .gitmessage CONTRIBUTING.md = CONTRIBUTING.md + .cm\gitstream.cm = .cm\gitstream.cm EndProjectSection EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SemVer.Json", "src\SemVer.Json\SemVer.Json.csproj", "{0DA1B9C2-0F3D-4BE3-99D4-628CCE9E4389}" From eca5a6204d704c3153358b1741be512b20da70fd Mon Sep 17 00:00:00 2001 From: Simon Baynes Date: Thu, 21 Mar 2024 12:02:46 +0000 Subject: [PATCH 07/15] Add license Closes #13 --- LICENSE.txt | 201 ++++++++++++++++++++++++++++++++++++++++++++++ README.md | 4 + SemVer.Action.sln | 1 + 3 files changed, 206 insertions(+) create mode 100644 LICENSE.txt diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 0000000..9c8f3ea --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "{}" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright {yyyy} {name of copyright owner} + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. \ No newline at end of file diff --git a/README.md b/README.md index 37badd1..83b9f60 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,10 @@ This is a GitHub Action to allow you to use a JSON file to manage your project's Semantic Version Number. +## License + +[Apache 2.0](LICENSE.txt) + ## Contributing Please read [CONTRIBUTING.md](CONTRIBUTING.md) for details on our code of conduct, and the process for submitting pull diff --git a/SemVer.Action.sln b/SemVer.Action.sln index 668aa03..f8c2fc6 100644 --- a/SemVer.Action.sln +++ b/SemVer.Action.sln @@ -11,6 +11,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution .gitmessage = .gitmessage CONTRIBUTING.md = CONTRIBUTING.md .cm\gitstream.cm = .cm\gitstream.cm + LICENSE.txt = LICENSE.txt EndProjectSection EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SemVer.Json", "src\SemVer.Json\SemVer.Json.csproj", "{0DA1B9C2-0F3D-4BE3-99D4-628CCE9E4389}" From a03326fb2f419bea1386e2b988f06e531891ba1e Mon Sep 17 00:00:00 2001 From: Simon Baynes Date: Thu, 21 Mar 2024 13:48:35 +0000 Subject: [PATCH 08/15] Add Ci/CD pipeline Closes #15 --- .github/workflows/branch-develop.yml | 26 +++++++ .github/workflows/branch-feature.yml | 28 ++++++++ .github/workflows/branch-hotfix.yml | 58 ++++++++++++++++ .github/workflows/branch-master.yml | 44 ++++++++++++ .github/workflows/branch-release.yml | 29 ++++++++ .github/workflows/draft-new-release.yml | 67 +++++++++++++++++++ .github/workflows/step-build.yml | 46 +++++++++++++ .github/workflows/step-tag-release.yml | 20 ++++++ .github/workflows/step-version.yml | 55 +++++++++++++++ CHANGELOG.md | 9 +++ SemVer.Action.sln | 3 + build.cake | 45 +++++++++++++ semver.json | 6 ++ .../SemVer.Json.UnitTests.csproj | 5 ++ 14 files changed, 441 insertions(+) create mode 100644 .github/workflows/branch-develop.yml create mode 100644 .github/workflows/branch-feature.yml create mode 100644 .github/workflows/branch-hotfix.yml create mode 100644 .github/workflows/branch-master.yml create mode 100644 .github/workflows/branch-release.yml create mode 100644 .github/workflows/draft-new-release.yml create mode 100644 .github/workflows/step-build.yml create mode 100644 .github/workflows/step-tag-release.yml create mode 100644 .github/workflows/step-version.yml create mode 100644 CHANGELOG.md create mode 100644 build.cake create mode 100644 semver.json diff --git a/.github/workflows/branch-develop.yml b/.github/workflows/branch-develop.yml new file mode 100644 index 0000000..8e6a11e --- /dev/null +++ b/.github/workflows/branch-develop.yml @@ -0,0 +1,26 @@ +name: Deploy Develop Branch + +on: + push: + branches: + - develop + paths: + - 'src/**' + - 'test/**' + - '**.sln' + - '**.cake' + - '.github/workflows/branch-develop.yml' + - '.github/workflows/step-*.yml' + workflow_dispatch: + +jobs: + get-version: + uses: ./.github/workflows/step-version.yml + + build: + needs: [get-version] + uses: ./.github/workflows/step-build.yml + secrets: inherit + with: + version: ${{ needs.get-version.outputs.version }} + checkout-ref: ${{ github.base_ref }} diff --git a/.github/workflows/branch-feature.yml b/.github/workflows/branch-feature.yml new file mode 100644 index 0000000..3833e3a --- /dev/null +++ b/.github/workflows/branch-feature.yml @@ -0,0 +1,28 @@ +name: Deploy Feature Branch + +on: + pull_request: + types: [opened, synchronize] + branches: + - develop + paths: + - 'src/**' + - 'test/**' + - '**.sln' + - '**.cake' + - '.github/workflows/branch-feature.yml' + - '.github/workflows/step-*.yml' + workflow_dispatch: + +jobs: + get-version: + if: startsWith(github.head_ref, 'feature/') || github.head_ref == 'master' + uses: ./.github/workflows/step-version.yml + + build: + needs: [get-version] + uses: ./.github/workflows/step-build.yml + secrets: inherit + with: + version: ${{ needs.get-version.outputs.version }} + checkout-ref: ${{ github.head_ref }} \ No newline at end of file diff --git a/.github/workflows/branch-hotfix.yml b/.github/workflows/branch-hotfix.yml new file mode 100644 index 0000000..17dcee1 --- /dev/null +++ b/.github/workflows/branch-hotfix.yml @@ -0,0 +1,58 @@ +name: Deploy HotFix Branch + +on: + pull_request: + types: [opened, synchronize] + branches: + - master + workflow_dispatch: + +jobs: + get-version: + if: startsWith(github.head_ref, 'hotfix/') + uses: ./.github/workflows/step-version.yml + + build: + needs: [get-version] + uses: ./.github/workflows/step-build.yml + secrets: inherit + with: + version: ${{ needs.get-version.outputs.version }} + checkout-ref: ${{ github.head_ref }} + + update-metadata: + if: github.event.action == 'opened' + needs: [get-version] + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + ref: ${{ github.head_ref }} + - name: Increment Version + id: increment_version + run: | + echo "patch_version=$(($(cat semver.json | jq -r '.patch')+1))" > $GITHUB_OUTPUT + - name: Store New Version + uses: RadovanPelka/github-action-json@v1.0.1 + with: + path: semver.json + replaceWith: | + { + "major": "${{ needs.get-version.outputs.major }}", + "minor": "${{ needs.get-version.outputs.minor }}", + "patch": "${{ steps.increment_version.outputs.patch_version }}", + "build": "${{ github.run_number }}" + } + - name: Update changelog + uses: thomaseizinger/keep-a-changelog-new-release@2.0.0 + with: + tag: ${{ needs.get-version.outputs.major }}.${{ needs.get-version.outputs.minor }}.${{ steps.increment_version.outputs.patch_version }}.${{ github.run_number }} + - name: Commit Changes + run: | + git config --global user.name "GitHub Action Bot" + git config --global user.email "no-reply@after-life.co" + git add CHANGELOG.md semver.json + git commit --message "Bump Version to ${{ needs.get-version.outputs.major }}.${{ needs.get-version.outputs.minor }}.${{ steps.increment_version.outputs.patch_version }}.${{ github.run_number }}" + + - name: Push Version + run: git push origin ${{ github.head_ref }} \ No newline at end of file diff --git a/.github/workflows/branch-master.yml b/.github/workflows/branch-master.yml new file mode 100644 index 0000000..9233532 --- /dev/null +++ b/.github/workflows/branch-master.yml @@ -0,0 +1,44 @@ +name: Deploy Master Branch + +on: + push: + branches: + - master + workflow_dispatch: + +jobs: + get-version: + uses: ./.github/workflows/step-version.yml + with: + static-build: true + + build: + needs: [get-version] + uses: ./.github/workflows/step-build.yml + secrets: inherit + with: + version: ${{ needs.get-version.outputs.version }} + checkout-ref: ${{ github.base_ref }} + + tag-release: + needs: [get-version,build] + uses: ./.github/workflows/step-tag-release.yml + with: + version: ${{ needs.get-version.outputs.version }} + + merge-master-to-develop: + needs: [build] + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Create Pull Request + env: + GH_TOKEN: ${{ secrets.CREATE_PR_TOKEN }} + run: | + echo -e "This PR merges the master branch back into develop.\nThis happens to ensure that the updates that happend on the release branch, i.e. CHANGELOG updates are also present on the develop branch." > msg.txt + + export msg=$(cat msg.txt) ; gh pr create \ + --head master \ + --base develop \ + --title "Merge master into develop branch" \ + --body "$msg" \ No newline at end of file diff --git a/.github/workflows/branch-release.yml b/.github/workflows/branch-release.yml new file mode 100644 index 0000000..b7696f0 --- /dev/null +++ b/.github/workflows/branch-release.yml @@ -0,0 +1,29 @@ +name: Deploy Release Branch + +on: + pull_request: + types: [opened, synchronize] + branches: + - master + - develop + paths: + - 'src/**' + - 'test/**' + - '**.sln' + - '**.cake' + - '.github/workflows/branch-release.yml' + - '.github/workflows/step-*.yml' + workflow_dispatch: + +jobs: + get-version: + if: startsWith(github.head_ref, 'release/') + uses: ./.github/workflows/step-version.yml + + build: + needs: [get-version] + uses: ./.github/workflows/step-build.yml + secrets: inherit + with: + version: ${{ needs.get-version.outputs.version }} + checkout-ref: ${{ github.head_ref }} \ No newline at end of file diff --git a/.github/workflows/draft-new-release.yml b/.github/workflows/draft-new-release.yml new file mode 100644 index 0000000..0e5fc36 --- /dev/null +++ b/.github/workflows/draft-new-release.yml @@ -0,0 +1,67 @@ +name: "Draft new production release" + +on: + workflow_dispatch: + inputs: + major_version: + description: 'The major version you want to release.' + required: true + minor_version: + description: 'The minor version you want to release.' + required: true + patch_version: + description: 'The patch version you want to release.' + required: true + +jobs: + + draft-new-release: + name: "Draft a new release" + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Create release branch + run: git checkout -b release/${{ github.event.inputs.major_version }}.${{ github.event.inputs.minor_version }}.${{ github.event.inputs.patch_version }}.${{ github.run_number }} + + - name: Update Version Number + uses: RadovanPelka/github-action-json@v1.0.1 + with: + path: semver.json + replaceWith: | + { + "major": "${{ github.event.inputs.major_version }}", + "minor": "${{ github.event.inputs.minor_version }}", + "patch": "${{ github.event.inputs.patch_version }}", + "build": "${{ github.run_number }}" + } + + - name: Update changelog + uses: thomaseizinger/keep-a-changelog-new-release@2.0.0 + with: + tag: ${{ github.event.inputs.major_version }}.${{ github.event.inputs.minor_version }}.${{ github.event.inputs.patch_version }}.${{ github.run_number }} + + - name: Commit changelog and manifest files + id: make-commit + run: | + git config --global user.name "GitHub Action Bot" + git config --global user.email "no-reply@after-life.co" + git add CHANGELOG.md semver.json + git commit --message "Prepare release ${{ github.event.inputs.major_version }}.${{ github.event.inputs.minor_version }}.${{ github.event.inputs.patch_version }}.${{ github.run_number }}" + + echo "commit=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT + + - name: Push new branch + run: git push origin release/${{ github.event.inputs.major_version }}.${{ github.event.inputs.minor_version }}.${{ github.event.inputs.patch_version }}.${{ github.run_number }} + + - name: Create pull request + env: + GH_TOKEN: ${{ secrets.CREATE_PR_TOKEN }} + run: | + echo -e "Hi @${{ github.actor }}!\n\nThis PR was created in response to a manual trigger of the release workflow here: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}.\nI've updated the changelog and bumped the versions in the manifest files in this commit: ${{ steps.make-commit.outputs.commit }}.\n\nMerging this PR will create a GitHub release and upload any assets that are created as part of the release build." > msg.txt + + export msg=$(cat msg.txt) ; gh pr create \ + --head release/${{ github.event.inputs.major_version }}.${{ github.event.inputs.minor_version }}.${{ github.event.inputs.patch_version }}.${{ github.run_number }} \ + --base master \ + --title "Release version ${{ github.event.inputs.major_version }}.${{ github.event.inputs.minor_version }}.${{ github.event.inputs.patch_version }}.${{ github.run_number }}" \ + --reviewer ${{ github.actor }} \ + --body "$msg" diff --git a/.github/workflows/step-build.yml b/.github/workflows/step-build.yml new file mode 100644 index 0000000..4e974bb --- /dev/null +++ b/.github/workflows/step-build.yml @@ -0,0 +1,46 @@ +on: + workflow_call: + inputs: + version: + description: 'The version number to use for the build' + required: true + type: string + checkout-ref: + description: 'The commit SHA to checkout' + required: true + type: string + +jobs: + build-app: + runs-on: ubuntu-latest + steps: + - name: Log Branch + run: | + echo "Branch: ${{ inputs.checkout-ref }}" + - name: Checkout + uses: actions/checkout@v4 + with: + ref: ${{ inputs.checkout-ref }} + - name: Setup .NET Core + uses: actions/setup-dotnet@v4.0.0 + with: + dotnet-version: 8.0.x + - name: Restore + uses: cake-build/cake-action@v2 + with: + target: Restore + - name: Build + uses: cake-build/cake-action@v2 + with: + target: Build + arguments: | + versionNumber: ${{inputs.version}} + - name: Run tests + uses: cake-build/cake-action@v2 + with: + target: Test + - name: Publish Unit Test Results + if: ${{ github.actor != 'dependabot[bot]' }} + uses: EnricoMi/publish-unit-test-result-action/composite@v2 + with: + files: "**/TestResults/*.xml" \ No newline at end of file diff --git a/.github/workflows/step-tag-release.yml b/.github/workflows/step-tag-release.yml new file mode 100644 index 0000000..6f9b247 --- /dev/null +++ b/.github/workflows/step-tag-release.yml @@ -0,0 +1,20 @@ +on: + workflow_call: + inputs: + version: + required: true + description: 'Version to deploy' + type: string + +jobs: + tag: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Create tag + run: | + git config --global user.name "GitHub Action Bot" + git config --global user.email "no-reply@after-life.co" + git tag -a ${{ inputs.version }} -m "Version ${{ inputs.version }} created via GitHub Actions" + git push origin ${{ inputs.version }} \ No newline at end of file diff --git a/.github/workflows/step-version.yml b/.github/workflows/step-version.yml new file mode 100644 index 0000000..993f698 --- /dev/null +++ b/.github/workflows/step-version.yml @@ -0,0 +1,55 @@ +on: + workflow_call: + inputs: + static-build: + description: 'Should the build number come from the semver.json file?' + type: boolean + required: false + default: false + outputs: + version: + description: 'The version of the app' + value: ${{ jobs.version-number.outputs.version }} + major: + description: 'The major version of the app' + value: ${{ jobs.version-number.outputs.major }} + minor: + description: 'The minor version of the app' + value: ${{ jobs.version-number.outputs.minor }} + patch: + description: 'The patch version of the app' + value: ${{ jobs.version-number.outputs.patch }} + build: + description: 'The patch version of the app' + value: ${{ jobs.version-number.outputs.build }} + +jobs: + version-number: + runs-on: ubuntu-latest + outputs: + version: ${{ steps.set-version.outputs.version }} + major: ${{ steps.set-version.outputs.major }} + minor: ${{ steps.set-version.outputs.minor }} + patch: ${{ steps.set-version.outputs.patch }} + build: ${{ steps.set-version.outputs.build }} + steps: + - name: Get Code + uses: actions/checkout@v4 + - name: Get Version + id: get-version + uses: RadovanPelka/github-action-json@v1.0.1 + with: + path: 'semver.json' + - id: set-version + run: | + echo "major=${{ steps.get-version.outputs.major }}" >> $GITHUB_OUTPUT + echo "minor=${{ steps.get-version.outputs.minor }}" >> $GITHUB_OUTPUT + echo "patch=${{ steps.get-version.outputs.patch }}" >> $GITHUB_OUTPUT + + if [ "${{ inputs.static-build }}" == true ]; then + echo "version=${{ steps.get-version.outputs.major }}.${{ steps.get-version.outputs.minor }}.${{ steps.get-version.outputs.patch }}.${{ steps.get-version.outputs.build }}" >> $GITHUB_OUTPUT + echo "build=${{ steps.get-version.outputs.build }}" >> $GITHUB_OUTPUT + else + echo "version=${{ steps.get-version.outputs.major }}.${{ steps.get-version.outputs.minor }}.${{ steps.get-version.outputs.patch }}.${{ github.run_number }}" >> $GITHUB_OUTPUT + echo "build=${{ github.run_number }}" >> $GITHUB_OUTPUT + fi \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..743064c --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,9 @@ +# Changelog + +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [Unreleased] + diff --git a/SemVer.Action.sln b/SemVer.Action.sln index f8c2fc6..022878b 100644 --- a/SemVer.Action.sln +++ b/SemVer.Action.sln @@ -12,6 +12,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution CONTRIBUTING.md = CONTRIBUTING.md .cm\gitstream.cm = .cm\gitstream.cm LICENSE.txt = LICENSE.txt + build.cake = build.cake + CHANGELOG.md = CHANGELOG.md + semver.json = semver.json EndProjectSection EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SemVer.Json", "src\SemVer.Json\SemVer.Json.csproj", "{0DA1B9C2-0F3D-4BE3-99D4-628CCE9E4389}" diff --git a/build.cake b/build.cake new file mode 100644 index 0000000..3a820d5 --- /dev/null +++ b/build.cake @@ -0,0 +1,45 @@ +var target = Argument("target", "Test"); +var configuration = Argument("configuration", "Release"); +var versionNumber = Argument("versionNumber", "0.1.0"); +var solutionFolder = "./"; +var appProject = "./src/SemVer.Action/SemVer.Action.csproj"; + +Task("Clean") + .Does(() => + { + // Clean solution + DotNetClean(solutionFolder); + }); + +Task("Restore") + .Does(() => + { + // Restore NuGet packages + DotNetRestore(solutionFolder); + }); + +Task("Build") + .Does(() => + { + // Build solution + DotNetBuild(solutionFolder, new DotNetBuildSettings + { + NoRestore = true, + Configuration = configuration, + ArgumentCustomization = args => args.Append("/p:Version=" + versionNumber) + }); + }); + +Task("Test") + .Does(() => + { + // Run tests + DotNetTest(solutionFolder, new DotNetTestSettings + { + NoRestore = true, + Configuration = configuration, + Loggers = new string[] { "junit;LogFileName=results.xml" } + }); + }); + +RunTarget(target); \ No newline at end of file diff --git a/semver.json b/semver.json new file mode 100644 index 0000000..3e70dca --- /dev/null +++ b/semver.json @@ -0,0 +1,6 @@ +{ + "major": "0", + "minor": "0", + "patch": "0", + "build": "0" +} \ No newline at end of file diff --git a/test/SemVer.Json.UnitTests/SemVer.Json.UnitTests.csproj b/test/SemVer.Json.UnitTests/SemVer.Json.UnitTests.csproj index a86edbe..8e96426 100644 --- a/test/SemVer.Json.UnitTests/SemVer.Json.UnitTests.csproj +++ b/test/SemVer.Json.UnitTests/SemVer.Json.UnitTests.csproj @@ -9,10 +9,15 @@ + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + From f6268ca09f6a914a69300134fd98d5ae5c394704 Mon Sep 17 00:00:00 2001 From: Simon Baynes Date: Thu, 21 Mar 2024 13:56:25 +0000 Subject: [PATCH 09/15] Add editorconfig Closes #18 --- .editorconfig | 207 ++++++++++++++++++++++++++++++++++++++++++++++ SemVer.Action.sln | 1 + 2 files changed, 208 insertions(+) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..5411ad1 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,207 @@ +# EditorConfig is awesome: https://EditorConfig.org + +# top-most EditorConfig file +root = true + +[*] +end_of_line = lf +insert_final_newline = false +indent_style = space +indent_size = 4 +charset = utf-8 + +[*.tf] +indent_size = 2 + +[*.yml] +indent_size = 2 + +#### .NET Coding Conventions #### + +# Organize usings +dotnet_separate_import_directive_groups = false +dotnet_sort_system_directives_first = false +file_header_template = unset + +# this. and Me. preferences +dotnet_style_qualification_for_event = false:silent +dotnet_style_qualification_for_field = false:silent +dotnet_style_qualification_for_method = false:silent +dotnet_style_qualification_for_property = false:silent + +# Language keywords vs BCL types preferences +dotnet_style_predefined_type_for_locals_parameters_members = true:silent +dotnet_style_predefined_type_for_member_access = true:silent + +# Parentheses preferences +dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity:silent +dotnet_style_parentheses_in_other_binary_operators = always_for_clarity:silent +dotnet_style_parentheses_in_other_operators = never_if_unnecessary:silent +dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity:silent + +# Modifier preferences +dotnet_style_require_accessibility_modifiers = for_non_interface_members:silent + +# Expression-level preferences +dotnet_style_coalesce_expression = true:suggestion +dotnet_style_collection_initializer = true:suggestion +dotnet_style_explicit_tuple_names = true:suggestion +dotnet_style_null_propagation = true:suggestion +dotnet_style_object_initializer = true:suggestion +dotnet_style_operator_placement_when_wrapping = beginning_of_line +dotnet_style_prefer_auto_properties = true:silent +dotnet_style_prefer_compound_assignment = true:suggestion +dotnet_style_prefer_conditional_expression_over_assignment = true:silent +dotnet_style_prefer_conditional_expression_over_return = true:silent +dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion +dotnet_style_prefer_inferred_tuple_names = true:suggestion +dotnet_style_prefer_is_null_check_over_reference_equality_method = true:suggestion +dotnet_style_prefer_simplified_boolean_expressions = true:suggestion +dotnet_style_prefer_simplified_interpolation = true:suggestion + +# Field preferences +dotnet_style_readonly_field = true:suggestion + +# Parameter preferences +dotnet_code_quality_unused_parameters = all:suggestion + +# Suppression preferences +dotnet_remove_unnecessary_suppression_exclusions = none + +#### C# Coding Conventions #### + +# var preferences +csharp_style_var_elsewhere = false:silent +csharp_style_var_for_built_in_types = false:silent +csharp_style_var_when_type_is_apparent = false:silent + +# Expression-bodied members +csharp_style_expression_bodied_accessors = true:silent +csharp_style_expression_bodied_constructors = false:silent +csharp_style_expression_bodied_indexers = true:silent +csharp_style_expression_bodied_lambdas = true:silent +csharp_style_expression_bodied_local_functions = false:silent +csharp_style_expression_bodied_methods = false:silent +csharp_style_expression_bodied_operators = false:silent +csharp_style_expression_bodied_properties = true:silent + +# Pattern matching preferences +csharp_style_pattern_matching_over_as_with_null_check = true:suggestion +csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion +csharp_style_prefer_not_pattern = true:suggestion +csharp_style_prefer_pattern_matching = true:silent +csharp_style_prefer_switch_expression = true:suggestion + +# Null-checking preferences +csharp_style_conditional_delegate_call = true:suggestion + +# Modifier preferences +csharp_prefer_static_local_function = true:suggestion +csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async:silent + +# Code-block preferences +csharp_prefer_braces = true:silent +csharp_prefer_simple_using_statement = true:suggestion + +# Expression-level preferences +csharp_prefer_simple_default_expression = true:suggestion +csharp_style_deconstructed_variable_declaration = true:suggestion +csharp_style_inlined_variable_declaration = true:suggestion +csharp_style_pattern_local_over_anonymous_function = true:suggestion +csharp_style_prefer_index_operator = true:suggestion +csharp_style_prefer_range_operator = true:suggestion +csharp_style_throw_expression = true:suggestion +csharp_style_unused_value_assignment_preference = discard_variable:suggestion +csharp_style_unused_value_expression_statement_preference = discard_variable:silent + +# 'using' directive preferences +csharp_using_directive_placement = inside_namespace:silent + +#### C# Formatting Rules #### + +# New line preferences +csharp_new_line_before_catch = true +csharp_new_line_before_else = true +csharp_new_line_before_finally = true +csharp_new_line_before_members_in_anonymous_types = true +csharp_new_line_before_members_in_object_initializers = true +csharp_new_line_before_open_brace = all +csharp_new_line_between_query_expression_clauses = true + +# Indentation preferences +csharp_indent_block_contents = true +csharp_indent_braces = false +csharp_indent_case_contents = true +csharp_indent_case_contents_when_block = true +csharp_indent_labels = one_less_than_current +csharp_indent_switch_labels = true + +# Space preferences +csharp_space_after_cast = false +csharp_space_after_colon_in_inheritance_clause = true +csharp_space_after_comma = true +csharp_space_after_dot = false +csharp_space_after_keywords_in_control_flow_statements = true +csharp_space_after_semicolon_in_for_statement = true +csharp_space_around_binary_operators = before_and_after +csharp_space_around_declaration_statements = false +csharp_space_before_colon_in_inheritance_clause = true +csharp_space_before_comma = false +csharp_space_before_dot = false +csharp_space_before_open_square_brackets = false +csharp_space_before_semicolon_in_for_statement = false +csharp_space_between_empty_square_brackets = false +csharp_space_between_method_call_empty_parameter_list_parentheses = false +csharp_space_between_method_call_name_and_opening_parenthesis = false +csharp_space_between_method_call_parameter_list_parentheses = false +csharp_space_between_method_declaration_empty_parameter_list_parentheses = false +csharp_space_between_method_declaration_name_and_open_parenthesis = false +csharp_space_between_method_declaration_parameter_list_parentheses = false +csharp_space_between_parentheses = false +csharp_space_between_square_brackets = false + +# Wrapping preferences +csharp_preserve_single_line_blocks = true +csharp_preserve_single_line_statements = true + +#### Naming styles #### + +# Naming rules + +dotnet_naming_rule.interface_should_be_begins_with_i.severity = suggestion +dotnet_naming_rule.interface_should_be_begins_with_i.symbols = interface +dotnet_naming_rule.interface_should_be_begins_with_i.style = begins_with_i + +dotnet_naming_rule.types_should_be_pascal_case.severity = suggestion +dotnet_naming_rule.types_should_be_pascal_case.symbols = types +dotnet_naming_rule.types_should_be_pascal_case.style = pascal_case + +dotnet_naming_rule.non_field_members_should_be_pascal_case.severity = suggestion +dotnet_naming_rule.non_field_members_should_be_pascal_case.symbols = non_field_members +dotnet_naming_rule.non_field_members_should_be_pascal_case.style = pascal_case + +# Symbol specifications + +dotnet_naming_symbols.interface.applicable_kinds = interface +dotnet_naming_symbols.interface.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected +dotnet_naming_symbols.interface.required_modifiers = + +dotnet_naming_symbols.types.applicable_kinds = class, struct, interface, enum +dotnet_naming_symbols.types.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected +dotnet_naming_symbols.types.required_modifiers = + +dotnet_naming_symbols.non_field_members.applicable_kinds = property, event, method +dotnet_naming_symbols.non_field_members.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected +dotnet_naming_symbols.non_field_members.required_modifiers = + +# Naming styles + +dotnet_naming_style.pascal_case.required_prefix = +dotnet_naming_style.pascal_case.required_suffix = +dotnet_naming_style.pascal_case.word_separator = +dotnet_naming_style.pascal_case.capitalization = pascal_case + +dotnet_naming_style.begins_with_i.required_prefix = I +dotnet_naming_style.begins_with_i.required_suffix = +dotnet_naming_style.begins_with_i.word_separator = +dotnet_naming_style.begins_with_i.capitalization = pascal_case \ No newline at end of file diff --git a/SemVer.Action.sln b/SemVer.Action.sln index 022878b..bff1d6f 100644 --- a/SemVer.Action.sln +++ b/SemVer.Action.sln @@ -15,6 +15,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution build.cake = build.cake CHANGELOG.md = CHANGELOG.md semver.json = semver.json + .editorconfig = .editorconfig EndProjectSection EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SemVer.Json", "src\SemVer.Json\SemVer.Json.csproj", "{0DA1B9C2-0F3D-4BE3-99D4-628CCE9E4389}" From 4ebaa074115b3abb2fcabfb1d3a7b626eca6d9e3 Mon Sep 17 00:00:00 2001 From: Simon Baynes Date: Thu, 21 Mar 2024 13:58:22 +0000 Subject: [PATCH 10/15] Add dependabot configuration Closes #18 --- .github/dependabot.yml | 21 +++++++++++++++++++++ .github/workflows/test-dependabot.yml | 21 +++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 .github/dependabot.yml create mode 100644 .github/workflows/test-dependabot.yml diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..26cebfa --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,21 @@ +# To get started with Dependabot version updates, you'll need to specify which +# package ecosystems to update and where the package manifests are located. +# Please see the documentation for all configuration options: +# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates + +version: 2 +updates: + - package-ecosystem: "nuget" + directory: "/" # Location of package manifests + schedule: + interval: "daily" + labels: + - "dependencies" + open-pull-requests-limit: 10 + + - package-ecosystem: "github-actions" + directory: "/" # Location of package manifests + schedule: + interval: "daily" + labels: + - "dependencies" \ No newline at end of file diff --git a/.github/workflows/test-dependabot.yml b/.github/workflows/test-dependabot.yml new file mode 100644 index 0000000..e6d6f69 --- /dev/null +++ b/.github/workflows/test-dependabot.yml @@ -0,0 +1,21 @@ +name: Test Dependabot PRs + +on: + pull_request_target: + types: [opened, synchronize] + branches: + - develop + workflow_dispatch: + +jobs: + get-version: + if: ${{ github.actor == 'dependabot[bot]' || github.event_name == 'workflow_dispatch' }} + uses: ./.github/workflows/step-version.yml + + build: + needs: [get-version] + uses: ./.github/workflows/step-build.yml + secrets: inherit + with: + version: ${{ needs.get-version.outputs.version }} + checkout-ref: ${{ github.event.pull_request.head.sha }} \ No newline at end of file From 34b0ce2f17388134c7f9654a37057eb29de93efc Mon Sep 17 00:00:00 2001 From: Simon Baynes Date: Thu, 21 Mar 2024 14:04:46 +0000 Subject: [PATCH 11/15] Resolve deprecated unit test upload action Closes #20 --- .github/workflows/step-build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/step-build.yml b/.github/workflows/step-build.yml index 4e974bb..459c80c 100644 --- a/.github/workflows/step-build.yml +++ b/.github/workflows/step-build.yml @@ -41,6 +41,6 @@ jobs: target: Test - name: Publish Unit Test Results if: ${{ github.actor != 'dependabot[bot]' }} - uses: EnricoMi/publish-unit-test-result-action/composite@v2 + uses: EnricoMi/publish-unit-test-result-action/linux@v2 with: files: "**/TestResults/*.xml" \ No newline at end of file From 1a6b3976fd08990b43bf66a8ee74752343714d4b Mon Sep 17 00:00:00 2001 From: Simon Baynes Date: Thu, 21 Mar 2024 14:33:28 +0000 Subject: [PATCH 12/15] Enable GitHub Action for the project Closes #16 --- .dockerignore | 25 +++++++++ .github/workflows/branch-hotfix.yml | 13 ++--- .github/workflows/draft-new-release.yml | 13 ++--- .github/workflows/step-version.yml | 2 +- README.md | 46 ++++++++++++++++ SemVer.Action.sln | 3 ++ action.yml | 52 +++++++++++++++++++ src/SemVer.Json/App.cs | 4 +- src/SemVer.Json/Dockerfile | 12 +++++ .../Features/ReadJsonFile/ReadJsonCommand.cs | 2 + .../WriteJsonFile/WriteJsonCommand.cs | 17 +++--- src/SemVer.Json/Program.cs | 4 +- .../WriteJsonFile/WriteJsonCommandTests.cs | 6 ++- 13 files changed, 169 insertions(+), 30 deletions(-) create mode 100644 .dockerignore create mode 100644 action.yml create mode 100644 src/SemVer.Json/Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..cd967fc --- /dev/null +++ b/.dockerignore @@ -0,0 +1,25 @@ +**/.dockerignore +**/.env +**/.git +**/.gitignore +**/.project +**/.settings +**/.toolstarget +**/.vs +**/.vscode +**/.idea +**/*.*proj.user +**/*.dbmdl +**/*.jfm +**/azds.yaml +**/bin +**/charts +**/docker-compose* +**/Dockerfile* +**/node_modules +**/npm-debug.log +**/obj +**/secrets.dev.yaml +**/values.dev.yaml +LICENSE +README.md \ No newline at end of file diff --git a/.github/workflows/branch-hotfix.yml b/.github/workflows/branch-hotfix.yml index 17dcee1..7d95d16 100644 --- a/.github/workflows/branch-hotfix.yml +++ b/.github/workflows/branch-hotfix.yml @@ -33,16 +33,13 @@ jobs: run: | echo "patch_version=$(($(cat semver.json | jq -r '.patch')+1))" > $GITHUB_OUTPUT - name: Store New Version - uses: RadovanPelka/github-action-json@v1.0.1 + uses: Afterlife-Guide/SemVer.Action@feature/issue-16-action with: path: semver.json - replaceWith: | - { - "major": "${{ needs.get-version.outputs.major }}", - "minor": "${{ needs.get-version.outputs.minor }}", - "patch": "${{ steps.increment_version.outputs.patch_version }}", - "build": "${{ github.run_number }}" - } + major-version: ${{ needs.get-version.outputs.major }} + minor-version: ${{ needs.get-version.outputs.minor }} + patch-version: ${{ steps.increment_version.outputs.patch_version }} + build-version: ${{ github.run_number }} - name: Update changelog uses: thomaseizinger/keep-a-changelog-new-release@2.0.0 with: diff --git a/.github/workflows/draft-new-release.yml b/.github/workflows/draft-new-release.yml index 0e5fc36..49f0cab 100644 --- a/.github/workflows/draft-new-release.yml +++ b/.github/workflows/draft-new-release.yml @@ -24,16 +24,13 @@ jobs: run: git checkout -b release/${{ github.event.inputs.major_version }}.${{ github.event.inputs.minor_version }}.${{ github.event.inputs.patch_version }}.${{ github.run_number }} - name: Update Version Number - uses: RadovanPelka/github-action-json@v1.0.1 + uses: Afterlife-Guide/SemVer.Action@feature/issue-16-action with: path: semver.json - replaceWith: | - { - "major": "${{ github.event.inputs.major_version }}", - "minor": "${{ github.event.inputs.minor_version }}", - "patch": "${{ github.event.inputs.patch_version }}", - "build": "${{ github.run_number }}" - } + major-version: ${{ github.event.inputs.major_version }} + minor-version: ${{ github.event.inputs.minor_version }} + patch-version: ${{ github.event.inputs.patch_version }} + build-version: ${{ github.run_number }} - name: Update changelog uses: thomaseizinger/keep-a-changelog-new-release@2.0.0 diff --git a/.github/workflows/step-version.yml b/.github/workflows/step-version.yml index 993f698..edbf3d9 100644 --- a/.github/workflows/step-version.yml +++ b/.github/workflows/step-version.yml @@ -37,7 +37,7 @@ jobs: uses: actions/checkout@v4 - name: Get Version id: get-version - uses: RadovanPelka/github-action-json@v1.0.1 + uses: Afterlife-Guide/SemVer.Action@feature/issue-16-action with: path: 'semver.json' - id: set-version diff --git a/README.md b/README.md index 83b9f60..887963c 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,52 @@ This is a GitHub Action to allow you to use a JSON file to manage your project's Semantic Version Number. +## Usage + +To use this action, you need to create a JSON file in your repository with the following structure: + +```json +{ + "major": 0, + "minor": 1, + "patch": 0, + "build": 0 +} +``` +### Reading the version number + +Then you can use this action in your workflow to read this file.: + +```yaml + - name: Read Version + uses: Afterlife-Guide/SemVer.Action@0.1.0 + with: + path: 'version.json' +``` + +It will create the following outputs: + +- `major`: The major version number. +- `minor`: The minor version number. +- `patch`: The patch version number. +- `build`: The build version number. +- `version`: The full version number. + +### Writing the version number + +You can also use this action to write the version number back to the file.: + +```yaml + - name: Write Version + uses: Afterlife-Guide/SemVer.Action@0.1.0 + with: + path: 'version.json' + major: 0 + minor: 1 + patch: 1 + build: 0 +``` + ## License [Apache 2.0](LICENSE.txt) diff --git a/SemVer.Action.sln b/SemVer.Action.sln index bff1d6f..4f8110f 100644 --- a/SemVer.Action.sln +++ b/SemVer.Action.sln @@ -16,6 +16,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution CHANGELOG.md = CHANGELOG.md semver.json = semver.json .editorconfig = .editorconfig + .dockerignore = .dockerignore + src\SemVer.Json\Dockerfile = src\SemVer.Json\Dockerfile + action.yml = action.yml EndProjectSection EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SemVer.Json", "src\SemVer.Json\SemVer.Json.csproj", "{0DA1B9C2-0F3D-4BE3-99D4-628CCE9E4389}" diff --git a/action.yml b/action.yml new file mode 100644 index 0000000..b0fabf6 --- /dev/null +++ b/action.yml @@ -0,0 +1,52 @@ +name: 'SemVer Action' +description: 'A GitHub Action for using a JSON file as the persistence for your Semantic Version number for your repository' +inputs: + path: + description: 'The path to the semver JSON file' + required: false + default: 'semver.json' + major-version: + description: 'The major version number' + required: false + default: '0' + minor-version: + description: 'The minor version number' + required: false + default: '0' + patch-version: + description: 'The patch version number' + required: false + default: '0' + build-version: + description: 'The build version number' + required: false + default: '0' +outputs: + major: + description: 'The major version number' + minor: + description: 'The minor version number' + patch: + description: 'The patch version number' + build: + description: 'The build version number' + version: + description: 'The full version number' +runs: + using: 'docker' + image: 'src/SemVer.Json/Dockerfile' + args: + - ${{ (inputs.major-version == '0' && inputs.minor-version == '0' && inputs.patch-version == '0' && inputs.build-version == '0') && 'read' || 'write' }} + - '-p' + - '/github/workspace/${{ inputs.path }}' + - ${{ !(inputs.major-version == '0' && inputs.minor-version == '0' && inputs.patch-version == '0' && inputs.build-version == '0') && '-m' || '' }} + - ${{ !(inputs.major-version == '0' && inputs.minor-version == '0' && inputs.patch-version == '0' && inputs.build-version == '0') && inputs.major-version || '' }} + - ${{ !(inputs.major-version == '0' && inputs.minor-version == '0' && inputs.patch-version == '0' && inputs.build-version == '0') && '-n' || '' }} + - ${{ !(inputs.major-version == '0' && inputs.minor-version == '0' && inputs.patch-version == '0' && inputs.build-version == '0') && inputs.minor-version || '' }} + - ${{ !(inputs.major-version == '0' && inputs.minor-version == '0' && inputs.patch-version == '0' && inputs.build-version == '0') && '-h' || '' }} + - ${{ !(inputs.major-version == '0' && inputs.minor-version == '0' && inputs.patch-version == '0' && inputs.build-version == '0') && inputs.patch-version || '' }} + - ${{ !(inputs.major-version == '0' && inputs.minor-version == '0' && inputs.patch-version == '0' && inputs.build-version == '0') && '-b' || '' }} + - ${{ !(inputs.major-version == '0' && inputs.minor-version == '0' && inputs.patch-version == '0' && inputs.build-version == '0') && inputs.build-version || '' }} +branding: + icon: 'grid' + color: 'green' diff --git a/src/SemVer.Json/App.cs b/src/SemVer.Json/App.cs index e643265..c741517 100644 --- a/src/SemVer.Json/App.cs +++ b/src/SemVer.Json/App.cs @@ -16,9 +16,9 @@ public App(IConfiguration configuration, ReadJsonCommand readJsonCommand, WriteJ _writeJsonCommand = writeJsonCommand; } - public void Run(IEnumerable args) + public int Run(IEnumerable args) { - Parser.Default.ParseArguments(args) + return Parser.Default.ParseArguments(args) .MapResult( (ReadJsonOptions opts) => _readJsonCommand.Read(opts), (WriteJsonOptions opts) => _writeJsonCommand.Write(opts), diff --git a/src/SemVer.Json/Dockerfile b/src/SemVer.Json/Dockerfile new file mode 100644 index 0000000..8f5941d --- /dev/null +++ b/src/SemVer.Json/Dockerfile @@ -0,0 +1,12 @@ +# Set the base image as the .NET 7.0 SDK (this includes the runtime) +FROM mcr.microsoft.com/dotnet/sdk:8.0 as build-env + +# Copy everything and publish the release (publish implicitly restores and builds) +WORKDIR /app +COPY . ./ +RUN dotnet publish ./SemVer.Json.csproj -c Release -o out --no-self-contained + +# Relayer the .NET SDK, anew with the build output +FROM mcr.microsoft.com/dotnet/sdk:8.0 +COPY --from=build-env /app/out . +ENTRYPOINT [ "dotnet", "/SemVer.Json.dll" ] \ No newline at end of file diff --git a/src/SemVer.Json/Features/ReadJsonFile/ReadJsonCommand.cs b/src/SemVer.Json/Features/ReadJsonFile/ReadJsonCommand.cs index 0cff36c..8374239 100644 --- a/src/SemVer.Json/Features/ReadJsonFile/ReadJsonCommand.cs +++ b/src/SemVer.Json/Features/ReadJsonFile/ReadJsonCommand.cs @@ -17,6 +17,8 @@ public int Read(ReadJsonOptions opts) try { json = File.ReadAllText(opts.Path); + logger.LogInformation("Read JSON file: {Path}", opts.Path); + logger.LogInformation("JSON content: {Json}", json); } catch (FileNotFoundException ex) { diff --git a/src/SemVer.Json/Features/WriteJsonFile/WriteJsonCommand.cs b/src/SemVer.Json/Features/WriteJsonFile/WriteJsonCommand.cs index a80de77..d83f121 100644 --- a/src/SemVer.Json/Features/WriteJsonFile/WriteJsonCommand.cs +++ b/src/SemVer.Json/Features/WriteJsonFile/WriteJsonCommand.cs @@ -1,23 +1,20 @@ using System.Text.Json; +using Microsoft.Extensions.Logging; using SemVer.Json.Persistence; namespace SemVer.Json.Features.WriteJsonFile; -public class WriteJsonCommand +public class WriteJsonCommand(IFileWriter fileWriter, ILogger logger) { - private readonly IFileWriter _fileWriter; private readonly JsonSerializerOptions _jsonSerializerOptions = new() { PropertyNamingPolicy = JsonNamingPolicy.CamelCase }; - public WriteJsonCommand(IFileWriter fileWriter) - { - _fileWriter = fileWriter; - } - public int Write(WriteJsonOptions options) { + logger.LogInformation("Version Number to write: {Major}.{Minor}.{Patch}.{Build}", options.Major, options.Minor, options.Patch, options.Build); + var semVer = new SemVer { Major = options.Major, @@ -26,7 +23,11 @@ public int Write(WriteJsonOptions options) Build = options.Build }; var json = JsonSerializer.Serialize(semVer, _jsonSerializerOptions); - _fileWriter.WriteJson(json, options.Path); + + logger.LogInformation("Json to write: {Json}", json); + logger.LogInformation("Writing to file: {Path}", options.Path); + + fileWriter.WriteJson(json, options.Path); return 0; } diff --git a/src/SemVer.Json/Program.cs b/src/SemVer.Json/Program.cs index 677bcf4..3b39035 100644 --- a/src/SemVer.Json/Program.cs +++ b/src/SemVer.Json/Program.cs @@ -12,11 +12,13 @@ var services = scope.ServiceProvider; try { - services.GetRequiredService().Run(args); + var exit = services.GetRequiredService().Run(args); + Environment.Exit(exit); } catch (Exception e) { Console.WriteLine(e.Message); + Environment.Exit(1); } return; diff --git a/test/SemVer.Json.UnitTests/Features/WriteJsonFile/WriteJsonCommandTests.cs b/test/SemVer.Json.UnitTests/Features/WriteJsonFile/WriteJsonCommandTests.cs index c61b92e..5b09f97 100644 --- a/test/SemVer.Json.UnitTests/Features/WriteJsonFile/WriteJsonCommandTests.cs +++ b/test/SemVer.Json.UnitTests/Features/WriteJsonFile/WriteJsonCommandTests.cs @@ -1,4 +1,5 @@ -using SemVer.Json.Features.WriteJsonFile; +using Microsoft.Extensions.Logging; +using SemVer.Json.Features.WriteJsonFile; using SemVer.Json.Persistence; namespace SemVer.Json.UnitTests.Features.WriteJsonFile; @@ -6,11 +7,12 @@ namespace SemVer.Json.UnitTests.Features.WriteJsonFile; public class WriteJsonCommandTests { private readonly IFileWriter _mockFileWriter = Substitute.For(); + private readonly ILogger _mockLogger = Substitute.For>(); private readonly WriteJsonCommand _sut; public WriteJsonCommandTests() { - _sut = new WriteJsonCommand(_mockFileWriter); + _sut = new WriteJsonCommand(_mockFileWriter, _mockLogger); } [Fact] From 0104504b2e751cec845d34f5540b0fb7cfff0d6d Mon Sep 17 00:00:00 2001 From: Simon Baynes Date: Fri, 22 Mar 2024 07:27:07 +0000 Subject: [PATCH 13/15] Move dogfooding to develop Closes #25 --- .github/workflows/branch-hotfix.yml | 2 +- .github/workflows/draft-new-release.yml | 2 +- .github/workflows/step-version.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/branch-hotfix.yml b/.github/workflows/branch-hotfix.yml index 7d95d16..89e01fe 100644 --- a/.github/workflows/branch-hotfix.yml +++ b/.github/workflows/branch-hotfix.yml @@ -33,7 +33,7 @@ jobs: run: | echo "patch_version=$(($(cat semver.json | jq -r '.patch')+1))" > $GITHUB_OUTPUT - name: Store New Version - uses: Afterlife-Guide/SemVer.Action@feature/issue-16-action + uses: Afterlife-Guide/SemVer.Action@develop with: path: semver.json major-version: ${{ needs.get-version.outputs.major }} diff --git a/.github/workflows/draft-new-release.yml b/.github/workflows/draft-new-release.yml index 49f0cab..524b596 100644 --- a/.github/workflows/draft-new-release.yml +++ b/.github/workflows/draft-new-release.yml @@ -24,7 +24,7 @@ jobs: run: git checkout -b release/${{ github.event.inputs.major_version }}.${{ github.event.inputs.minor_version }}.${{ github.event.inputs.patch_version }}.${{ github.run_number }} - name: Update Version Number - uses: Afterlife-Guide/SemVer.Action@feature/issue-16-action + uses: Afterlife-Guide/SemVer.Action@develop with: path: semver.json major-version: ${{ github.event.inputs.major_version }} diff --git a/.github/workflows/step-version.yml b/.github/workflows/step-version.yml index edbf3d9..3435251 100644 --- a/.github/workflows/step-version.yml +++ b/.github/workflows/step-version.yml @@ -37,7 +37,7 @@ jobs: uses: actions/checkout@v4 - name: Get Version id: get-version - uses: Afterlife-Guide/SemVer.Action@feature/issue-16-action + uses: Afterlife-Guide/SemVer.Action@develop with: path: 'semver.json' - id: set-version From 7ed6547ee9bf8d531acb345c1298c1c928604c2a Mon Sep 17 00:00:00 2001 From: Simon Baynes Date: Fri, 22 Mar 2024 07:30:18 +0000 Subject: [PATCH 14/15] Add blocked issue workflow Closes #27 --- .github/workflows/blocked-issue.yml | 36 +++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 .github/workflows/blocked-issue.yml diff --git a/.github/workflows/blocked-issue.yml b/.github/workflows/blocked-issue.yml new file mode 100644 index 0000000..aa565ce --- /dev/null +++ b/.github/workflows/blocked-issue.yml @@ -0,0 +1,36 @@ +name: Blocked Issue Labeler + +on: + issues: + types: + - opened + - edited + issue_comment: + types: + - created + - edited + +jobs: + add-blocked-label: + runs-on: ubuntu-latest + steps: + - name: Checkout repo + uses: actions/checkout@v4 + - name: Add blocked label if issue is blocked + run: | + body=$BODY + comment=$COMMENT + issue_number=${{ github.event.issue.number }} + + # if body contains "blocked" or comment contains "blocked" + # add label "blocked" + + if [[ "${body,,}" == *"blocked"* ]] || [[ "${comment,,}" == *"blocked"* ]]; then + echo "Issue is blocked" + echo "Adding blocked label" + gh issue edit $issue_number --add-label blocked + fi + env: + BODY: ${{ github.event.issue.body }} + COMMENT: ${{ github.event.comment.body }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file From f9ea77386c01b3a60543a12fe6bc234d4c40d566 Mon Sep 17 00:00:00 2001 From: GitHub Action Bot Date: Fri, 22 Mar 2024 07:33:17 +0000 Subject: [PATCH 15/15] Prepare release 0.1.0.1 --- CHANGELOG.md | 5 +++++ semver.json | 7 +------ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 743064c..af440be 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,3 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [0.1.0.1] - 2024-03-22 + +[Unreleased]: https://github.com/Afterlife-Guide/SemVer.Action/compare/0.1.0.1...HEAD + +[0.1.0.1]: https://github.com/Afterlife-Guide/SemVer.Action/compare/4504613496b5d76d18531a4c41b3b88d241c41c2...0.1.0.1 diff --git a/semver.json b/semver.json index 3e70dca..d04f3c9 100644 --- a/semver.json +++ b/semver.json @@ -1,6 +1 @@ -{ - "major": "0", - "minor": "0", - "patch": "0", - "build": "0" -} \ No newline at end of file +{"major":"0","minor":"1","patch":"0","build":"1"} \ No newline at end of file