From 0d43814da49345fc88f4403c0ab518eac1b8d7f8 Mon Sep 17 00:00:00 2001 From: Christo du Toit Date: Sat, 17 Feb 2024 17:59:29 +0000 Subject: [PATCH] INFRA: Initial chesk-in --- .editorconfig | 14 ++ .github/workflows/build.yml | 145 ++++++++++++++++++ LICENSE => License.txt | 0 STX.SPAL.Core.Infrastructure.Build/Program.cs | 17 ++ .../STX.SPAL.Core.Infrastructure.Build.csproj | 15 ++ .../Services/ScriptGenerationService.cs | 123 +++++++++++++++ STX.SPAL.Core.sln | 25 +++ .../STX.SPAL.Core.Tests.Acceptance.csproj | 28 ++++ .../STX.SPAL.Core.Tests.Unit.csproj | 28 ++++ STX.SPAL.Core/STX.SPAL.Core.sln | 43 ++++++ .../STX.SPAL.Core/STX.SPAL.Core.csproj | 9 ++ 11 files changed, 447 insertions(+) create mode 100644 .editorconfig create mode 100644 .github/workflows/build.yml rename LICENSE => License.txt (100%) create mode 100644 STX.SPAL.Core.Infrastructure.Build/Program.cs create mode 100644 STX.SPAL.Core.Infrastructure.Build/STX.SPAL.Core.Infrastructure.Build.csproj create mode 100644 STX.SPAL.Core.Infrastructure.Build/Services/ScriptGenerationService.cs create mode 100644 STX.SPAL.Core.sln create mode 100644 STX.SPAL.Core/STX.SPAL.Core.Tests.Acceptance/STX.SPAL.Core.Tests.Acceptance.csproj create mode 100644 STX.SPAL.Core/STX.SPAL.Core.Tests.Unit/STX.SPAL.Core.Tests.Unit.csproj create mode 100644 STX.SPAL.Core/STX.SPAL.Core.sln create mode 100644 STX.SPAL.Core/STX.SPAL.Core/STX.SPAL.Core.csproj diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..b63edb8 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,14 @@ +# Remove the line below if you want to inherit .editorconfig settings from higher directories + +# C# or VB files +[*.{cs,vb,ts,tsx}] +guidelines = 120 + +#### Core EditorConfig Options #### + +#Formatting - header template +file_header_template = ----------------------------------------------------------------------------------\nCopyright (c) The Standard Organization: A coalition of the Good-Hearted Engineers\n---------------------------------------------------------------------------------- + +#sort System.* using directives alphabetically, and place them before other usings +dotnet_sort_system_directives_first = true + diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..47332f3 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,145 @@ +name: Build +on: + push: + branches: + - main + pull_request: + types: + - opened + - synchronize + - reopened + - closed + branches: + - main +env: + IS_RELEASE_CANDIDATE: >- + ${{ + ( + github.event_name == 'pull_request' && + startsWith(github.event.pull_request.title, 'RELEASES:') && + contains(github.event.pull_request.labels.*.name, 'RELEASES') + ) + || + ( + github.event_name == 'push' && + startsWith(github.event.head_commit.message, 'RELEASES:') && + startsWith(github.ref_name, 'RELEASE') + ) + }} +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Check out + uses: actions/checkout@v3 + - name: Setup .Net + uses: actions/setup-dotnet@v3 + with: + dotnet-version: 7.0.201 + - name: Restore + run: dotnet restore + - name: Build + run: dotnet build --no-restore + - name: Test + run: dotnet test --no-build --verbosity normal + add_tag: + runs-on: ubuntu-latest + needs: + - build + if: >- + needs.build.result == 'success' && + + github.event.pull_request.merged && + + github.event.pull_request.base.ref == 'main' && + + startsWith(github.event.pull_request.title, 'RELEASES:') && + + contains(github.event.pull_request.labels.*.name, 'RELEASES') + steps: + - name: Checkout code + uses: actions/checkout@v3 + with: + token: ${{ secrets.PAT_FOR_TAGGING }} + - name: Configure Git + run: >- + git config user.name "GitHub Action" + + git config user.email "action@github.com" + - name: Extract Version + id: extract_version + run: > + # Running on Linux/Unix + + sudo apt-get install xmlstarlet + + version_number=$(xmlstarlet sel -t -v "//Version" -n STX.SPAL.Core/STX.SPAL.Core.csproj) + + echo "$version_number" + + echo "version_number<> $GITHUB_OUTPUT + + echo "$version_number" >> $GITHUB_OUTPUT + + echo "EOF" >> $GITHUB_OUTPUT + shell: bash + - name: Display Version + run: 'echo "Version number: ${{ steps.extract_version.outputs.version_number }}"' + - name: Extract Package Release Notes + id: extract_package_release_notes + run: > + # Running on Linux/Unix + + sudo apt-get install xmlstarlet + + package_release_notes=$(xmlstarlet sel -t -v "//PackageReleaseNotes" -n STX.SPAL.Core/STX.SPAL.Core.csproj) + + echo "$package_release_notes" + + echo "package_release_notes<> $GITHUB_OUTPUT + + echo "$package_release_notes" >> $GITHUB_OUTPUT + + echo "EOF" >> $GITHUB_OUTPUT + shell: bash + - name: Display Package Release Notes + run: 'echo "Package Release Notes: ${{ steps.extract_package_release_notes.outputs.package_release_notes }}"' + - name: Create GitHub Tag + run: >- + git tag -a "v${{ steps.extract_version.outputs.version_number }}" -m "Release - v${{ steps.extract_version.outputs.version_number }}" + + git push origin --tags + - name: Create GitHub Release + uses: actions/create-release@v1 + with: + tag_name: v${{ steps.extract_version.outputs.version_number }} + release_name: Release - v${{ steps.extract_version.outputs.version_number }} + body: >- + ## Release - v${{ steps.extract_version.outputs.version_number }} + + + ### Release Notes + + ${{ steps.extract_package_release_notes.outputs.package_release_notes }} + env: + GITHUB_TOKEN: ${{ secrets.PAT_FOR_TAGGING }} + publish: + runs-on: ubuntu-latest + needs: + - add_tag + if: needs.add_tag.result == 'success' + steps: + - name: Check out + uses: actions/checkout@v3 + - name: Setup .Net + uses: actions/setup-dotnet@v3 + with: + dotnet-version: 7.0.201 + - name: Restore + run: dotnet restore + - name: Build + run: dotnet build --no-restore --configuration Release + - name: Pack NuGet Package + run: dotnet pack --configuration Release --include-symbols + - name: Push NuGet Package + run: dotnet nuget push **/bin/Release/**/*.nupkg --source https://api.nuget.org/v3/index.json --api-key ${{ secrets.NUGET_ACCESS }} --skip-duplicate diff --git a/LICENSE b/License.txt similarity index 100% rename from LICENSE rename to License.txt diff --git a/STX.SPAL.Core.Infrastructure.Build/Program.cs b/STX.SPAL.Core.Infrastructure.Build/Program.cs new file mode 100644 index 0000000..c681ceb --- /dev/null +++ b/STX.SPAL.Core.Infrastructure.Build/Program.cs @@ -0,0 +1,17 @@ +// ---------------------------------------------------------------------------------- +// Copyright (c) The Standard Organization: A coalition of the Good-Hearted Engineers +// ---------------------------------------------------------------------------------- + +using STX.SPAL.Core.Infrastructure.Build.Services; + +namespace STX.SPAL.Core.Infrastructure.Build +{ + internal class Program + { + static void Main(string[] args) + { + var scriptGenerationService = new ScriptGenerationService(); + scriptGenerationService.GenerateBuildScript(); + } + } +} diff --git a/STX.SPAL.Core.Infrastructure.Build/STX.SPAL.Core.Infrastructure.Build.csproj b/STX.SPAL.Core.Infrastructure.Build/STX.SPAL.Core.Infrastructure.Build.csproj new file mode 100644 index 0000000..902c8eb --- /dev/null +++ b/STX.SPAL.Core.Infrastructure.Build/STX.SPAL.Core.Infrastructure.Build.csproj @@ -0,0 +1,15 @@ + + + + Exe + net8.0 + disable + enable + false + + + + + + + diff --git a/STX.SPAL.Core.Infrastructure.Build/Services/ScriptGenerationService.cs b/STX.SPAL.Core.Infrastructure.Build/Services/ScriptGenerationService.cs new file mode 100644 index 0000000..e5ffe48 --- /dev/null +++ b/STX.SPAL.Core.Infrastructure.Build/Services/ScriptGenerationService.cs @@ -0,0 +1,123 @@ +// ---------------------------------------------------------------------------------- +// Copyright (c) The Standard Organization: A coalition of the Good-Hearted Engineers +// ---------------------------------------------------------------------------------- + +using System.Collections.Generic; +using System.IO; +using ADotNet.Clients; +using ADotNet.Models.Pipelines.GithubPipelines.DotNets; +using ADotNet.Models.Pipelines.GithubPipelines.DotNets.Tasks; +using ADotNet.Models.Pipelines.GithubPipelines.DotNets.Tasks.SetupDotNetTaskV3s; + +namespace STX.SPAL.Core.Infrastructure.Build.Services +{ + internal class ScriptGenerationService + { + private readonly ADotNetClient adotNetClient; + + public ScriptGenerationService() => + adotNetClient = new ADotNetClient(); + + public void GenerateBuildScript() + { + string branchName = "main"; + + var githubPipeline = new GithubPipeline + { + Name = "Build", + + OnEvents = new Events + { + Push = new PushEvent + { + Branches = new string[] { branchName } + }, + + PullRequest = new PullRequestEvent + { + Types = new string[] { "opened", "synchronize", "reopened", "closed" }, + Branches = new string[] { branchName } + } + }, + + EnvironmentVariables = new Dictionary + { + { "IS_RELEASE_CANDIDATE", EnvironmentVariables.IsGitHubReleaseCandidate() } + }, + + Jobs = new Dictionary + { + { + "build", + new Job + { + RunsOn = BuildMachines.UbuntuLatest, + + Steps = new List + { + new CheckoutTaskV3 + { + Name = "Check out" + }, + + new SetupDotNetTaskV3 + { + Name = "Setup .Net", + + With = new TargetDotNetVersionV3 + { + DotNetVersion = "7.0.201" + } + }, + + new RestoreTask + { + Name = "Restore" + }, + + new DotNetBuildTask + { + Name = "Build" + }, + + new TestTask + { + Name = "Test" + } + } + } + }, + { + "add_tag", + new TagJob( + runsOn: BuildMachines.UbuntuLatest, + dependsOn: "build", + projectRelativePath: "STX.SPAL.Core/" + + "STX.SPAL.Core.csproj", + githubToken: "${{ secrets.PAT_FOR_TAGGING }}", + branchName: branchName) + }, + { + "publish", + new PublishJob( + runsOn: BuildMachines.UbuntuLatest, + dependsOn: "add_tag", + nugetApiKey: "${{ secrets.NUGET_ACCESS }}") + } + } + }; + + string buildScriptPath = "../../../../.github/workflows/build.yml"; + string directoryPath = Path.GetDirectoryName(buildScriptPath); + + if (!Directory.Exists(directoryPath)) + { + Directory.CreateDirectory(directoryPath); + } + + adotNetClient.SerializeAndWriteToFile( + adoPipeline: githubPipeline, + path: buildScriptPath); + } + } +} diff --git a/STX.SPAL.Core.sln b/STX.SPAL.Core.sln new file mode 100644 index 0000000..9ad26cc --- /dev/null +++ b/STX.SPAL.Core.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.9.34607.119 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "STX.SPAL.Abstractions.Infrastructure.Build", "STX.SPAL.Abstractions.Infrastructure.Build\STX.SPAL.Abstractions.Infrastructure.Build.csproj", "{2D431C20-BE0E-4C25-9C89-3111EFE3737E}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {2D431C20-BE0E-4C25-9C89-3111EFE3737E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2D431C20-BE0E-4C25-9C89-3111EFE3737E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2D431C20-BE0E-4C25-9C89-3111EFE3737E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2D431C20-BE0E-4C25-9C89-3111EFE3737E}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {6D7B900D-5E0A-4553-8E9C-E6AA90E02CC2} + EndGlobalSection +EndGlobal diff --git a/STX.SPAL.Core/STX.SPAL.Core.Tests.Acceptance/STX.SPAL.Core.Tests.Acceptance.csproj b/STX.SPAL.Core/STX.SPAL.Core.Tests.Acceptance/STX.SPAL.Core.Tests.Acceptance.csproj new file mode 100644 index 0000000..8dc40ee --- /dev/null +++ b/STX.SPAL.Core/STX.SPAL.Core.Tests.Acceptance/STX.SPAL.Core.Tests.Acceptance.csproj @@ -0,0 +1,28 @@ + + + + net8.0 + disable + disable + false + true + + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + + + + + + diff --git a/STX.SPAL.Core/STX.SPAL.Core.Tests.Unit/STX.SPAL.Core.Tests.Unit.csproj b/STX.SPAL.Core/STX.SPAL.Core.Tests.Unit/STX.SPAL.Core.Tests.Unit.csproj new file mode 100644 index 0000000..8dc40ee --- /dev/null +++ b/STX.SPAL.Core/STX.SPAL.Core.Tests.Unit/STX.SPAL.Core.Tests.Unit.csproj @@ -0,0 +1,28 @@ + + + + net8.0 + disable + disable + false + true + + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + + + + + + diff --git a/STX.SPAL.Core/STX.SPAL.Core.sln b/STX.SPAL.Core/STX.SPAL.Core.sln new file mode 100644 index 0000000..7f9d4a4 --- /dev/null +++ b/STX.SPAL.Core/STX.SPAL.Core.sln @@ -0,0 +1,43 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.9.34607.119 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "STX.SPAL.Core", "STX.SPAL.Core\STX.SPAL.Core.csproj", "{E0E396BF-C201-493B-B6AA-E6D96A4EABA8}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "STX.SPAL.Core.Infrastructure.Build", "..\STX.SPAL.Core.Infrastructure.Build\STX.SPAL.Core.Infrastructure.Build.csproj", "{668B03BC-0C15-424C-BA35-F7ED0C16BEFC}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "STX.SPAL.Core.Tests.Unit", "STX.SPAL.Core.Tests.Unit\STX.SPAL.Core.Tests.Unit.csproj", "{6DDD05F4-4126-41AA-9DF8-8CC1C487914B}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "STX.SPAL.Core.Tests.Acceptance", "STX.SPAL.Core.Tests.Acceptance\STX.SPAL.Core.Tests.Acceptance.csproj", "{666059CF-F406-40E5-98C3-1CFA4F4682F9}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {E0E396BF-C201-493B-B6AA-E6D96A4EABA8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E0E396BF-C201-493B-B6AA-E6D96A4EABA8}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E0E396BF-C201-493B-B6AA-E6D96A4EABA8}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E0E396BF-C201-493B-B6AA-E6D96A4EABA8}.Release|Any CPU.Build.0 = Release|Any CPU + {668B03BC-0C15-424C-BA35-F7ED0C16BEFC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {668B03BC-0C15-424C-BA35-F7ED0C16BEFC}.Debug|Any CPU.Build.0 = Debug|Any CPU + {668B03BC-0C15-424C-BA35-F7ED0C16BEFC}.Release|Any CPU.ActiveCfg = Release|Any CPU + {668B03BC-0C15-424C-BA35-F7ED0C16BEFC}.Release|Any CPU.Build.0 = Release|Any CPU + {6DDD05F4-4126-41AA-9DF8-8CC1C487914B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6DDD05F4-4126-41AA-9DF8-8CC1C487914B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6DDD05F4-4126-41AA-9DF8-8CC1C487914B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6DDD05F4-4126-41AA-9DF8-8CC1C487914B}.Release|Any CPU.Build.0 = Release|Any CPU + {666059CF-F406-40E5-98C3-1CFA4F4682F9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {666059CF-F406-40E5-98C3-1CFA4F4682F9}.Debug|Any CPU.Build.0 = Debug|Any CPU + {666059CF-F406-40E5-98C3-1CFA4F4682F9}.Release|Any CPU.ActiveCfg = Release|Any CPU + {666059CF-F406-40E5-98C3-1CFA4F4682F9}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {DD4FD8ED-6B49-4F8F-98BF-8EE70838E59A} + EndGlobalSection +EndGlobal diff --git a/STX.SPAL.Core/STX.SPAL.Core/STX.SPAL.Core.csproj b/STX.SPAL.Core/STX.SPAL.Core/STX.SPAL.Core.csproj new file mode 100644 index 0000000..3a2ca8f --- /dev/null +++ b/STX.SPAL.Core/STX.SPAL.Core/STX.SPAL.Core.csproj @@ -0,0 +1,9 @@ + + + + net8.0 + disable + disable + + +