Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 58 additions & 1 deletion .github/nuke/build/Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
CacheKeyFiles = ["global.json", "**/*.csproj", "**/Directory.*.props"])]
// GitHub Actions workflow for releases
// Triggered when a new release is created, publishes NuGet packages
// Publishes to both NuGet.org and GitHub Packages
[GitHubActions(
"release",
GitHubActionsImage.UbuntuLatest,
Expand All @@ -48,6 +49,11 @@ class Build : NukeBuild
[Secret]
readonly string NuGetApiKey;

// GitHub token for publishing packages to GitHub Packages
[Parameter("GitHub Token for publishing packages")]
[Secret]
readonly string GitHubToken;

// Solution file reference
[Solution(GenerateProjects = true)]
readonly Solution Solution;
Expand Down Expand Up @@ -224,7 +230,7 @@ string GetVersion()

// Publish NuGet packages to NuGet.org
// Only runs on release builds with valid API key
Target Publish => _ => _
Target PublishToNuGet => _ => _
.DependsOn(Pack)
.Requires(() => !string.IsNullOrEmpty(NuGetApiKey))
.Requires(() => IsServerBuild)
Expand Down Expand Up @@ -252,6 +258,57 @@ string GetVersion()
Log.Information("Successfully published {Count} packages to NuGet.org", packages.Count());
});

// Publish NuGet packages to GitHub Packages
// Publishes to GitHub Container Registry (ghcr.io)
Target PublishToGitHub => _ => _
.DependsOn(Pack)
.Requires(() => IsServerBuild)
.Executes(() =>
{
// GitHub token is provided automatically by GitHub Actions
var token = GitHubToken ?? Environment.GetEnvironmentVariable("GITHUB_TOKEN");

if (string.IsNullOrEmpty(token))
{
Log.Warning("GitHub token not available, skipping GitHub Packages publish");
return;
}

Log.Information("Publishing NuGet packages to GitHub Packages");

var packages = PackagesDirectory.GlobFiles("*.nupkg")
.Where(x => !x.Name.EndsWith(".symbols.nupkg", StringComparison.OrdinalIgnoreCase));

if (!packages.Any())
{
throw new Exception("No packages found to publish");
}

// GitHub Packages NuGet feed URL
var githubSource = "https://nuget.pkg.github.com/AppifySheets/index.json";

// Push each package to GitHub Packages
DotNetNuGetPush(s => s
.SetSource(githubSource)
.SetApiKey(token)
// Skip duplicate packages (in case of retry)
.SetSkipDuplicate(true)
.CombineWith(packages, (settings, package) => settings
.SetTargetPath(package)));

Log.Information("Successfully published {Count} packages to GitHub Packages", packages.Count());
});

// Publish packages to all configured registries
// Combines publishing to NuGet.org and GitHub Packages
Target Publish => _ => _
.DependsOn(Pack)
.Triggers(PublishToNuGet, PublishToGitHub)
.Executes(() =>
{
Log.Information("Publishing packages to all configured registries");
});

// Helper target to display version information
Target ShowVersion => _ => _
.Executes(() =>
Expand Down
7 changes: 6 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@

name: release

on: [workflow_dispatch]
on:
# Manual workflow dispatch for testing
workflow_dispatch:
# Trigger when a new GitHub release is published
release:
types: [published]

jobs:
ubuntu-latest:
Expand Down
7 changes: 7 additions & 0 deletions .nuke/build.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
"Compile",
"Pack",
"Publish",
"PublishToGitHub",
"PublishToNuGet",
"Restore",
"ShowVersion",
"Test"
Expand Down Expand Up @@ -113,6 +115,11 @@
"Release"
]
},
"GitHubToken": {
"type": "string",
"description": "GitHub Token for publishing packages",
"default": "Secrets must be entered via 'nuke :secrets [profile]'"
},
"NuGetApiKey": {
"type": "string",
"description": "NuGet API Key for publishing packages",
Expand Down
Loading