Skip to content

Commit

Permalink
Move Nuget pushing from Yaml into Nuke
Browse files Browse the repository at this point in the history
  • Loading branch information
dennisdoomen committed Jan 16, 2022
1 parent ca0d5e1 commit 94d3491
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 18 deletions.
20 changes: 8 additions & 12 deletions .github/workflows/build.yml
Expand Up @@ -2,10 +2,10 @@ name: build

on:
pull_request:
paths-ignore:
paths-ignore:
- docs/**
push:
paths-ignore:
paths-ignore:
- docs/**

jobs:
Expand All @@ -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:
Expand All @@ -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 }}



6 changes: 6 additions & 0 deletions .nuke/build.schema.json
Expand Up @@ -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"
Expand Down Expand Up @@ -76,6 +80,7 @@
"Clean",
"Compile",
"Pack",
"Push",
"Restore",
"TestFrameworks",
"UnitTests"
Expand All @@ -97,6 +102,7 @@
"Clean",
"Compile",
"Pack",
"Push",
"Restore",
"TestFrameworks",
"UnitTests"
Expand Down
7 changes: 5 additions & 2 deletions Build/.editorconfig
Expand Up @@ -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
38 changes: 34 additions & 4 deletions Build/Build.cs
@@ -1,3 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Nuke.Common;
using Nuke.Common.Execution;
Expand All @@ -24,18 +26,25 @@ class Build : NukeBuild
- Microsoft VSCode https://nuke.build/vscode
*/

public static int Main() => Execute<Build>(x => x.Pack);
public static int Main() => Execute<Build>(x => x.Push);

[Parameter("A branch specification such as develop or refs/pull/1775/merge")]
readonly string BranchSpec;

[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";

Expand Down Expand Up @@ -172,4 +181,25 @@ class Build : NukeBuild
.EnableContinuousIntegrationBuild() // Necessary for deterministic builds
.SetVersion(SemVer));
});

Target Push => _ => _
.DependsOn(Pack)
.OnlyWhenDynamic(() => IsTag)
.Executes(() =>
{
var packages = GlobFiles(ArtifactsDirectory, "*.nupkg");
Assert.NotEmpty(packages.ToList());
DotNetNuGetPush(s => s
.SetApiKey(ApiKey)
.EnableSkipDuplicate()
.SetSource("https://api.nuget.org/v3/index.json")
.EnableNoSymbols()
.CombineWith(packages,
(v, path) => v.SetTargetPath(path)));
});

bool IsTag => BranchSpec != null && BranchSpec.Contains("refs/tags", StringComparison.InvariantCultureIgnoreCase);

}

0 comments on commit 94d3491

Please sign in to comment.