Skip to content

Commit

Permalink
Merge pull request #74 from hassanhabib/users/cjdutoit/data-job-publish
Browse files Browse the repository at this point in the history
INFRASTRUCTURE: Publish Job
  • Loading branch information
hassanhabib authored May 19, 2023
2 parents 3b69b95 + 7bb6db9 commit 9dc520c
Show file tree
Hide file tree
Showing 6 changed files with 148 additions and 12 deletions.
34 changes: 28 additions & 6 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,14 @@ jobs:
runs-on: ubuntu-latest
needs:
- build
if: >
github.event.pull_request.merged &&
if: >-
needs.build.result == 'success' &&
github.event.pull_request.base.ref == 'master' &&
github.event.pull_request.merged &&
startsWith(github.event.pull_request.title, 'RELEASES:') &&
github.event.pull_request.base.ref == 'master' &&
startsWith(github.event.pull_request.title, 'RELEASES:') &&
contains(github.event.pull_request.labels.*.name, 'RELEASES')
steps:
Expand All @@ -73,15 +75,15 @@ jobs:
- name: Authenticate with GitHub
uses: actions/checkout@v3
with:
token: ${{ secrets.PAT_FOR_TAGGING }}
token: ${{ secrets.GITHUB_PAT_FOR_TAGGING }}
- name: Add Release 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 Release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.PAT_FOR_TAGGING }}
GITHUB_TOKEN: ${{ secrets.GITHUB_PAT_FOR_TAGGING }}
with:
tag_name: v${{ steps.extract_version.outputs.version_number }}
release_name: Release - v${{ steps.extract_version.outputs.version_number }}
Expand All @@ -92,3 +94,23 @@ jobs:
#### Release Notes
${{ steps.extract_version.outputs.package_release_notes }}
publish:
runs-on: ubuntu-latest
needs:
- add_tag
if: needs.add_tag.result == 'success'
steps:
- name: Check out
uses: actions/checkout@v3
- name: Setup .Net
uses: actions/setup-dotnet@v3
with:
dotnet-version: 7.0.201
- name: Restore
run: dotnet restore
- name: Build
run: dotnet build --no-restore --configuration Release
- name: Pack NuGet Package
run: dotnet pack --configuration Release
- name: Push NuGet Package
run: dotnet nuget push **/bin/Release/**/*.nupkg --source https://api.nuget.org/v3/index.json --api-key ${{ secrets.NUGET_API_KEY }}
60 changes: 54 additions & 6 deletions ADotNet.Infrastructure.Build/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,11 @@ static void Main(string[] args)
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",
"needs.build.result == 'success' &&\r"
+ "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')",

Steps = new List<GithubTask>
{
Expand Down Expand Up @@ -122,8 +123,7 @@ static void Main(string[] args)
{
Name = "Configure Git",
Run =
"git config user.name \"GitHub Action\""
+ "\r"
"git config user.name \"GitHub Action\"\r"
+ "git config user.email \"[email protected]\""
},

Expand Down Expand Up @@ -168,6 +168,54 @@ static void Main(string[] args)
}
}
}
},
Publish = new PublishJob
{
RunsOn = BuildMachines.UbuntuLatest,
Needs = new string[] { "add_tag" },

If =
"needs.add_tag.result == 'success'",

Steps = new List<GithubTask> {
new CheckoutTaskV3
{
Name = "Check out"
},

new SetupDotNetTaskV3
{
Name = "Setup .Net",

TargetDotNetVersion = new TargetDotNetVersionV3
{
DotNetVersion = "7.0.201"
}
},

new RestoreTask
{
Name = "Restore"
},

new DotNetBuildTask
{
Name = "Build",
Run = "dotnet build --no-restore --configuration Release"
},

new PackTask
{
Name = "Pack NuGet Package",

},

new NugetPushTask
{
Name = "Push NuGet Package",
}

},
}
}
};
Expand Down
3 changes: 3 additions & 0 deletions ADotNet/Models/Pipelines/GithubPipelines/DotNets/Jobs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,8 @@ public class Jobs

[YamlMember(Order = 1, Alias = "add_tag", DefaultValuesHandling = DefaultValuesHandling.OmitDefaults)]
public TagJob AddTag { get; set; }

[YamlMember(Order = 2, Alias = "publish", DefaultValuesHandling = DefaultValuesHandling.OmitDefaults)]
public PublishJob Publish { get; set; }
}
}
31 changes: 31 additions & 0 deletions ADotNet/Models/Pipelines/GithubPipelines/DotNets/PublishJob.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// ---------------------------------------------------------------------------
// Copyright (c) Hassan Habib & Shri Humrudha Jagathisun All rights reserved.
// Licensed under the MIT License.
// See License.txt in the project root for license information.
// ---------------------------------------------------------------------------

using System.Collections.Generic;
using ADotNet.Models.Pipelines.GithubPipelines.DotNets.Tasks;
using YamlDotNet.Serialization;

namespace ADotNet.Models.Pipelines.GithubPipelines.DotNets
{
public class PublishJob
{
[YamlMember(Order = 0, Alias = "runs-on")]
public string RunsOn { get; set; }

[YamlMember(Order = 1, Alias = "needs", DefaultValuesHandling = DefaultValuesHandling.OmitDefaults)]
public string[] Needs { get; set; }

[YamlMember(Order = 2, Alias = "if", DefaultValuesHandling = DefaultValuesHandling.OmitDefaults)]
public string If { get; set; }

[YamlMember(Order = 3, Alias = "env", DefaultValuesHandling = DefaultValuesHandling.OmitDefaults)]
public Dictionary<string, string> EnvironmentVariables { get; set; }

[YamlMember(Order = 4)]
public List<GithubTask> Steps { get; set; }
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// ---------------------------------------------------------------------------
// Copyright (c) Hassan Habib & Shri Humrudha Jagathisun All rights reserved.
// Licensed under the MIT License.
// See License.txt in the project root for license information.
// ---------------------------------------------------------------------------

using YamlDotNet.Serialization;

namespace ADotNet.Models.Pipelines.GithubPipelines.DotNets.Tasks
{
public class NugetPushTask : GithubTask
{
[YamlMember(Order = 1)]
public string Run = "dotnet nuget push **/bin/Release/**/*.nupkg --source https://api.nuget.org/v3/index.json --api-key ${{ secrets.NUGET_API_KEY }}";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// ---------------------------------------------------------------------------
// Copyright (c) Hassan Habib & Shri Humrudha Jagathisun All rights reserved.
// Licensed under the MIT License.
// See License.txt in the project root for license information.
// ---------------------------------------------------------------------------

using YamlDotNet.Serialization;

namespace ADotNet.Models.Pipelines.GithubPipelines.DotNets.Tasks
{
public class PackTask : GithubTask
{
[YamlMember(Order = 1)]
public string Run = "dotnet pack --configuration Release";
}
}

0 comments on commit 9dc520c

Please sign in to comment.