Skip to content

Commit

Permalink
feat(cicd): add EnvironmentName and EnvironmentUrl to GitHubActionsAt…
Browse files Browse the repository at this point in the history
…tribute (#1389)
  • Loading branch information
stefandevo authored and matkoch committed Jul 3, 2024
1 parent fbb325b commit c9d6b88
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ jobs:
concurrency:
group: custom-job-group
cancel-in-progress: true
environment:
name: environment-name
url: environment-url
steps:
- uses: actions/checkout@v4
with:
Expand Down Expand Up @@ -101,6 +104,9 @@ jobs:
concurrency:
group: custom-job-group
cancel-in-progress: true
environment:
name: environment-name
url: environment-url
steps:
- uses: actions/checkout@v4
with:
Expand Down Expand Up @@ -146,6 +152,9 @@ jobs:
concurrency:
group: custom-job-group
cancel-in-progress: true
environment:
name: environment-name
url: environment-url
steps:
- uses: actions/checkout@v4
with:
Expand Down
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

0 comments on commit c9d6b88

Please sign in to comment.