Skip to content
Open
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
11 changes: 11 additions & 0 deletions src/Runner.Worker/ActionManifestManagerWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,17 @@ private GitHub.DistributedTask.Pipelines.ActionStepDefinitionReference ParseActi
};
}

// Self-repository reference: $/path/to/action
// Mirrors PipelineTemplateConverter.ConvertToStep, which folds any '@ref' into the path.
if (GitHub.DistributedTask.Pipelines.PipelineConstants.TryParseSelfRepository(uses, out var selfPath))
{
return new GitHub.DistributedTask.Pipelines.RepositoryPathReference
{
RepositoryType = GitHub.DistributedTask.Pipelines.PipelineConstants.SelfRepositoryAlias,
Path = selfPath
};
}

// Repository reference: owner/repo@ref or owner/repo/path@ref
var atIndex = uses.LastIndexOf('@');
string refPart = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1759,7 +1759,8 @@ private static IStep ConvertToStep(

if (!uses.Value.StartsWith(WorkflowTemplateConstants.DockerUriPrefix, StringComparison.Ordinal) &&
!uses.Value.StartsWith("./") &&
!uses.Value.StartsWith(".\\"))
!uses.Value.StartsWith(".\\") &&
!GitHub.DistributedTask.Pipelines.PipelineConstants.TryParseSelfRepository(uses.Value, out _))
{
var usesSegments = uses.Value.Split('@');
var pathSegments = usesSegments[0].Split(new[] { '/', '\\' }, StringSplitOptions.RemoveEmptyEntries);
Expand Down
37 changes: 37 additions & 0 deletions src/Test/L0/Worker/ActionManifestManagerL0.cs
Original file line number Diff line number Diff line change
Expand Up @@ -786,6 +786,43 @@ public void Load_ConditionalCompositeAction()
}
}

[Fact]
[Trait("Level", "L0")]
[Trait("Category", "Worker")]
public void Load_SelfRepositoryCompositeAction()
{
try
{
//Arrange
Setup();

var actionManifest = new ActionManifestManager();
actionManifest.Initialize(_hc);

//Act
var result = actionManifest.Load(_ec.Object, Path.Combine(TestUtil.GetTestDataPath(), "self_repository_composite_action.yml"));

//Assert
Assert.Equal("Self Repository Composite", result.Name);
Assert.Equal(ActionExecutionType.Composite, result.Execution.ExecutionType);

var composite = result.Execution as CompositeActionExecutionDataNew;
Assert.NotNull(composite);
Assert.Equal(6, composite.Steps.Count);

Assert.Equal("$/.github/actions/inventory-client", Assert.IsType<ActionStep>(composite.Steps[0]).Uses.Value);
Assert.Equal("$/actions/nested/composite", Assert.IsType<ActionStep>(composite.Steps[1]).Uses.Value);
Assert.Equal("$/foo@v1", Assert.IsType<ActionStep>(composite.Steps[2]).Uses.Value);

// No template errors should have been reported for the $/ steps
_ec.Verify(x => x.AddIssue(It.Is<Issue>(s => s.Message.Contains("Expected format")), It.IsAny<ExecutionContextLogOptions>()), Times.Never);
}
finally
{
Teardown();
}
}

[Fact]
[Trait("Level", "L0")]
[Trait("Category", "Worker")]
Expand Down
67 changes: 67 additions & 0 deletions src/Test/L0/Worker/ActionManifestParserComparisonL0.cs
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,73 @@ public void Load_BothParsersRejectInvalidExpressionContext()
}
}

[Fact]
[Trait("Level", "L0")]
[Trait("Category", "Worker")]
public void Load_SelfRepositoryReferences_BothParsersAgree()
{
try
{
// Arrange — regression test: '$/' self-repository references must be
// accepted by the new parser exactly like the legacy parser, otherwise
// green jobs emit spurious template errors.
Setup();
_ec.Object.Global.Variables.Set(Constants.Runner.Features.CompareWorkflowParser, "true");

var legacyManager = new ActionManifestManagerLegacy();
legacyManager.Initialize(_hc);
_hc.SetSingleton<IActionManifestManagerLegacy>(legacyManager);

var newManager = new ActionManifestManager();
newManager.Initialize(_hc);
_hc.SetSingleton<IActionManifestManager>(newManager);

var wrapper = new ActionManifestManagerWrapper();
wrapper.Initialize(_hc);

var manifestPath = Path.Combine(TestUtil.GetTestDataPath(), "self_repository_composite_action.yml");

// Act
var result = wrapper.Load(_ec.Object, manifestPath);

// Assert - no mismatch recorded between the two parsers
Assert.False(_ec.Object.Global.HasActionManifestMismatch);

Assert.NotNull(result);
Assert.Equal(ActionExecutionType.Composite, result.Execution.ExecutionType);

var compositeExecution = result.Execution as CompositeActionExecutionData;
Assert.NotNull(compositeExecution);
Assert.Equal(6, compositeExecution.Steps.Count);

// $/path resolves to the self-repository alias with the subpath preserved
var selfRepoRef = Assert.IsType<GitHub.DistributedTask.Pipelines.RepositoryPathReference>(compositeExecution.Steps[0].Reference);
Assert.Equal(GitHub.DistributedTask.Pipelines.PipelineConstants.SelfRepositoryAlias, selfRepoRef.RepositoryType);
Assert.Equal(".github/actions/inventory-client", selfRepoRef.Path);
Assert.Null(selfRepoRef.Name);
Assert.Null(selfRepoRef.Ref);

var nestedRef = Assert.IsType<GitHub.DistributedTask.Pipelines.RepositoryPathReference>(compositeExecution.Steps[1].Reference);
Assert.Equal(GitHub.DistributedTask.Pipelines.PipelineConstants.SelfRepositoryAlias, nestedRef.RepositoryType);
Assert.Equal("actions/nested/composite", nestedRef.Path);

// '$/foo@v1' — legacy folds the '@ref' into the path; the new parser must match
var withRefRef = Assert.IsType<GitHub.DistributedTask.Pipelines.RepositoryPathReference>(compositeExecution.Steps[2].Reference);
Assert.Equal(GitHub.DistributedTask.Pipelines.PipelineConstants.SelfRepositoryAlias, withRefRef.RepositoryType);
Assert.Equal("foo@v1", withRefRef.Path);

// Sanity: ordinary references are unaffected
var externalRef = Assert.IsType<GitHub.DistributedTask.Pipelines.RepositoryPathReference>(compositeExecution.Steps[3].Reference);
Assert.Equal("GitHub", externalRef.RepositoryType);
Assert.Equal("actions/checkout", externalRef.Name);
Assert.Equal("v4", externalRef.Ref);
}
finally
{
Teardown();
}
}

private string GetFullExceptionMessage(Exception ex)
{
var messages = new List<string>();
Expand Down
22 changes: 22 additions & 0 deletions src/Test/TestData/self_repository_composite_action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: 'Self Repository Composite'
description: 'Test composite action referencing actions in the same repository via $/'
runs:
using: "composite"
steps:
- uses: $/.github/actions/inventory-client
id: inventory

- uses: $/actions/nested/composite
id: nested

- uses: $/foo@v1
id: with-ref

- uses: actions/checkout@v4
id: external

- uses: ./local-action
id: local

- run: echo done
shell: bash