Skip to content

Commit

Permalink
INFRASTRUCTURE: Updated build script
Browse files Browse the repository at this point in the history
  • Loading branch information
cjdutoit committed May 19, 2023
1 parent a900bc3 commit 3b69b95
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 22 deletions.
37 changes: 28 additions & 9 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 '(?<=<Version>)[^<]+' ADotNet/ADotNet.csproj)"
echo "version_number=$(grep -oP '(?<=<Version>)[^<]+' ADotNet/ADotNet.csproj)" >> $GITHUB_OUTPUT
echo "package_release_notes=$(grep -oP '(?<=<PackageReleaseNotes>)[^<]+' 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 "[email protected]"
- 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 }}
62 changes: 49 additions & 13 deletions ADotNet.Infrastructure.Build/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<GithubTask>
{
new CheckoutTaskV3
Expand All @@ -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 '(?<=<Version>)[^<]+' ADotNet/ADotNet.csproj)\""
Run =
"echo \"version_number=$(grep -oP '(?<=<Version>)[^<]+' ADotNet/ADotNet.csproj)\" >> $GITHUB_OUTPUT\r"
+ "echo \"package_release_notes=$(grep -oP '(?<=<PackageReleaseNotes>)[^<]+' 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 \"[email protected]\""
},

new CheckoutTaskV3
Expand All @@ -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<string, string>
{
{ "GITHUB_TOKEN", "${{ secrets.PAT_FOR_TAGGING }}" }
},

With = new Dictionary<string, string>
{
{ "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);
}
}
}
}

0 comments on commit 3b69b95

Please sign in to comment.