Skip to content

Commit cb068cb

Browse files
committed
(GH-4891) Add missing GitHub Actions environment variables and XML documentation
Expose documented GitHub Actions default environment variables that were previously unavailable through the Cake provider, and improve API documentation with integration-inspired XML examples. - Add workflow properties: ActionRepository, ActorId, RepositoryId, RepositoryOwnerId, RetentionDays, TriggeringActor, WorkflowRef, and WorkflowSha - Add runner properties: IsDebug and Environment, with new GitHubActionsRunnerEnvironment enum - Extend GitHubActionsInfoFixture and unit tests for new workflow and runner properties - Add XML documentation examples to IGitHubActionsProvider, GitHubActionsCommands, GitHubActionsRunnerInfo, GitHubActionsRuntimeInfo, and GitHubActionsPullRequestInfo - Expand GitHub Actions integration step summary to exercise new environment properties on CI - fixes #4891
1 parent ddc3fce commit cb068cb

12 files changed

Lines changed: 1518 additions & 5 deletions

File tree

src/Cake.Common.Tests/Fixtures/Build/GitHubActionsInfoFixture.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,14 @@ public GitHubActionsInfoFixture()
3333
Environment.GetEnvironmentVariable("ImageOS").Returns("ubuntu20");
3434
Environment.GetEnvironmentVariable("ImageVersion").Returns("20211209.3");
3535
Environment.GetEnvironmentVariable("RUNNER_USER").Returns("runner");
36+
Environment.GetEnvironmentVariable("RUNNER_DEBUG").Returns("1");
37+
Environment.GetEnvironmentVariable("RUNNER_ENVIRONMENT").Returns("github-hosted");
3638

3739
Environment.GetEnvironmentVariable("GITHUB_ACTION").Returns("run1");
3840
Environment.GetEnvironmentVariable("GITHUB_ACTION_PATH").Returns("/path/to/action");
41+
Environment.GetEnvironmentVariable("GITHUB_ACTION_REPOSITORY").Returns("actions/checkout");
3942
Environment.GetEnvironmentVariable("GITHUB_ACTOR").Returns("dependabot");
43+
Environment.GetEnvironmentVariable("GITHUB_ACTOR_ID").Returns("1234567");
4044
Environment.GetEnvironmentVariable("GITHUB_API_URL").Returns("https://api.github.com");
4145
Environment.GetEnvironmentVariable("GITHUB_BASE_REF").Returns("master");
4246
Environment.GetEnvironmentVariable("GITHUB_EVENT_NAME").Returns("pull_request");
@@ -46,12 +50,18 @@ public GitHubActionsInfoFixture()
4650
Environment.GetEnvironmentVariable("GITHUB_JOB").Returns("job");
4751
Environment.GetEnvironmentVariable("GITHUB_REF").Returns("refs/pull/1/merge");
4852
Environment.GetEnvironmentVariable("GITHUB_REPOSITORY").Returns("cake-build/cake");
53+
Environment.GetEnvironmentVariable("GITHUB_REPOSITORY_ID").Returns("123456789");
4954
Environment.GetEnvironmentVariable("GITHUB_REPOSITORY_OWNER").Returns("cake-build");
55+
Environment.GetEnvironmentVariable("GITHUB_REPOSITORY_OWNER_ID").Returns("9876543");
56+
Environment.GetEnvironmentVariable("GITHUB_RETENTION_DAYS").Returns("90");
5057
Environment.GetEnvironmentVariable("GITHUB_RUN_ID").Returns("34058136");
5158
Environment.GetEnvironmentVariable("GITHUB_RUN_NUMBER").Returns("60");
5259
Environment.GetEnvironmentVariable("GITHUB_SERVER_URL").Returns("https://github.com");
5360
Environment.GetEnvironmentVariable("GITHUB_SHA").Returns("d1e4f990f57349334368c8253382abc63be02d73");
61+
Environment.GetEnvironmentVariable("GITHUB_TRIGGERING_ACTOR").Returns("octocat");
5462
Environment.GetEnvironmentVariable("GITHUB_WORKFLOW").Returns("Build");
63+
Environment.GetEnvironmentVariable("GITHUB_WORKFLOW_REF").Returns("cake-build/cake/.github/workflows/build.yml@refs/heads/main");
64+
Environment.GetEnvironmentVariable("GITHUB_WORKFLOW_SHA").Returns("a1b2c3d4e5f6789012345678901234567890abcd");
5565
Environment.GetEnvironmentVariable("GITHUB_WORKSPACE").Returns("/home/runner/work/cake/cake");
5666
Environment.GetEnvironmentVariable("GITHUB_RUN_ATTEMPT").Returns("2");
5767
Environment.GetEnvironmentVariable("GITHUB_REF_PROTECTED").Returns("true");
@@ -70,9 +80,11 @@ public GitHubActionsInfoFixture()
7080
Environment.Runtime.CakeVersion.Returns(CakeTestVersion);
7181
}
7282

73-
public GitHubActionsRunnerInfo CreateRunnerInfo(string architecture = null)
83+
public GitHubActionsRunnerInfo CreateRunnerInfo(string architecture = null, string debug = "1", string environment = "github-hosted")
7484
{
7585
Environment.GetEnvironmentVariable("RUNNER_ARCH").Returns(architecture);
86+
Environment.GetEnvironmentVariable("RUNNER_DEBUG").Returns(debug);
87+
Environment.GetEnvironmentVariable("RUNNER_ENVIRONMENT").Returns(environment);
7688
return new GitHubActionsRunnerInfo(Environment);
7789
}
7890

src/Cake.Common.Tests/Unit/Build/GitHubActions/Data/GitHubActionsRunnerInfoTests.cs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,5 +159,43 @@ public void Should_Return_Correct_Value(string value, GitHubActionsArchitecture
159159
Assert.Equal(expected, result);
160160
}
161161
}
162+
163+
public sealed class TheIsDebugProperty
164+
{
165+
[Theory]
166+
[InlineData("1", true)]
167+
[InlineData("", false)]
168+
[InlineData("true", false)]
169+
public void Should_Return_Correct_Value(string value, bool expected)
170+
{
171+
// Given
172+
var info = new GitHubActionsInfoFixture().CreateRunnerInfo(debug: value);
173+
174+
// When
175+
var result = info.IsDebug;
176+
177+
// Then
178+
Assert.Equal(expected, result);
179+
}
180+
}
181+
182+
public sealed class TheEnvironmentProperty
183+
{
184+
[Theory]
185+
[InlineData("github-hosted", GitHubActionsRunnerEnvironment.GitHubHosted)]
186+
[InlineData("self-hosted", GitHubActionsRunnerEnvironment.SelfHosted)]
187+
[InlineData("", GitHubActionsRunnerEnvironment.Unknown)]
188+
public void Should_Return_Correct_Value(string value, GitHubActionsRunnerEnvironment expected)
189+
{
190+
// Given
191+
var info = new GitHubActionsInfoFixture().CreateRunnerInfo(environment: value);
192+
193+
// When
194+
var result = info.Environment;
195+
196+
// Then
197+
Assert.Equal(expected, result);
198+
}
199+
}
162200
}
163201
}

src/Cake.Common.Tests/Unit/Build/GitHubActions/Data/GitHubActionsWorkflowInfoTests.cs

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,22 @@ public void Should_Return_Correct_Value()
4242
}
4343
}
4444

45+
public sealed class TheActionRepositoryProperty
46+
{
47+
[Fact]
48+
public void Should_Return_Correct_Value()
49+
{
50+
// Given
51+
var info = new GitHubActionsInfoFixture().CreateWorkflowInfo();
52+
53+
// When
54+
var result = info.ActionRepository;
55+
56+
// Then
57+
Assert.Equal("actions/checkout", result);
58+
}
59+
}
60+
4561
public sealed class TheActorProperty
4662
{
4763
[Fact]
@@ -58,6 +74,22 @@ public void Should_Return_Correct_Value()
5874
}
5975
}
6076

77+
public sealed class TheActorIdProperty
78+
{
79+
[Fact]
80+
public void Should_Return_Correct_Value()
81+
{
82+
// Given
83+
var info = new GitHubActionsInfoFixture().CreateWorkflowInfo();
84+
85+
// When
86+
var result = info.ActorId;
87+
88+
// Then
89+
Assert.Equal("1234567", result);
90+
}
91+
}
92+
6193
public sealed class TheApiUrlProperty
6294
{
6395
[Fact]
@@ -202,6 +234,22 @@ public void Should_Return_Correct_Value()
202234
}
203235
}
204236

237+
public sealed class TheRepositoryIdProperty
238+
{
239+
[Fact]
240+
public void Should_Return_Correct_Value()
241+
{
242+
// Given
243+
var info = new GitHubActionsInfoFixture().CreateWorkflowInfo();
244+
245+
// When
246+
var result = info.RepositoryId;
247+
248+
// Then
249+
Assert.Equal("123456789", result);
250+
}
251+
}
252+
205253
public sealed class TheRepositoryOwnerProperty
206254
{
207255
[Fact]
@@ -218,6 +266,38 @@ public void Should_Return_Correct_Value()
218266
}
219267
}
220268

269+
public sealed class TheRepositoryOwnerIdProperty
270+
{
271+
[Fact]
272+
public void Should_Return_Correct_Value()
273+
{
274+
// Given
275+
var info = new GitHubActionsInfoFixture().CreateWorkflowInfo();
276+
277+
// When
278+
var result = info.RepositoryOwnerId;
279+
280+
// Then
281+
Assert.Equal("9876543", result);
282+
}
283+
}
284+
285+
public sealed class TheRetentionDaysProperty
286+
{
287+
[Fact]
288+
public void Should_Return_Correct_Value()
289+
{
290+
// Given
291+
var info = new GitHubActionsInfoFixture().CreateWorkflowInfo();
292+
293+
// When
294+
var result = info.RetentionDays;
295+
296+
// Then
297+
Assert.Equal(90, result);
298+
}
299+
}
300+
221301
public sealed class TheRunIdProperty
222302
{
223303
[Fact]
@@ -282,6 +362,22 @@ public void Should_Return_Correct_Value()
282362
}
283363
}
284364

365+
public sealed class TheTriggeringActorProperty
366+
{
367+
[Fact]
368+
public void Should_Return_Correct_Value()
369+
{
370+
// Given
371+
var info = new GitHubActionsInfoFixture().CreateWorkflowInfo();
372+
373+
// When
374+
var result = info.TriggeringActor;
375+
376+
// Then
377+
Assert.Equal("octocat", result);
378+
}
379+
}
380+
285381
public sealed class TheWorkflowProperty
286382
{
287383
[Fact]
@@ -298,6 +394,38 @@ public void Should_Return_Correct_Value()
298394
}
299395
}
300396

397+
public sealed class TheWorkflowRefProperty
398+
{
399+
[Fact]
400+
public void Should_Return_Correct_Value()
401+
{
402+
// Given
403+
var info = new GitHubActionsInfoFixture().CreateWorkflowInfo();
404+
405+
// When
406+
var result = info.WorkflowRef;
407+
408+
// Then
409+
Assert.Equal("cake-build/cake/.github/workflows/build.yml@refs/heads/main", result);
410+
}
411+
}
412+
413+
public sealed class TheWorkflowShaProperty
414+
{
415+
[Fact]
416+
public void Should_Return_Correct_Value()
417+
{
418+
// Given
419+
var info = new GitHubActionsInfoFixture().CreateWorkflowInfo();
420+
421+
// When
422+
var result = info.WorkflowSha;
423+
424+
// Then
425+
Assert.Equal("a1b2c3d4e5f6789012345678901234567890abcd", result);
426+
}
427+
}
428+
301429
public sealed class TheWorkspaceProperty
302430
{
303431
[Fact]

0 commit comments

Comments
 (0)