Skip to content

Commit

Permalink
Use auto-generated pipeline in Nuke (#10)
Browse files Browse the repository at this point in the history
* Use auto-generation of pipeline in Nuke

* Only run builds against main
  • Loading branch information
Hawxy authored Apr 18, 2023
1 parent 6e70483 commit 8e59754
Show file tree
Hide file tree
Showing 7 changed files with 135 additions and 58 deletions.
45 changes: 45 additions & 0 deletions .github/workflows/Build_&_Test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# ------------------------------------------------------------------------------
# <auto-generated>
#
# This code was generated.
#
# - To turn off auto-generation set:
#
# [GitHubActions (AutoGenerate = false)]
#
# - To trigger manual generation invoke:
#
# nuke --generate-configuration GitHubActions_Build_&_Test --host GitHubActions
#
# </auto-generated>
# ------------------------------------------------------------------------------

name: Build_&_Test

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
ubuntu-latest:
name: ubuntu-latest
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Cache .nuke/temp, ~/.nuget/packages
uses: actions/cache@v3
with:
path: |
.nuke/temp
~/.nuget/packages
key: ${{ runner.os }}-${{ hashFiles('**/global.json', '**/*.csproj') }}
- name: Run './build.cmd Test'
run: ./build.cmd Test
env:
FgaStoreId: ${{ secrets.FGA_STORE_ID }}
FgaClientId: ${{ secrets.FGA_CLIENT_ID }}
FgaClientSecret: ${{ secrets.FGA_CLIENT_SECRET }}
37 changes: 37 additions & 0 deletions .github/workflows/Manual_Nuget_Push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# ------------------------------------------------------------------------------
# <auto-generated>
#
# This code was generated.
#
# - To turn off auto-generation set:
#
# [GitHubActions (AutoGenerate = false)]
#
# - To trigger manual generation invoke:
#
# nuke --generate-configuration GitHubActions_Manual_Nuget_Push --host GitHubActions
#
# </auto-generated>
# ------------------------------------------------------------------------------

name: Manual_Nuget_Push

on: [workflow_dispatch]

jobs:
ubuntu-latest:
name: ubuntu-latest
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Cache .nuke/temp, ~/.nuget/packages
uses: actions/cache@v3
with:
path: |
.nuke/temp
~/.nuget/packages
key: ${{ runner.os }}-${{ hashFiles('**/global.json', '**/*.csproj') }}
- name: Run './build.cmd NugetPush'
run: ./build.cmd NugetPush
env:
NugetApiKey: ${{ secrets.NUGET_API_KEY }}
27 changes: 0 additions & 27 deletions .github/workflows/build.yml

This file was deleted.

24 changes: 0 additions & 24 deletions .github/workflows/nuget-push.yml

This file was deleted.

16 changes: 16 additions & 0 deletions .nuke/build.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,21 @@
"type": "boolean",
"description": "Indicates to continue a previously failed build attempt"
},
"FgaClientId": {
"type": "string",
"description": "FGA Client ID",
"default": "Secrets must be entered via 'nuke :secrets [profile]'"
},
"FgaClientSecret": {
"type": "string",
"description": "FGA Client Secret",
"default": "Secrets must be entered via 'nuke :secrets [profile]'"
},
"FgaStoreId": {
"type": "string",
"description": "FGA Store ID",
"default": "Secrets must be entered via 'nuke :secrets [profile]'"
},
"Help": {
"type": "boolean",
"description": "Shows the help text for this build assembly"
Expand All @@ -21,6 +36,7 @@
"AppVeyor",
"AzurePipelines",
"Bamboo",
"Bitbucket",
"Bitrise",
"GitHubActions",
"GitLab",
Expand Down
42 changes: 36 additions & 6 deletions build/Build.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,27 @@
using Nuke.Common;
using Nuke.Common.CI;
using Nuke.Common.CI.GitHubActions;
using Nuke.Common.IO;
using Nuke.Common.ProjectModel;
using Nuke.Common.Tooling;
using Nuke.Common.Tools.DotNet;
using static Nuke.Common.IO.FileSystemTasks;
using static Nuke.Common.Tools.DotNet.DotNetTasks;

[ShutdownDotNetAfterServerBuild]
[GitHubActions(
"Build & Test",
GitHubActionsImage.UbuntuLatest,
OnPushBranches = new []{ "main" },
OnPullRequestBranches = new []{ "main" },
InvokedTargets = new[] { nameof(Test) },
ImportSecrets = new []{ nameof(FgaStoreId), nameof(FgaClientId), nameof(FgaClientSecret) })]
[GitHubActions(
"Manual Nuget Push",
GitHubActionsImage.UbuntuLatest,
On = new[] { GitHubActionsTrigger.WorkflowDispatch },
InvokedTargets = new[] { nameof(NugetPush) },
ImportSecrets = new[] { nameof(NugetApiKey) })]
class Build : NukeBuild
{
/// Support plugins are available for:
Expand All @@ -19,7 +34,6 @@ class Build : NukeBuild

[Solution(GenerateProjects = true)] readonly Solution Solution;

AbsolutePath SourceDirectory => RootDirectory / "src";
AbsolutePath ArtifactsDirectory => RootDirectory / "artifacts";

Target Clean => _ => _
Expand Down Expand Up @@ -47,12 +61,28 @@ class Build : NukeBuild
.EnableNoRestore());
});

[Parameter("FGA Store ID")][Secret] readonly string FgaStoreId;
[Parameter("FGA Client ID")][Secret] readonly string FgaClientId;
[Parameter("FGA Client Secret")][Secret] readonly string FgaClientSecret;

Target Test => _ => _
.DependsOn(Compile)
.Executes(() =>
{
DotNetTest(s => s
.SetProjectFile(Solution.Fga_Net_Tests));
DotNetTest(s =>
{
var config = s
.SetProjectFile(Solution.Fga_Net_Tests);
if (!string.IsNullOrEmpty(FgaStoreId))
{
return config.AddProcessEnvironmentVariable("AUTH0FGA__STOREID", FgaStoreId)
.AddProcessEnvironmentVariable("AUTH0FGA__CLIENTID", FgaClientId)
.AddProcessEnvironmentVariable("AUTH0FGA__CLIENTSECRET", FgaClientSecret);
}

return config;

});
});

Target NugetPack => _ => _
Expand All @@ -72,10 +102,10 @@ class Build : NukeBuild
.SetOutputDirectory(ArtifactsDirectory));
});

[Parameter("Nuget Api Key")]
readonly string NugetApiKey = string.Empty;
[Parameter("Nuget Api Key")] [Secret] readonly string NugetApiKey;

Target NugetPush => _ => _
.After(NugetPack)
.DependsOn(NugetPack)
.Requires(() => !string.IsNullOrEmpty(NugetApiKey))
.Executes(() =>
{
Expand Down
2 changes: 1 addition & 1 deletion build/_build.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<RootNamespace></RootNamespace>
<NoWarn>CS0649;CS0169</NoWarn>
<NukeRootDirectory>..</NukeRootDirectory>
Expand Down

0 comments on commit 8e59754

Please sign in to comment.