From 046b2096f8c2d38ae54969278c0f7726d1556b9e Mon Sep 17 00:00:00 2001 From: Ricardo Cruz Date: Sun, 28 Jul 2024 16:32:50 -0400 Subject: [PATCH] INFRA: Initialize Build Project --- .github/workflows/build.yml | 107 ++++++++++++++++++ .../Program.cs | 17 +++ ...ons.PostgreSQL.Infrastructure.Build.csproj | 19 ++++ .../Services/ScriptGenerationService.cs | 107 ++++++++++++++++++ STX.EFxceptions.PostgreSQL.sln | 6 +- 5 files changed, 255 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/build.yml create mode 100644 STX.EFxceptions.PostgreSQL.Infrastructure.Build/Program.cs create mode 100644 STX.EFxceptions.PostgreSQL.Infrastructure.Build/STX.EFxceptions.PostgreSQL.Infrastructure.Build.csproj create mode 100644 STX.EFxceptions.PostgreSQL.Infrastructure.Build/Services/ScriptGenerationService.cs diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..3c3bcc8 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,107 @@ +name: Build +on: + push: + branches: + - main + pull_request: + branches: + - main +jobs: + build: + name: Build + runs-on: windows-latest + steps: + - name: Check out + uses: actions/checkout@v3 + - name: Setup .Net + uses: actions/setup-dotnet@v3 + with: + dotnet-version: 8.0.302 + - name: Restore + run: dotnet restore + - name: Build + run: dotnet build --no-restore + - name: Test + run: dotnet test --no-build --verbosity normal + add_tag: + name: Tag and Release + 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.EFxceptions.PostgreSQL/STX.EFxceptions.PostgreSQL.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.EFxceptions.PostgreSQL/STX.EFxceptions.PostgreSQL.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 }} diff --git a/STX.EFxceptions.PostgreSQL.Infrastructure.Build/Program.cs b/STX.EFxceptions.PostgreSQL.Infrastructure.Build/Program.cs new file mode 100644 index 0000000..1b5a194 --- /dev/null +++ b/STX.EFxceptions.PostgreSQL.Infrastructure.Build/Program.cs @@ -0,0 +1,17 @@ +// ---------------------------------------------------------------------------------- +// Copyright(c) The Standard Organization: A coalition of the Good-Hearted Engineers +// ---------------------------------------------------------------------------------- + +using STX.EFxceptions.PostgreSQL.Infrastructure.Build.Services; + +namespace STX.EFxceptions.PostgreSQL.Infrastructure.Build +{ + internal class Program + { + static void Main(string[] args) + { + var scriptGenerationService = new ScriptGenerationService(); + scriptGenerationService.GenerateBuildScript(); + } + } +} diff --git a/STX.EFxceptions.PostgreSQL.Infrastructure.Build/STX.EFxceptions.PostgreSQL.Infrastructure.Build.csproj b/STX.EFxceptions.PostgreSQL.Infrastructure.Build/STX.EFxceptions.PostgreSQL.Infrastructure.Build.csproj new file mode 100644 index 0000000..becef5f --- /dev/null +++ b/STX.EFxceptions.PostgreSQL.Infrastructure.Build/STX.EFxceptions.PostgreSQL.Infrastructure.Build.csproj @@ -0,0 +1,19 @@ + + + + Exe + net8.0 + disable + disable + false + + + + + + + + + + + diff --git a/STX.EFxceptions.PostgreSQL.Infrastructure.Build/Services/ScriptGenerationService.cs b/STX.EFxceptions.PostgreSQL.Infrastructure.Build/Services/ScriptGenerationService.cs new file mode 100644 index 0000000..e84cf01 --- /dev/null +++ b/STX.EFxceptions.PostgreSQL.Infrastructure.Build/Services/ScriptGenerationService.cs @@ -0,0 +1,107 @@ +// ---------------------------------------------------------------------------------- +// 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.EFxceptions.PostgreSQL.Infrastructure.Build.Services +{ + internal class ScriptGenerationService + { + private readonly ADotNetClient adotNetClient; + + public ScriptGenerationService() => + this.adotNetClient = new ADotNetClient(); + + public void GenerateBuildScript() + { + string branchName = "main"; + string projectName = "STX.EFxceptions.PostgreSQL"; + + var githubPipeline = new GithubPipeline + { + Name = "Build", + + OnEvents = new Events + { + Push = new PushEvent { Branches = [branchName] }, + PullRequest = new PullRequestEvent { Branches = [branchName] } + }, + + Jobs = new Dictionary + { + { + "build", + new Job + { + Name = "Build", + RunsOn = BuildMachines.WindowsLatest, + + Steps = new List + { + new CheckoutTaskV3 + { + Name = "Check out" + }, + + new SetupDotNetTaskV3 + { + Name = "Setup .Net", + + With = new TargetDotNetVersionV3 + { + DotNetVersion = "8.0.302" + } + }, + + new RestoreTask + { + Name = "Restore" + }, + + new DotNetBuildTask + { + Name = "Build" + }, + + new TestTask + { + Name = "Test" + } + } + } + }, + { + "add_tag", + new TagJob( + runsOn: BuildMachines.UbuntuLatest, + dependsOn: "build", + projectRelativePath: $"{projectName}/{projectName}.csproj", + githubToken: "${{ secrets.PAT_FOR_TAGGING }}", + branchName: branchName) + { + Name = "Tag and Release" + } + }, + } + }; + + string buildScriptPath = "../../../../.github/workflows/build.yml"; + string directoryPath = Path.GetDirectoryName(buildScriptPath); + + if (!Directory.Exists(directoryPath)) + { + Directory.CreateDirectory(directoryPath); + } + + adotNetClient.SerializeAndWriteToFile( + adoPipeline: githubPipeline, + path: buildScriptPath); + } + } +} \ No newline at end of file diff --git a/STX.EFxceptions.PostgreSQL.sln b/STX.EFxceptions.PostgreSQL.sln index e60c55b..24d8c63 100644 --- a/STX.EFxceptions.PostgreSQL.sln +++ b/STX.EFxceptions.PostgreSQL.sln @@ -15,7 +15,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "STX.EFxceptions.PostgreSQL. EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "STX.EFxceptions.Identity.PostgreSQL.Tests.Acceptance", "STX.EFxceptions.Identity.PostgreSQL.Tests.Acceptance\STX.EFxceptions.Identity.PostgreSQL.Tests.Acceptance.csproj", "{2A18E4E6-ED2F-4579-B85A-4282DA9EDDD3}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "STX.EFxceptions.PostgreSQL.Tests.Acceptance", "STX.EFxceptions.PostgreSQL.Tests.Acceptance\STX.EFxceptions.PostgreSQL.Tests.Acceptance.csproj", "{E8F4E849-EC1B-49B4-BE19-8C7A7C36C25A}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "STX.EFxceptions.PostgreSQL.Infrastructure.Build", "STX.EFxceptions.PostgreSQL.Infrastructure.Build\STX.EFxceptions.PostgreSQL.Infrastructure.Build.csproj", "{068E4391-352C-42B9-8DB6-A928C2B612FE}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -47,6 +47,10 @@ Global {2A18E4E6-ED2F-4579-B85A-4282DA9EDDD3}.Debug|Any CPU.Build.0 = Debug|Any CPU {2A18E4E6-ED2F-4579-B85A-4282DA9EDDD3}.Release|Any CPU.ActiveCfg = Release|Any CPU {2A18E4E6-ED2F-4579-B85A-4282DA9EDDD3}.Release|Any CPU.Build.0 = Release|Any CPU + {068E4391-352C-42B9-8DB6-A928C2B612FE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {068E4391-352C-42B9-8DB6-A928C2B612FE}.Debug|Any CPU.Build.0 = Debug|Any CPU + {068E4391-352C-42B9-8DB6-A928C2B612FE}.Release|Any CPU.ActiveCfg = Release|Any CPU + {068E4391-352C-42B9-8DB6-A928C2B612FE}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE