diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index 61d0091..6418926 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -43,33 +43,52 @@ jobs: - name: Test run: dotnet test --no-build --verbosity normal add_tag: + runs-on: ubuntu-latest + needs: + - build if: > github.event.pull_request.merged && + github.event.pull_request.base.ref == 'master' && + startsWith(github.event.pull_request.title, 'RELEASES:') && + contains(github.event.pull_request.labels.*.name, 'RELEASES') - runs-on: ubuntu-latest - needs: - - build steps: - name: Checkout code uses: actions/checkout@v3 - name: Extract Version Number id: extract_version run: |- - echo "::set-output name=version_number::$(grep -oP '(?<=)[^<]+' ADotNet/ADotNet.csproj)" + echo "version_number=$(grep -oP '(?<=)[^<]+' ADotNet/ADotNet.csproj)" >> $GITHUB_OUTPUT + echo "package_release_notes=$(grep -oP '(?<=)[^<]+' ADotNet/ADotNet.csproj)" >> $GITHUB_OUTPUT - name: Print Version Number run: |- - echo "Version number is ${{ steps.extract_version.outputs.version_number }}" + echo "Version number - v${{ steps.extract_version.outputs.version_number }}" + echo "Release Notes - ${{ steps.extract_version.outputs.package_release_notes }}" - name: Configure Git run: |- - git config user.name "Add Git Release Tag Action" - git config user.email "github.action@noreply.github.com" + git config user.name "GitHub Action" + git config user.email "action@github.com" - name: Authenticate with GitHub uses: actions/checkout@v3 with: token: ${{ secrets.PAT_FOR_TAGGING }} - - name: Add Git Tag - Release + - name: Add Release Tag run: |- - git tag -a "release-${{ steps.extract_version.outputs.version_number }}" -m "Release ${{ steps.extract_version.outputs.version_number }}" + 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 Release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.PAT_FOR_TAGGING }} + 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_version.outputs.package_release_notes }} diff --git a/ADotNet.Infrastructure.Build/Program.cs b/ADotNet.Infrastructure.Build/Program.cs index 68038ed..49efaaa 100644 --- a/ADotNet.Infrastructure.Build/Program.cs +++ b/ADotNet.Infrastructure.Build/Program.cs @@ -5,6 +5,7 @@ // --------------------------------------------------------------------------- using System.Collections.Generic; +using System.IO; using ADotNet.Clients; using ADotNet.Models.Pipelines.GithubPipelines.DotNets; using ADotNet.Models.Pipelines.GithubPipelines.DotNets.Tasks; @@ -83,16 +84,16 @@ static void Main(string[] args) }, AddTag = new TagJob { + RunsOn = BuildMachines.UbuntuLatest, + + Needs = new string[] { "build" }, + If = "github.event.pull_request.merged &&\r" + "github.event.pull_request.base.ref == 'master' &&\r" + "startsWith(github.event.pull_request.title, 'RELEASES:') &&\r" + "contains(github.event.pull_request.labels.*.name, 'RELEASES')\r", - RunsOn = BuildMachines.UbuntuLatest, - - Needs = new string[] { "build" }, - Steps = new List { new CheckoutTaskV3 @@ -104,22 +105,26 @@ static void Main(string[] args) { Name = "Extract Version Number", Id = "extract_version", - Run = "echo \"::set-output name=version_number::$(grep -oP '(?<=)[^<]+' ADotNet/ADotNet.csproj)\"" + Run = + "echo \"version_number=$(grep -oP '(?<=)[^<]+' ADotNet/ADotNet.csproj)\" >> $GITHUB_OUTPUT\r" + + "echo \"package_release_notes=$(grep -oP '(?<=)[^<]+' ADotNet/ADotNet.csproj)\" >> $GITHUB_OUTPUT" }, new ShellScriptTask { Name = "Print Version Number", - Run = "echo \"Version number is ${{ steps.extract_version.outputs.version_number }}\"" + Run = + "echo \"Version number - v${{ steps.extract_version.outputs.version_number }}\"\r" + + "echo \"Release Notes - ${{ steps.extract_version.outputs.package_release_notes }}\"" }, new ShellScriptTask { Name = "Configure Git", Run = - "git config user.name \"Add Git Release Tag Action\"" + "git config user.name \"GitHub Action\"" + "\r" - + "git config user.email \"github.action@noreply.github.com\"" + + "git config user.email \"action@github.com\"" }, new CheckoutTaskV3 @@ -133,18 +138,49 @@ static void Main(string[] args) new ShellScriptTask { - Name = "Add Git Tag - Release", + Name = "Add Release Tag", Run = - "git tag -a \"release-${{ steps.extract_version.outputs.version_number }}\" -m \"Release ${{ steps.extract_version.outputs.version_number }}\"" - + "\r" + "git tag -a \"v${{ steps.extract_version.outputs.version_number }}\" -m \"Release - v${{ steps.extract_version.outputs.version_number }}\"\r" + "git push origin --tags" }, + + new ReleaseTaskV1 + { + Name = "Create Release", + Uses = "actions/create-release@v1", + + EnvironmentVariables = new Dictionary + { + { "GITHUB_TOKEN", "${{ secrets.PAT_FOR_TAGGING }}" } + }, + + With = new Dictionary + { + { "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 }}\r" + + "\r" + + "#### Release Notes\r" + + "${{ steps.extract_version.outputs.package_release_notes }}" + }, + } + } } } } }; - aDotNetClient.SerializeAndWriteToFile(githubPipeline, "../../../../.github/workflows/dotnet.yml"); + string buildScriptPath = "../../../../.github/workflows/dotnet.yml"; + string directoryPath = Path.GetDirectoryName(buildScriptPath); + + if (!Directory.Exists(directoryPath)) + { + Directory.CreateDirectory(directoryPath); + } + + aDotNetClient.SerializeAndWriteToFile(githubPipeline, path: buildScriptPath); } } -} +} \ No newline at end of file