Skip to content

Commit

Permalink
Only push nugets on tags
Browse files Browse the repository at this point in the history
  • Loading branch information
harry-cpp committed Nov 7, 2023
1 parent 7f8485e commit f3c66d9
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
1 change: 0 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ jobs:
ACTIONS_RUNTIME_TOKEN: ${{ env.ACTIONS_RUNTIME_TOKEN }}
ACTIONS_RUNTIME_URL: "${{ env.ACTIONS_RUNTIME_URL }}"
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
VERSION: 3.18.0
- name: Make a release
uses: ncipollo/release-action@v1
with:
Expand Down
6 changes: 5 additions & 1 deletion build/PackContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,21 @@ public class PackContext

public string Version { get; }

public bool IsTag { get; }

public PackContext(ICakeContext context)
{
LibraryName = context.Arguments("libraryname", "X").FirstOrDefault()!;
LicensePath = context.Arguments("licensepath", "").FirstOrDefault()!;
Version = "1.0.0";
IsTag = false;

if (context.BuildSystem().IsRunningOnGitHubActions)
{
RepositoryOwner = context.EnvironmentVariable("GITHUB_REPOSITORY_OWNER");
RepositoryUrl = $"https://github.com/{context.EnvironmentVariable("GITHUB_REPOSITORY")}";
Version = context.EnvironmentVariable("VERSION") + "." + context.EnvironmentVariable("GITHUB_RUN_NUMBER");
Version = context.EnvironmentVariable("GITHUB_REF_NAME");
IsTag = context.EnvironmentVariable("GITHUB_REF_TYPE") == "tag";
}
}
}
12 changes: 8 additions & 4 deletions build/Tasks/PublishPackageTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,15 @@ public override async Task RunAsync(BuildContext context)
foreach (var nugetPath in context.GetFiles("bin/Release/*.nupkg"))
{
await context.BuildSystem().GitHubActions.Commands.UploadArtifact(nugetPath, nugetPath.GetFilename().ToString());
context.DotNetNuGetPush(nugetPath, new()

if (context.PackContext.IsTag)
{
ApiKey = context.EnvironmentVariable("GITHUB_TOKEN"),
Source = $"https://nuget.pkg.github.com/{context.PackContext.RepositoryOwner}/index.json"
});
context.DotNetNuGetPush(nugetPath, new()
{
ApiKey = context.EnvironmentVariable("GITHUB_TOKEN"),
Source = $"https://nuget.pkg.github.com/{context.PackContext.RepositoryOwner}/index.json"
});
}
}
}
}
Expand Down

0 comments on commit f3c66d9

Please sign in to comment.