Skip to content

Commit

Permalink
try and fix nugetpublish
Browse files Browse the repository at this point in the history
  • Loading branch information
david-driscoll committed Dec 18, 2024
1 parent 66d89d9 commit 79b7081
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .build/Build.CI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
[CloseMilestoneJob]
[DraftReleaseJob]
[UpdateMilestoneJob]
[PublishNugetPackagesJob("RSG_NUGET_API_KEY", "ci", [])]
[PublishNugetPackagesJob("RSG_NUGET_API_KEY", "ci")]
[GitHubActionsVariable("THIS_IS_A_VARIABLE", Alias = "ThisIsAOtherVariable")]
[GitHubActionsVariable("THIS_IS_ANOTHER_VARIABLE")]
[GitHubActionsInput("THIS_IS_A_INPUT" /*, Alias = "ThisIsAInput"*/)]
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish-nuget.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ jobs:
- name: nuget.org
env:
ApiKey: '${{ secrets.RSG_NUGET_API_KEY }}'
if: startsWith(github.ref, 'refs/tags/')
if: startsWith(github.event.workflow_run.head_branch, 'v') && contains(github.event.workflow_run.head_branch, '.') && !contains(github.event.workflow_run.head_branch, '/')
shell: pwsh
run: |
dotnet nuget push **/*.nupkg --skip-duplicate -s nuget.org --api-key $ENV:ApiKey
Expand Down
28 changes: 18 additions & 10 deletions src/Nuke/GithubActions/GithubActionCondition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,20 @@ namespace Rocket.Surgery.Nuke.GithubActions;
/// <summary>
/// Defines an action condition
/// </summary>
/// <remarks>
/// The default constructor
/// </remarks>
/// <param name="condition"></param>
[PublicAPI]
public class GithubActionCondition
[System.Diagnostics.DebuggerDisplay("{DebuggerDisplay,nq}")]
public class GithubActionCondition(string condition)
{
/// <summary>
/// Convert the condition expression to a string.
/// </summary>
/// <param name="condition"></param>
/// <returns></returns>
public static implicit operator string?(GithubActionCondition? condition) => condition?.Condition;
public static implicit operator string(GithubActionCondition condition) => condition.Condition;

/// <summary>
/// Convert an expression string into a GithubActionCondition
Expand Down Expand Up @@ -41,17 +46,20 @@ public class GithubActionCondition
/// </summary>
public static GithubActionCondition Failure { get; } = new("failure()");

/// <summary>
/// The default constructor
/// </summary>
/// <param name="condition"></param>
public GithubActionCondition(string condition) => Condition = condition;

/// <summary>
/// The condition expression
/// </summary>
public string? Condition { get; }
public string Condition { get; } = condition;

[System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
private string DebuggerDisplay
{
get
{
return ToString();
}
}

/// <inheritdoc />
public override string? ToString() => Condition;
public override string ToString() => Condition;
}
14 changes: 8 additions & 6 deletions src/Nuke/Jobs/PublishNugetPackagesJobAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ public sealed class PublishNugetPackagesJobAttribute : GitHubActionsStepsAttribu
{
private readonly string _secretKey;
private readonly string _triggeringWorkflow;
private readonly GithubActionCondition _nugetOrgCondition;

private readonly GithubActionCondition _nugetOrgCondition =
"startsWith(github.event.workflow_run.head_branch, 'v') && contains(github.event.workflow_run.head_branch, '.') && !contains(github.event.workflow_run.head_branch, '/')";
private readonly ImmutableArray<string> _includeBranches;

/// <summary>
Expand All @@ -29,8 +31,8 @@ public PublishNugetPackagesJobAttribute(string secretKey, string triggeringWorkf
{
_secretKey = secretKey;
_triggeringWorkflow = triggeringWorkflow;
_nugetOrgCondition = nugetOrgCondition ?? "startsWith(github.ref, 'refs/tags/')";
_includeBranches = [.. includeBranches ?? ["master", "main", "v*"]];
_nugetOrgCondition = nugetOrgCondition ?? _nugetOrgCondition;
_includeBranches = [.. includeBranches ?? Array.Empty<string>()];
}

/// <summary>
Expand All @@ -40,7 +42,7 @@ public PublishNugetPackagesJobAttribute(string secretKey, string triggeringWorkf
{
_secretKey = secretKey;
_triggeringWorkflow = triggeringWorkflow;
_nugetOrgCondition = nugetOrgCondition ?? "startsWith(github.ref, 'refs/tags/')";
_nugetOrgCondition = nugetOrgCondition ?? _nugetOrgCondition;
_includeBranches = [.. includeBranches];
}

Expand All @@ -51,8 +53,8 @@ public PublishNugetPackagesJobAttribute(string secretKey, string triggeringWorkf
{
_secretKey = secretKey;
_triggeringWorkflow = triggeringWorkflow;
_nugetOrgCondition = nugetOrgCondition ?? "startsWith(github.ref, 'refs/tags/')";
_includeBranches = [.. includeBranches ?? ["master", "main", "v*"]];
_nugetOrgCondition = nugetOrgCondition ?? _nugetOrgCondition;
_includeBranches = [.. includeBranches ?? Array.Empty<string>()];
}

private string DebuggerDisplay => ToString();
Expand Down

0 comments on commit 79b7081

Please sign in to comment.