Skip to content

Commit

Permalink
Add NuGet/Feedz.io publish support
Browse files Browse the repository at this point in the history
  • Loading branch information
lahma committed Feb 17, 2024
1 parent 14e1864 commit 1ec6576
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 44 deletions.
42 changes: 6 additions & 36 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,47 +25,17 @@ on:
- 'v*.*.*'

jobs:
macos-latest:
name: macos-latest
runs-on: macos-latest
steps:
- uses: actions/checkout@v3
- name: 'Run: Compile, Test, Pack'
run: ./build.cmd Compile Test Pack
- name: 'Publish: test-results'
uses: actions/upload-artifact@v3
with:
name: test-results
path: artifacts/test-results
- name: 'Publish: packages'
uses: actions/upload-artifact@v3
with:
name: packages
path: artifacts/packages
ubuntu-latest:
name: ubuntu-latest
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: 'Run: Compile, Test, Pack'
run: ./build.cmd Compile Test Pack
- name: 'Publish: test-results'
uses: actions/upload-artifact@v3
with:
name: test-results
path: artifacts/test-results
- name: 'Publish: packages'
uses: actions/upload-artifact@v3
with:
name: packages
path: artifacts/packages
windows-latest:
name: windows-latest
runs-on: windows-latest
steps:
- uses: actions/checkout@v3
- name: 'Run: Compile, Test, Pack'
run: ./build.cmd Compile Test Pack
- name: 'Run: Compile, Test, Pack, Publish'
run: ./build.cmd Compile Test Pack Publish
env:
FeedzNuGetApiKey: ${{ secrets.FEEDZ_NUGET_API_KEY }}
PublicNuGetApiKey: ${{ secrets.PUBLIC_NUGET_API_KEY }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: 'Publish: test-results'
uses: actions/upload-artifact@v3
with:
Expand Down
10 changes: 10 additions & 0 deletions .nuke/build.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
"type": "boolean",
"description": "Indicates to continue a previously failed build attempt"
},
"FeedzNuGetApiKey": {
"type": "string",
"default": "Secrets must be entered via 'nuke :secrets [profile]'"
},
"Help": {
"type": "boolean",
"description": "Shows the help text for this build assembly"
Expand Down Expand Up @@ -65,6 +69,10 @@
"type": "string"
}
},
"PublicNuGetApiKey": {
"type": "string",
"default": "Secrets must be entered via 'nuke :secrets [profile]'"
},
"Root": {
"type": "string",
"description": "Root directory during build execution"
Expand All @@ -78,6 +86,7 @@
"Clean",
"Compile",
"Pack",
"Publish",
"Restore",
"Test"
]
Expand All @@ -96,6 +105,7 @@
"Clean",
"Compile",
"Pack",
"Publish",
"Restore",
"Test"
]
Expand Down
1 change: 1 addition & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<LangVersion>12</LangVersion>
<Nullable>enable</Nullable>
<WarningsAsErrors>nullable</WarningsAsErrors>
<VersionPrefix>0.1.0</VersionPrefix>
</PropertyGroup>

</Project>
8 changes: 4 additions & 4 deletions build/Build.CI.GitHubActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
]
[GitHubActions(
"build",
GitHubActionsImage.MacOsLatest,
GitHubActionsImage.UbuntuLatest,
GitHubActionsImage.WindowsLatest,
OnPushBranches = ["main", "master"],
OnPushTags = ["v*.*.*"],
PublishArtifacts = true,
InvokedTargets = [nameof(ICompile.Compile), nameof(ITest.Test), nameof(IPack.Pack)],
CacheKeyFiles = []
InvokedTargets = [nameof(ICompile.Compile), nameof(ITest.Test), nameof(IPack.Pack), nameof(IPublish.Publish)],
CacheKeyFiles = [],
EnableGitHubToken = true,
ImportSecrets = [nameof(FeedzNuGetApiKey), nameof(PublicNuGetApiKey)]
)
]
public partial class Build;
33 changes: 29 additions & 4 deletions build/Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System.Linq;
using Nuke.Common;
using Nuke.Common.CI;
using Nuke.Common.CI.GitHubActions;
using Nuke.Common.Git;
using Nuke.Common.IO;
using Nuke.Common.ProjectModel;
Expand All @@ -14,7 +13,7 @@
using Serilog;

[ShutdownDotNetAfterServerBuild]
partial class Build : NukeBuild, ITest, IPack
partial class Build : NukeBuild, IPublish
{
public static int Main() => Execute<Build>(x => ((ICompile) x).Compile);

Expand All @@ -31,6 +30,16 @@ partial class Build : NukeBuild, ITest, IPack
[Parameter]
string Version;

string PublicNuGetSource => "https://api.nuget.org/v3/index.json";
string FeedzNuGetSource => "https://f.feedz.io/acornima/acornima/nuget/index.json";

[Parameter] [Secret] readonly string PublicNuGetApiKey;
[Parameter] [Secret] readonly string FeedzNuGetApiKey;

bool IsPublicRelease => GitRepository.IsOnMainOrMasterBranch() && IsTaggedBuild;
string IPublish.NuGetSource => IsPublicRelease ? PublicNuGetSource : FeedzNuGetSource;
string IPublish.NuGetApiKey => IsPublicRelease ? PublicNuGetApiKey : FeedzNuGetApiKey;

protected override void OnBuildInitialized()
{
VersionSuffix = !IsTaggedBuild
Expand All @@ -41,6 +50,13 @@ protected override void OnBuildInitialized()
{
VersionSuffix = $"dev-{DateTime.UtcNow:yyyyMMdd-HHmm}";
}
else
{
if (IsTaggedBuild)
{
Version = TagVersion;
}
}

Log.Information("BUILD SETUP");
Log.Information("Configuration:\t{Configuration}", ((IHazConfiguration) this).Configuration);
Expand All @@ -60,7 +76,16 @@ protected override void OnBuildInitialized()

public IEnumerable<Project> TestProjects => ((IHazSolution) this).Solution.AllProjects.Where(x => x.Name.Contains("Tests"));

public Configure<DotNetTestSettings, Project> TestProjectSettings => (testSettings, _) => testSettings
.When(GitHubActions.Instance is not null, settings => settings.AddLoggers("GitHubActions;report-warnings=false"));

public Configure<DotNetBuildSettings> CompileSettings => _ => _
.SetVersion(Version)
.SetVersionSuffix(VersionSuffix);

public Configure<DotNetPublishSettings> PublishSettings => _ => _
.SetVersion(Version)
.SetVersionSuffix(VersionSuffix);

public Configure<DotNetPackSettings> PackSettings => _ => _
.SetVersion(Version)
.SetVersionSuffix(VersionSuffix);
}

0 comments on commit 1ec6576

Please sign in to comment.