Skip to content

Commit

Permalink
Merge pull request #92 from hassanhabib/users/cjdutoit/mediumfix-tag-…
Browse files Browse the repository at this point in the history
…release-assignment

MEDIUMFIX: TagJob to use step variables as environment variables has a combined size limitation
  • Loading branch information
cjdutoit authored Jun 28, 2023
2 parents 44e566c + 40cefb1 commit 373da23
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 34 deletions.
48 changes: 33 additions & 15 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,42 +67,60 @@ jobs:
git config user.email "[email protected]"
- 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<<EOF' >> $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<<EOF" >> $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<<EOF' >> $env:GITHUB_ENV
echo "package_release_notes<<EOF" >> $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:
Expand Down
2 changes: 0 additions & 2 deletions ADotNet.Infrastructure.Build/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
},
{
Expand Down
34 changes: 23 additions & 11 deletions ADotNet/Models/Pipelines/GithubPipelines/DotNets/TagJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ public TagJob(
string dependsOn,
string projectRelativePath,
string githubToken,
string versionEnvironmentVariableName,
string packageReleaseNotesEnvironmentVariable,
string branchName)
{
RunsOn = runsOn;
Expand Down Expand Up @@ -49,32 +47,46 @@ public TagJob(
},

new ExtractProjectPropertyTask(
name: "Extract Version",
id: "extract_version",
projectRelativePath,
propertyName: "Version",
environmentVariableName: versionEnvironmentVariableName)
stepVariableName: "version_number",
runsOn),

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",
runsOn),

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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,55 @@ 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,
string runsOn)
{
Run = "$" + environmentVariableName + "=((Select-Xml -Path '" + projectRelativePath + "' -XPath '//" + propertyName + "').Node.InnerXML)\n"
+ "'" + environmentVariableName + "<<EOF' >> $env:GITHUB_ENV\n"
+ "'$" + environmentVariableName + "' >> $env:GITHUB_ENV\n"
+ "'EOF' >> $env:GITHUB_ENV\n";
Name = name;
Id = id;

if (runsOn.ToLower().StartsWith("windows"))
{
Shell = ShellEnvironments.PowerShellCore;

Run =
"# Running on Windows \n"
+ "$" + stepVariableName + "=((Select-Xml -Path '" + projectRelativePath + "' -XPath '//" + propertyName + "').Node.InnerXML)\n"
+ "echo \"$" + stepVariableName + "\"\n"
+ "echo \"" + stepVariableName + "<<EOF\" >> $GITHUB_OUTPUT \n"
+ "echo \"$" + stepVariableName + "\" >> $GITHUB_OUTPUT \n"
+ "echo \"EOF\" >> $GITHUB_OUTPUT \n";
}
else
{
Shell = ShellEnvironments.Bash;

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 + "<<EOF\" >> $GITHUB_OUTPUT \n"
+ "echo \"$" + stepVariableName + "\" >> $GITHUB_OUTPUT \n"
+ "echo \"EOF\" >> $GITHUB_OUTPUT \n";
}
}

/// <summary>
/// Gets the name of the task.
/// </summary>
[YamlMember(Order = 0, DefaultValuesHandling = DefaultValuesHandling.OmitDefaults)]
public new string Name { get; private set; }

/// <summary>
/// Gets the unique identifier of the task.
/// </summary>
[YamlMember(Order = 1, DefaultValuesHandling = DefaultValuesHandling.OmitDefaults)]
public new string Id { get; private set; }

/// <summary>
/// Gets the command to execute for the task.
/// </summary>
Expand All @@ -34,6 +73,6 @@ public ExtractProjectPropertyTask(
/// Gets the shell on which the task is executed.
/// </summary>
[YamlMember(Order = 9, Alias = "shell")]
public new string Shell { get; private set; } = ShellEnvironments.PowerShellCore;
public new string Shell { get; private set; }
}
}

0 comments on commit 373da23

Please sign in to comment.