From 24362d81c3d4f3c38563109aab7c716f8fe7e7bb Mon Sep 17 00:00:00 2001 From: Jason Webb Date: Thu, 18 Apr 2024 22:59:20 -0600 Subject: [PATCH] Generating CI file now for Github. --- .github/workflows/ci.yml | 44 +++++++++++++++++++++++++++++++ .nuke/build.schema.json | 2 ++ .nuke/parameters.json | 3 ++- Build/Build.cs | 56 ++++++++++++++++++++-------------------- Build/Build.csproj | 24 +++++++++++++++++ 5 files changed, 100 insertions(+), 29 deletions(-) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..d9739fea --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,44 @@ +# ------------------------------------------------------------------------------ +# +# +# This code was generated. +# +# - To turn off auto-generation set: +# +# [GitHubActions (AutoGenerate = false)] +# +# - To trigger manual generation invoke: +# +# nuke --generate-configuration GitHubActions_ci --host GitHubActions +# +# +# ------------------------------------------------------------------------------ + +name: ci + +on: + push: + paths: + - 'Src/**' + - 'Build/**' + 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', '**/Directory.Packages.props') }} + - name: 'Run: Compile, Pack, Push' + run: ./build.cmd Compile Pack Push + env: + NuGetApiKey: ${{ secrets.NUGET_API_KEY }} diff --git a/.nuke/build.schema.json b/.nuke/build.schema.json index cc63599e..6c425416 100644 --- a/.nuke/build.schema.json +++ b/.nuke/build.schema.json @@ -87,6 +87,7 @@ "Pack", "Print", "Print_Net_SDK", + "Push", "Restore" ] } @@ -106,6 +107,7 @@ "Pack", "Print", "Print_Net_SDK", + "Push", "Restore" ] } diff --git a/.nuke/parameters.json b/.nuke/parameters.json index 183a9def..970ccaee 100644 --- a/.nuke/parameters.json +++ b/.nuke/parameters.json @@ -1,4 +1,5 @@ { "$schema": "./build.schema.json", - "Solution": "Src/RCommon.sln" + "Solution": "Src/RCommon.sln", + "Configuration": "Release" } diff --git a/Build/Build.cs b/Build/Build.cs index cbf0dd54..9506fb20 100644 --- a/Build/Build.cs +++ b/Build/Build.cs @@ -2,6 +2,7 @@ using System.IO; using System.Linq; using GlobExpressions; +using Microsoft.Build.Evaluation; using Nuke.Common; using Nuke.Common.CI; using Nuke.Common.CI.GitHubActions; @@ -20,17 +21,16 @@ using static Nuke.Common.IO.FileSystemTasks; using static Nuke.Common.IO.PathConstruction; -[GitHubActions( - "continuous", +[GitHubActions("ci", GitHubActionsImage.UbuntuLatest, - On = new[] { GitHubActionsTrigger.Push }, - InvokedTargets = new[] { nameof(Compile) }, + InvokedTargets = new[] { nameof(Compile), nameof(Pack), nameof(Push) }, OnPushIncludePaths = new[] { "Src/**", "Build/**" }, - OnPushBranches = new[] { "main" }, - AutoGenerate = false)] + OnPullRequestBranches = new[] { "main" }, + AutoGenerate = true, + ImportSecrets = new[] {"NuGetApiKey"})] [ShutdownDotNetAfterServerBuild] class Build : NukeBuild { @@ -40,7 +40,7 @@ class Build : NukeBuild /// - Microsoft VisualStudio https://nuke.build/visualstudio /// - Microsoft VSCode https://nuke.build/vscode - public static int Main () => Execute(x => x.Compile, x => x.Pack); + public static int Main () => Execute(build => build.Compile, build => build.Pack, build => build.Push); [Parameter("Configuration to build - Default is 'Debug' (local) or 'Release' (server)")] readonly Configuration Configuration = IsLocalBuild ? Configuration.Debug : Configuration.Release; @@ -102,7 +102,7 @@ protected override void OnBuildInitialized() { Log.Information("Cleaning solution"); Directory_Src.GlobDirectories("**/bin", "**/obj") - .ForEach(DeleteDirectory); + .ForEach(x => x.DeleteDirectory()); }); Target Restore => _ => _ @@ -468,26 +468,26 @@ protected override void OnBuildInitialized() }); - //Target Push => _ => _ - // //.DependsOn(Pack) - // .Requires(() => NuGetApiUrl) - // .Requires(() => NuGetApiKey) - // .Requires(() => Configuration.Equals(Configuration.Release)) - // .Executes(() => - // { - // Glob.Files(Directory_NuGet, "*.nupkg") - // .NotEmpty() - // .Where(x => !x.EndsWith("symbols.nupkg")) - // .ForEach(x => - // { - // DotNetTasks - // .DotNetNuGetPush(s => s - // .SetTargetPath(x) - // .SetSource(NuGetApiUrl) - // .SetApiKey(NuGetApiKey) - // ); - // }); - // }); + Target Push => _ => _ + .DependsOn(Pack) + .Requires(() => NuGetApiUrl) + .Requires(() => NuGetApiKey) + .Requires(() => Configuration.Equals(Configuration.Release)) + .Executes(() => + { + Assert.NotNull(Glob.Files(Directory_NuGet, "*.nupkg", GlobOptions.MatchFullPath)) + .Where(x => !x.EndsWith("symbols.nupkg")) + .ForEach(file => + { + Log.Information("Pushing nuget from path: {0}", Directory_NuGet/file); + DotNetTasks + .DotNetNuGetPush(s => s + .SetTargetPath(Directory_NuGet/file) + .SetSource(NuGetApiUrl) + .SetApiKey(NuGetApiKey) + ); + }); + }); //Target CreateRelease => _ => _ // .DependsOn(Pack) diff --git a/Build/Build.csproj b/Build/Build.csproj index 48dd8e5b..8a1192c3 100644 --- a/Build/Build.csproj +++ b/Build/Build.csproj @@ -20,4 +20,28 @@ + + + + + + + + + + + + + + + + + + + + + + + +