From dfe4d6d7282abbc4975bd3a59f35bd77933e30f7 Mon Sep 17 00:00:00 2001 From: Christo du Toit Date: Wed, 21 Jun 2023 00:55:29 +0100 Subject: [PATCH 1/2] CODE RUB: Updated build scripts --- .../GithubPipelines/DotNets/TagJob.cs | 32 +++++++++----- .../Tasks/ExtractProjectPropertyTask.cs | 42 ++++++++++++++++--- 2 files changed, 58 insertions(+), 16 deletions(-) diff --git a/ADotNet/Models/Pipelines/GithubPipelines/DotNets/TagJob.cs b/ADotNet/Models/Pipelines/GithubPipelines/DotNets/TagJob.cs index 5f8b6c8..bcb98fb 100644 --- a/ADotNet/Models/Pipelines/GithubPipelines/DotNets/TagJob.cs +++ b/ADotNet/Models/Pipelines/GithubPipelines/DotNets/TagJob.cs @@ -18,8 +18,6 @@ public TagJob( string dependsOn, string projectRelativePath, string githubToken, - string versionEnvironmentVariableName, - string packageReleaseNotesEnvironmentVariable, string branchName) { RunsOn = runsOn; @@ -49,32 +47,44 @@ public TagJob( }, new ExtractProjectPropertyTask( + name: "Extract Version", + id: "extract_version", projectRelativePath, propertyName: "Version", - environmentVariableName: versionEnvironmentVariableName) + stepVariableName: "version_number"), + + new GithubTask() { - Name = $"Extract Version" + Name = "Display Version", + Run = "echo \"Version number: ${{ steps.extract_version.outputs.version_number }}\"" }, new ExtractProjectPropertyTask( + name: $"Extract Package Release Notes", + id: "extract_package_release_notes", projectRelativePath, propertyName: "PackageReleaseNotes", - environmentVariableName: packageReleaseNotesEnvironmentVariable) + stepVariableName: "package_release_notes"), + + new GithubTask() { - Name = $"Extract Package Release Notes" + Name = "Display Package Release Notes", + Run = + "echo \"Package Release Notes: " + + "${{ steps.extract_package_release_notes.outputs.package_release_notes }}\"" }, new CreateGitHubTagTask( - tagName: "v${{ env." + versionEnvironmentVariableName + " }}", - tagMessage: "Release - v${{ env." + versionEnvironmentVariableName + " }}") + tagName: "v${{ steps.extract_version.outputs.version_number }}", + tagMessage: "Release - v${{ steps.extract_version.outputs.version_number }}") { Name = "Create GitHub Tag", }, new CreateGitHubReleaseTask( - releaseName: "Release - v${{ env." + versionEnvironmentVariableName + " }}", - tagName: "v${{ env." + versionEnvironmentVariableName + " }}", - releaseNotes: "${{ env." + packageReleaseNotesEnvironmentVariable + " }}", + releaseName: "Release - v${{ steps.extract_version.outputs.version_number }}", + tagName: "v${{ steps.extract_version.outputs.version_number }}", + releaseNotes: "${{ steps.extract_package_release_notes.outputs.package_release_notes }}", githubToken) { Name = "Create GitHub Release", diff --git a/ADotNet/Models/Pipelines/GithubPipelines/DotNets/Tasks/ExtractProjectPropertyTask.cs b/ADotNet/Models/Pipelines/GithubPipelines/DotNets/Tasks/ExtractProjectPropertyTask.cs index fae68c7..3a13da1 100644 --- a/ADotNet/Models/Pipelines/GithubPipelines/DotNets/Tasks/ExtractProjectPropertyTask.cs +++ b/ADotNet/Models/Pipelines/GithubPipelines/DotNets/Tasks/ExtractProjectPropertyTask.cs @@ -14,16 +14,48 @@ namespace ADotNet.Models.Pipelines.GithubPipelines.DotNets.Tasks public sealed class ExtractProjectPropertyTask : GithubTask { public ExtractProjectPropertyTask( + string name, + string id, string projectRelativePath, string propertyName, - string environmentVariableName) + string stepVariableName) { - Run = "$" + environmentVariableName + "=((Select-Xml -Path '" + projectRelativePath + "' -XPath '//" + propertyName + "').Node.InnerXML)\n" - + "'" + environmentVariableName + "<> $env:GITHUB_ENV\n" - + "'$" + environmentVariableName + "' >> $env:GITHUB_ENV\n" - + "'EOF' >> $env:GITHUB_ENV\n"; + Name = name; + Id = id; + Shell = ShellEnvironments.Bash; + + Run = + "if [[ \"$OSTYPE\" == \"msys\" || \"$OSTYPE\" == \"cygwin\" ]]; then \n" + + "# Running on Windows \n" + + + "choco install xmlstarlet\n" + + stepVariableName + "=$(xmlstarlet.exe sel -t -v \"//" + propertyName + "\" -n " + projectRelativePath + ")\n" + + + "else \n" + + "# Running on Linux/Unix\n" + + + "sudo apt-get install xmlstarlet\n" + + stepVariableName + "=$(xmlstarlet sel -t -v \"//" + propertyName + "\" -n " + projectRelativePath + ")\n" + + + "fi \n" + + "echo \"$" + stepVariableName + "\"\n" + + "echo \"" + stepVariableName + "<> $GITHUB_OUTPUT \n" + + "echo \"$" + stepVariableName + "\" >> $GITHUB_OUTPUT \n" + + "echo \"EOF\" >> $GITHUB_OUTPUT \n"; } + /// + /// Gets the name of the task. + /// + [YamlMember(Order = 0, DefaultValuesHandling = DefaultValuesHandling.OmitDefaults)] + public new string Name { get; private set; } + + /// + /// Gets the unique identifier of the task. + /// + [YamlMember(Order = 1, DefaultValuesHandling = DefaultValuesHandling.OmitDefaults)] + public new string Id { get; private set; } + /// /// Gets the command to execute for the task. /// From 40cefb1766b3da531c7d1cf51620db004b21b36e Mon Sep 17 00:00:00 2001 From: Christo du Toit Date: Wed, 28 Jun 2023 21:32:15 +0100 Subject: [PATCH 2/2] MEDIUMFIX: TagJob to use step variables as environment variables has a combined size limitation --- .github/workflows/dotnet.yml | 48 +++++++++++++------ ADotNet.Infrastructure.Build/Program.cs | 2 - .../GithubPipelines/DotNets/TagJob.cs | 6 ++- .../Tasks/ExtractProjectPropertyTask.cs | 45 +++++++++-------- 4 files changed, 63 insertions(+), 38 deletions(-) diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index 04a3f1e..73bddd0 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -67,42 +67,60 @@ jobs: git config user.email "action@github.com" - name: Extract Version + id: extract_version run: > - $version_number=((Select-Xml -Path 'ADotNet/ADotNet.csproj' -XPath '//Version').Node.InnerXML) + # Running on Linux/Unix - 'version_number<> $env:GITHUB_ENV + sudo apt-get install xmlstarlet - '$version_number' >> $env:GITHUB_ENV + version_number=$(xmlstarlet sel -t -v "//Version" -n ADotNet/ADotNet.csproj) - 'EOF' >> $env:GITHUB_ENV - shell: pwsh + 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: > - $package_release_notes=((Select-Xml -Path 'ADotNet/ADotNet.csproj' -XPath '//PackageReleaseNotes').Node.InnerXML) + # Running on Linux/Unix + + sudo apt-get install xmlstarlet + + package_release_notes=$(xmlstarlet sel -t -v "//PackageReleaseNotes" -n ADotNet/ADotNet.csproj) + + echo "$package_release_notes" - 'package_release_notes<> $env:GITHUB_ENV + echo "package_release_notes<> $GITHUB_OUTPUT - '$package_release_notes' >> $env:GITHUB_ENV + echo "$package_release_notes" >> $GITHUB_OUTPUT - 'EOF' >> $env:GITHUB_ENV - shell: pwsh + 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${{ env.version_number }}" -m "Release - v${{ env.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 GitHub Release uses: actions/create-release@v1 with: - tag_name: v${{ env.version_number }} - release_name: Release - v${{ env.version_number }} + tag_name: v${{ steps.extract_version.outputs.version_number }} + release_name: Release - v${{ steps.extract_version.outputs.version_number }} body: >- - ## Release - v${{ env.version_number }} + ## Release - v${{ steps.extract_version.outputs.version_number }} ### Release Notes - ${{ env.package_release_notes }} + ${{ steps.extract_package_release_notes.outputs.package_release_notes }} env: GITHUB_TOKEN: ${{ secrets.PAT_FOR_TAGGING }} publish: diff --git a/ADotNet.Infrastructure.Build/Program.cs b/ADotNet.Infrastructure.Build/Program.cs index 41e3d1c..bbfde8f 100644 --- a/ADotNet.Infrastructure.Build/Program.cs +++ b/ADotNet.Infrastructure.Build/Program.cs @@ -93,8 +93,6 @@ static void Main(string[] args) dependsOn: "build", projectRelativePath: "ADotNet/ADotNet.csproj", githubToken: "${{ secrets.PAT_FOR_TAGGING }}", - versionEnvironmentVariableName: "version_number", - packageReleaseNotesEnvironmentVariable: "package_release_notes", branchName: branchName) }, { diff --git a/ADotNet/Models/Pipelines/GithubPipelines/DotNets/TagJob.cs b/ADotNet/Models/Pipelines/GithubPipelines/DotNets/TagJob.cs index bcb98fb..ddb52c1 100644 --- a/ADotNet/Models/Pipelines/GithubPipelines/DotNets/TagJob.cs +++ b/ADotNet/Models/Pipelines/GithubPipelines/DotNets/TagJob.cs @@ -51,7 +51,8 @@ public TagJob( id: "extract_version", projectRelativePath, propertyName: "Version", - stepVariableName: "version_number"), + stepVariableName: "version_number", + runsOn), new GithubTask() { @@ -64,7 +65,8 @@ public TagJob( id: "extract_package_release_notes", projectRelativePath, propertyName: "PackageReleaseNotes", - stepVariableName: "package_release_notes"), + stepVariableName: "package_release_notes", + runsOn), new GithubTask() { diff --git a/ADotNet/Models/Pipelines/GithubPipelines/DotNets/Tasks/ExtractProjectPropertyTask.cs b/ADotNet/Models/Pipelines/GithubPipelines/DotNets/Tasks/ExtractProjectPropertyTask.cs index 3a13da1..b9de82d 100644 --- a/ADotNet/Models/Pipelines/GithubPipelines/DotNets/Tasks/ExtractProjectPropertyTask.cs +++ b/ADotNet/Models/Pipelines/GithubPipelines/DotNets/Tasks/ExtractProjectPropertyTask.cs @@ -18,30 +18,37 @@ public ExtractProjectPropertyTask( string id, string projectRelativePath, string propertyName, - string stepVariableName) + string stepVariableName, + string runsOn) { Name = name; Id = id; - Shell = ShellEnvironments.Bash; - Run = - "if [[ \"$OSTYPE\" == \"msys\" || \"$OSTYPE\" == \"cygwin\" ]]; then \n" - + "# Running on Windows \n" + if (runsOn.ToLower().StartsWith("windows")) + { + Shell = ShellEnvironments.PowerShellCore; - + "choco install xmlstarlet\n" - + stepVariableName + "=$(xmlstarlet.exe sel -t -v \"//" + propertyName + "\" -n " + projectRelativePath + ")\n" + Run = + "# Running on Windows \n" + + "$" + stepVariableName + "=((Select-Xml -Path '" + projectRelativePath + "' -XPath '//" + propertyName + "').Node.InnerXML)\n" + + "echo \"$" + stepVariableName + "\"\n" + + "echo \"" + stepVariableName + "<> $GITHUB_OUTPUT \n" + + "echo \"$" + stepVariableName + "\" >> $GITHUB_OUTPUT \n" + + "echo \"EOF\" >> $GITHUB_OUTPUT \n"; + } + else + { + Shell = ShellEnvironments.Bash; - + "else \n" - + "# Running on Linux/Unix\n" - - + "sudo apt-get install xmlstarlet\n" - + stepVariableName + "=$(xmlstarlet sel -t -v \"//" + propertyName + "\" -n " + projectRelativePath + ")\n" - - + "fi \n" - + "echo \"$" + stepVariableName + "\"\n" - + "echo \"" + stepVariableName + "<> $GITHUB_OUTPUT \n" - + "echo \"$" + stepVariableName + "\" >> $GITHUB_OUTPUT \n" - + "echo \"EOF\" >> $GITHUB_OUTPUT \n"; + Run = + "# Running on Linux/Unix \n" + + "sudo apt-get install xmlstarlet\n" + + stepVariableName + "=$(xmlstarlet sel -t -v \"//" + propertyName + "\" -n " + projectRelativePath + ")\n" + + "echo \"$" + stepVariableName + "\"\n" + + "echo \"" + stepVariableName + "<> $GITHUB_OUTPUT \n" + + "echo \"$" + stepVariableName + "\" >> $GITHUB_OUTPUT \n" + + "echo \"EOF\" >> $GITHUB_OUTPUT \n"; + } } /// @@ -66,6 +73,6 @@ public ExtractProjectPropertyTask( /// Gets the shell on which the task is executed. /// [YamlMember(Order = 9, Alias = "shell")] - public new string Shell { get; private set; } = ShellEnvironments.PowerShellCore; + public new string Shell { get; private set; } } }