Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Environment tag in Github Actions #1389

Merged
merged 2 commits into from
Jul 3, 2024
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
6 changes: 5 additions & 1 deletion source/Nuke.Common.Tests/CI/ConfigurationGenerationTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using JetBrains.Annotations;
using Nuke.Common.CI;
using Nuke.Common.CI.AppVeyor;
using Nuke.Common.CI.AzurePipelines;
Expand Down Expand Up @@ -48,6 +49,7 @@ public static IEnumerable<object[]> GetAttributes()
return TestBuild.GetAttributes().Select(x => new object[] { x.TestName, x.Generator });
}

[UsedImplicitly(ImplicitUseTargetFlags.WithMembers)]
[AppVeyorSecret("GitHubToken", "encrypted-yaml")]
[TeamCityToken("GitHubToken", "74928d76-46e8-45cc-ad22-6438915ac070")]
public class TestBuild : NukeBuild
Expand Down Expand Up @@ -161,7 +163,9 @@ public class TestBuild : NukeBuild
TimeoutMinutes = 30,
ConcurrencyCancelInProgress = true,
JobConcurrencyCancelInProgress = true,
JobConcurrencyGroup = "custom-job-group"
JobConcurrencyGroup = "custom-job-group",
EnvironmentName = "environment-name",
EnvironmentUrl = "environment-url"
}
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public class GitHubActionsJob : ConfigurationEntity
public GitHubActionsImage Image { get; set; }
public int TimeoutMinutes { get; set; }
public string ConcurrencyGroup { get; set; }
public string EnvironmentName { get; set; }
public string EnvironmentUrl { get; set; }
public bool ConcurrencyCancelInProgress { get; set; }
public GitHubActionsStep[] Steps { get; set; }

Expand Down Expand Up @@ -56,6 +58,23 @@ public override void Write(CustomFileWriter writer)
}
}

if (!EnvironmentName.IsNullOrWhiteSpace())
{
if (EnvironmentUrl.IsNullOrWhiteSpace())
{
writer.WriteLine($"environment: {EnvironmentName}");
}
else
{
writer.WriteLine("environment:");
using (writer.Indent())
{
writer.WriteLine($"name: {EnvironmentName}");
writer.WriteLine($"url: {EnvironmentUrl}");
}
}
}

writer.WriteLine("steps:");
using (writer.Indent())
{
Expand Down
5 changes: 5 additions & 0 deletions source/Nuke.Common/CI/GitHubActions/GitHubActionsAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ public GitHubActionsAttribute(
public string PublishCondition { get; set; }

public int TimeoutMinutes { get; set; }

public string EnvironmentName { get; set; }
public string EnvironmentUrl { get; set; }

public string ConcurrencyGroup { get; set; }
public bool ConcurrencyCancelInProgress { get; set; }
Expand Down Expand Up @@ -147,6 +150,8 @@ protected virtual GitHubActionsJob GetJobs(GitHubActionsImage image, IReadOnlyCo
return new GitHubActionsJob
{
Name = image.GetValue().Replace(".", "_"),
EnvironmentName = EnvironmentName,
EnvironmentUrl = EnvironmentUrl,
Steps = GetSteps(image, relevantTargets).ToArray(),
Image = image,
TimeoutMinutes = TimeoutMinutes,
Expand Down
Loading