Skip to content

Commit

Permalink
added support for workflow call in github actions (#823)
Browse files Browse the repository at this point in the history
  • Loading branch information
david-driscoll authored Jan 15, 2023
1 parent b93b037 commit e68a6ea
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 13 deletions.
8 changes: 6 additions & 2 deletions .build/Build.CI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
GitHubActionsImage.WindowsLatest,
GitHubActionsImage.UbuntuLatest,
AutoGenerate = false,
On = new[] { GitHubActionsTrigger.Push },
On = new[] { RocketSurgeonGitHubActionsTrigger.Push },
OnPushTags = new[] { "v*" },
OnPushBranches = new[] { "master", "main", "next" },
OnPullRequestBranches = new[] { "master", "main", "next" },
Expand All @@ -23,7 +23,11 @@
GitHubActionsImage.WindowsLatest,
GitHubActionsImage.UbuntuLatest,
AutoGenerate = false,
On = new[] { GitHubActionsTrigger.WorkflowDispatch },
On = new[]
{
RocketSurgeonGitHubActionsTrigger.WorkflowCall,
RocketSurgeonGitHubActionsTrigger.WorkflowDispatch
},
OnPushTags = new[] { "v*" },
OnPushBranches = new[] { "master", "main", "next" },
OnPullRequestBranches = new[] { "master", "main", "next" },
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ name: ci

on:
workflow_dispatch:
workflow_call:
push:
branches:
- 'master'
Expand Down
18 changes: 13 additions & 5 deletions src/Nuke/GithubActions/GitHubActionsStepsAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ protected GithubActionsStepsAttributeBase(string name)
/// <summary>
/// The triggers
/// </summary>
public GitHubActionsTrigger[] On { get; set; } = Array.Empty<GitHubActionsTrigger>();
public RocketSurgeonGitHubActionsTrigger[] On { get; set; } = Array.Empty<RocketSurgeonGitHubActionsTrigger>();

/// <summary>
/// The branches to run for push
Expand Down Expand Up @@ -176,11 +176,19 @@ public override CustomFileWriter CreateWriter(StreamWriter streamWriter)
/// <returns></returns>
protected virtual IEnumerable<GitHubActionsDetailedTrigger> GetTriggers()
{
if (On.Any(z => z == GitHubActionsTrigger.WorkflowDispatch))
if (On.Any(z => z == RocketSurgeonGitHubActionsTrigger.WorkflowDispatch))
{
yield return new RocketSurgeonGitHubActionsVcsTrigger
{
Kind = GitHubActionsTrigger.WorkflowDispatch
Kind = RocketSurgeonGitHubActionsTrigger.WorkflowDispatch
};
}

if (On.Any(z => z == RocketSurgeonGitHubActionsTrigger.WorkflowCall))
{
yield return new RocketSurgeonGitHubActionsVcsTrigger
{
Kind = RocketSurgeonGitHubActionsTrigger.WorkflowCall
};
}

Expand All @@ -191,7 +199,7 @@ protected virtual IEnumerable<GitHubActionsDetailedTrigger> GetTriggers()
{
yield return new RocketSurgeonGitHubActionsVcsTrigger
{
Kind = GitHubActionsTrigger.Push,
Kind = RocketSurgeonGitHubActionsTrigger.Push,
Branches = OnPushBranches,
Tags = OnPushTags,
IncludePaths = OnPushIncludePaths,
Expand All @@ -206,7 +214,7 @@ protected virtual IEnumerable<GitHubActionsDetailedTrigger> GetTriggers()
{
yield return new RocketSurgeonGitHubActionsVcsTrigger
{
Kind = GitHubActionsTrigger.PullRequest,
Kind = RocketSurgeonGitHubActionsTrigger.PullRequest,
Branches = OnPullRequestBranches,
Tags = OnPullRequestTags,
IncludePaths = OnPullRequestIncludePaths,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Nuke.Common.CI;
using Nuke.Common.CI.GitHubActions;
using Nuke.Common.CI.GitHubActions.Configuration;
using Nuke.Common.Tooling;

Expand All @@ -22,7 +21,7 @@ public class RocketSurgeonGitHubActionsConfiguration : ConfigurationEntity
/// <summary>
/// The short triggers
/// </summary>
public List<GitHubActionsTrigger> ShortTriggers { get; set; } = new();
public List<RocketSurgeonGitHubActionsTrigger> ShortTriggers { get; set; } = new();

/// <summary>
/// The detailed triggers
Expand Down
16 changes: 12 additions & 4 deletions src/Nuke/GithubActions/RocketSurgeonGitHubActionsVcsTrigger.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
using Nuke.Common.CI.GitHubActions;
using Nuke.Common.CI.GitHubActions.Configuration;
using Nuke.Common.CI.GitHubActions.Configuration;
using Nuke.Common.Tooling;
using Nuke.Common.Utilities.Collections;

#pragma warning disable CA1819
namespace Rocket.Surgery.Nuke.GithubActions;

[PublicAPI]
public enum RocketSurgeonGitHubActionsTrigger
{
[EnumValue("push")] Push,
[EnumValue("pull_request")] PullRequest,
[EnumValue("workflow_dispatch")] WorkflowDispatch,
[EnumValue("workflow_call")] WorkflowCall
}

/// <summary>
/// A detailed trigger for version control
/// </summary>
Expand All @@ -14,7 +22,7 @@ public class RocketSurgeonGitHubActionsVcsTrigger : GitHubActionsDetailedTrigger
/// <summary>
/// The kind of the trigger
/// </summary>
public GitHubActionsTrigger Kind { get; set; }
public RocketSurgeonGitHubActionsTrigger Kind { get; set; }

/// <summary>
/// The branches
Expand All @@ -41,7 +49,7 @@ public override void Write(CustomFileWriter writer)
{
writer.WriteLine(Kind.GetValue() + ":");

if (Kind == GitHubActionsTrigger.WorkflowDispatch) return;
if (Kind is RocketSurgeonGitHubActionsTrigger.WorkflowDispatch or RocketSurgeonGitHubActionsTrigger.WorkflowCall) return;
using (writer.Indent())
{
if (Branches.Length > 0)
Expand Down

0 comments on commit e68a6ea

Please sign in to comment.