From a299f153e114c526b01973d3dbb35035ec4c8ff1 Mon Sep 17 00:00:00 2001 From: Dennis Doomen Date: Sun, 16 Jan 2022 14:27:50 +0100 Subject: [PATCH] Move Nuget pushing from Yaml into Nuke --- .github/workflows/build.yml | 20 ++++++++------------ .nuke/build.schema.json | 6 ++++++ Build/.editorconfig | 7 +++++-- Build/Build.cs | 36 ++++++++++++++++++++++++++++++++---- 4 files changed, 51 insertions(+), 18 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index d86031f9ab..890a5ff95e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -2,10 +2,10 @@ name: build on: pull_request: - paths-ignore: + paths-ignore: - docs/** push: - paths-ignore: + paths-ignore: - docs/** jobs: @@ -17,17 +17,17 @@ jobs: - uses: actions/checkout@v2 with: fetch-depth: 0 - + - name: Setup .NET 5 uses: actions/setup-dotnet@v1 with: dotnet-version: 5.0.x - + - name: Setup .NET 3.1 uses: actions/setup-dotnet@v1 with: dotnet-version: 3.1.x - + - name: Setup .NET 2.1 uses: actions/setup-dotnet@v1 with: @@ -38,15 +38,11 @@ jobs: env: BranchSpec: ${{ github.ref }} BuildNumber: ${{ github.run_number}} + ApiKey: ${{ secrets.NUGETAPIKEY }} - name: Upload artifacts uses: actions/upload-artifact@v2 with: path: ./Artifacts/* - - - name: Push to Nuget - run: dotnet nuget push .\artifacts\*.nupkg --api-key "$env:ApiKey" --skip-duplicate --no-symbols true --source https://api.nuget.org/v3/index.json - if: contains(github.ref, 'refs/tags/') - env: - ApiKey: ${{ secrets.NUGETAPIKEY }} - + + diff --git a/.nuke/build.schema.json b/.nuke/build.schema.json index 813d3f4446..e85daa3006 100644 --- a/.nuke/build.schema.json +++ b/.nuke/build.schema.json @@ -6,6 +6,10 @@ "build": { "type": "object", "properties": { + "ApiKey": { + "type": "string", + "description": "The key to push to Nuget" + }, "BranchSpec": { "type": "string", "description": "A branch specification such as develop or refs/pull/1775/merge" @@ -76,6 +80,7 @@ "Clean", "Compile", "Pack", + "Push", "Restore", "TestFrameworks", "UnitTests" @@ -97,6 +102,7 @@ "Clean", "Compile", "Pack", + "Push", "Restore", "TestFrameworks", "UnitTests" diff --git a/Build/.editorconfig b/Build/.editorconfig index 21da7492e9..5641e0f6df 100644 --- a/Build/.editorconfig +++ b/Build/.editorconfig @@ -9,5 +9,8 @@ csharp_style_expression_bodied_properties = true:warning csharp_style_expression_bodied_indexers = true:warning csharp_style_expression_bodied_accessors = true:warning -dotnet_diagnostic.IDE0044.severity = none -dotnet_diagnostic.IDE0051.severity = none +dotnet_diagnostic.ide0044.severity = none +dotnet_diagnostic.ide0051.severity = none + +# ReSharper properties +resharper_place_field_attribute_on_same_line = false diff --git a/Build/Build.cs b/Build/Build.cs index 22cc7c0cf7..1063e96181 100644 --- a/Build/Build.cs +++ b/Build/Build.cs @@ -1,3 +1,5 @@ +using System; +using System.Collections.Generic; using System.Linq; using Nuke.Common; using Nuke.Common.Execution; @@ -24,7 +26,7 @@ class Build : NukeBuild - Microsoft VSCode https://nuke.build/vscode */ - public static int Main() => Execute(x => x.Pack); + public static int Main() => Execute(x => x.Push); [Parameter("A branch specification such as develop or refs/pull/1775/merge")] readonly string BranchSpec; @@ -32,10 +34,17 @@ class Build : NukeBuild [Parameter("An incrementing build number as provided by the build engine")] readonly string BuildNumber; + [Parameter("The key to push to Nuget")] + readonly string ApiKey; - [Solution(GenerateProjects = true)] readonly Solution Solution; - [GitVersion(Framework = "net5.0")] readonly GitVersion GitVersion; - [PackageExecutable("nspec", "NSpecRunner.exe", Version = "3.1.0")] Tool NSpec3; + [Solution(GenerateProjects = true)] + readonly Solution Solution; + + [GitVersion(Framework = "net5.0")] + readonly GitVersion GitVersion; + + [PackageExecutable("nspec", "NSpecRunner.exe", Version = "3.1.0")] + Tool NSpec3; AbsolutePath ArtifactsDirectory => RootDirectory / "Artifacts"; @@ -172,4 +181,23 @@ class Build : NukeBuild .EnableContinuousIntegrationBuild() // Necessary for deterministic builds .SetVersion(SemVer)); }); + + Target Push => _ => _ + .DependsOn(Pack) + .OnlyWhenDynamic(() => IsTag) + .Executes(() => + { + var packages = GlobFiles(ArtifactsDirectory, "*.nupkg"); + + DotNetNuGetPush(s => s + .SetApiKey(ApiKey) + .EnableSkipDuplicate() + .SetSource("https://api.nuget.org") + .EnableNoSymbols() + .CombineWith(packages, + (v, path) => v.SetTargetPath(path))); + }); + + bool IsTag => BranchSpec != null && BranchSpec.Contains("refs/tags", StringComparison.InvariantCultureIgnoreCase); + }