Skip to content

Commit

Permalink
build: add nuget publish (#36)
Browse files Browse the repository at this point in the history
* build: Add Nuget Publish

* adding publish yml
  • Loading branch information
RLittlesII authored Dec 27, 2020
1 parent 6d8d367 commit 70a91b0
Show file tree
Hide file tree
Showing 3 changed files with 150 additions and 17 deletions.
17 changes: 0 additions & 17 deletions .build/Build.cs
Original file line number Diff line number Diff line change
@@ -1,31 +1,14 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using JetBrains.Annotations;
using Nuke.Airframe;
using Nuke.Common;
using Nuke.Common.CI;
using Nuke.Common.CI.AzurePipelines;
using Nuke.Common.CI.GitHubActions;
using Nuke.Common.Execution;
using Nuke.Common.Git;
using Nuke.Common.Tools.DotNet;
using Nuke.Common.Tools.GitVersion;
using Nuke.Common.Tools.MSBuild;
using Rocket.Surgery.Nuke;
using Rocket.Surgery.Nuke.ContinuousIntegration;
using Rocket.Surgery.Nuke.DotNetCore;
using Rocket.Surgery.Nuke.GithubActions;
using Rocket.Surgery.Nuke.MsBuild;
using Rocket.Surgery.Nuke.Xamarin;
using Nuke.Common;
using Nuke.Common.IO;
using Nuke.Common.Tooling;
using Nuke.Common.Tools.DotNet;
using Nuke.Common.Utilities.Collections;
using static Nuke.Common.IO.FileSystemTasks;

[PublicAPI]
[CheckBuildProjectConfigurations]
Expand Down
86 changes: 86 additions & 0 deletions .build/Solution.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
using System.Collections.Generic;
using System.Linq;
using Nuke.Common.CI.GitHubActions;
using Rocket.Surgery.Nuke;
using Rocket.Surgery.Nuke.ContinuousIntegration;
using Rocket.Surgery.Nuke.DotNetCore;
using Rocket.Surgery.Nuke.GithubActions;

[GitHubActionsSteps("ci", GitHubActionsImage.MacOsLatest,
AutoGenerate = false,
On = new[] { GitHubActionsTrigger.Push },
OnPushTags = new[] { "v*" },
OnPushBranches = new[] { "master", "next", "feature/*" },
OnPullRequestBranches = new[] { "master", "next" },
InvokedTargets = new[] { nameof(Default) },
NonEntryTargets = new[]
{
nameof(ICIEnvironment.CIEnvironment),
nameof(ITriggerCodeCoverageReports.Trigger_Code_Coverage_Reports),
nameof(ITriggerCodeCoverageReports.Generate_Code_Coverage_Report_Cobertura),
nameof(IGenerateCodeCoverageBadges.Generate_Code_Coverage_Badges),
nameof(IGenerateCodeCoverageReport.Generate_Code_Coverage_Report),
nameof(IGenerateCodeCoverageSummary.Generate_Code_Coverage_Summary),
nameof(Default)
},
ExcludedTargets = new[] { nameof(ICanClean.Clean), nameof(ICanRestoreWithDotNetCore.DotnetToolRestore) },
Enhancements = new[] { nameof(Middleware) }
)]
[PrintBuildVersion, PrintCIEnvironment, UploadLogs]
public partial class Solution
{
public static RocketSurgeonGitHubActionsConfiguration Middleware(RocketSurgeonGitHubActionsConfiguration configuration)
{
var buildJob = configuration.Jobs.First(z => z.Name == "Build");
var checkoutStep = buildJob.Steps.OfType<CheckoutStep>().Single();
// For fetch all
checkoutStep.FetchDepth = 0;
buildJob.Steps.InsertRange(buildJob.Steps.IndexOf(checkoutStep) + 1, new BaseGitHubActionsStep[] {
new RunStep("Fetch all history for all tags and branches") {
Run = "git fetch --prune"
},
new SetupDotNetStep("Use .NET Core 3.1 SDK") {
DotNetVersion = "3.1.x"
}
});

buildJob.Steps.Add(new UsingStep("Publish Coverage")
{
Uses = "codecov/codecov-action@v1",
With = new Dictionary<string, string>
{
["name"] = "actions-${{ matrix.os }}",
}
});

buildJob.Steps.Add(new UploadArtifactStep("Publish logs")
{
Name = "logs",
Path = "artifacts/logs/",
If = "always()"
});

buildJob.Steps.Add(new UploadArtifactStep("Publish coverage data")
{
Name = "coverage",
Path = "coverage/",
If = "always()"
});

buildJob.Steps.Add(new UploadArtifactStep("Publish test data")
{
Name = "test data",
Path = "artifacts/test/",
If = "always()"
});

buildJob.Steps.Add(new UploadArtifactStep("Publish NuGet Packages")
{
Name = "nuget",
Path = "artifacts/nuget/",
If = "always()"
});

return configuration;
}
}
64 changes: 64 additions & 0 deletions .github/workflows/publish-nuget.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: Publish Nuget

on:
workflow_run:
workflows: ['ci']
types:
- completed

jobs:
publish:
runs-on: ubuntu-latest

steps:
- name: Dump GitHub context
env:
GITHUB_CONTEXT: ${{ toJson(github) }}
run: echo "$GITHUB_CONTEXT"

- uses: nuget/setup-nuget@v1
with:
nuget-version: '5.x'

- name: Download artifact
uses: dawidd6/action-download-artifact@v2
if: github.event.workflow_run.conclusion == 'success'
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
workflow: ci.yml
run_id: ${{ github.event.id }}
name: nuget

# - uses: actions/download-artifact@v2
# with:
# name: nuget

- name: nuget.org
# continue-on-error: true
if: (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main') && startsWith(github.event.workflow_run.head_branch, 'v') # this is the best approximation for a tag
env:
ApiKey: ${{ secrets.RSG_NUGET_API_KEY }}
shell: pwsh
run: |
dotnet nuget push **/*.nupkg --skip-duplicate -s nuget.org --api-key $ENV:ApiKey
dotnet nuget push **/*.snupkg --skip-duplicate -s nuget.org --api-key $ENV:ApiKey
- name: dev.azure.com
# continue-on-error: true
if: github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main'
env:
ApiKey: ${{ secrets.RSG_AZURE_DEVOPS }}
shell: pwsh
run: |
dotnet nuget add source https://rocketsurgeonsguild.pkgs.visualstudio.com/Libraries/_packaging/Packages/nuget/v3/index.json --store-password-in-clear-text --name LibrariesPackages --username azuredevops --password $ENV:ApiKey
dotnet nuget push **/*.nupkg --skip-duplicate --api-key azuredevops --source LibrariesPackages
- name: preview.dev.azure.com
# continue-on-error: true
if: github.ref != 'refs/heads/master' && github.ref != 'refs/heads/main'
env:
ApiKey: ${{ secrets.RSG_AZURE_DEVOPS }}
shell: pwsh
run: |
dotnet nuget add source https://rocketsurgeonsguild.pkgs.visualstudio.com/Libraries/_packaging/Preview/nuget/v3/index.json --store-password-in-clear-text --name LibrariesPreview --username azuredevops --password $ENV:ApiKey
dotnet nuget push **/*.nupkg --skip-duplicate --api-key azuredevops --source LibrariesPreview

0 comments on commit 70a91b0

Please sign in to comment.