fix: use /.github/workflows/ marker for derivation parsing
Fixes incorrect parsing for repos named .github (e.g. octo-org/.github). The old /.github/ marker would match too early, deriving the wrong repository name. Also treats empty-string fields as unset during derivation.
This commit is contained in:
committed by
GitHub
parent
5806ab55db
commit
4342a1b8f0
@@ -159,25 +159,27 @@ namespace GitHub.Runner.Worker
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Format: owner/repo/path/to/file.yml@ref
|
// Format: owner/repo/.github/workflows/file.yml@ref
|
||||||
var atIndex = workflowRef.IndexOf('@');
|
var atIndex = workflowRef.IndexOf('@');
|
||||||
var pathPart = atIndex >= 0 ? workflowRef.Substring(0, atIndex) : workflowRef;
|
var pathPart = atIndex >= 0 ? workflowRef.Substring(0, atIndex) : workflowRef;
|
||||||
|
|
||||||
// Split into owner/repo and file path at the .github/ boundary
|
// Split at /.github/workflows/ to correctly handle repos named ".github"
|
||||||
var githubDirIndex = pathPart.IndexOf("/.github/");
|
// e.g. "octo-org/.github/.github/workflows/ci.yml" → repo="octo-org/.github"
|
||||||
if (githubDirIndex < 0)
|
var marker = "/.github/workflows/";
|
||||||
|
var markerIndex = pathPart.IndexOf(marker);
|
||||||
|
if (markerIndex < 0)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (WorkflowRepository == null)
|
if (WorkflowRepository == null || WorkflowRepository == "")
|
||||||
{
|
{
|
||||||
WorkflowRepository = pathPart.Substring(0, githubDirIndex);
|
WorkflowRepository = pathPart.Substring(0, markerIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (WorkflowFilePath == null)
|
if (WorkflowFilePath == null || WorkflowFilePath == "")
|
||||||
{
|
{
|
||||||
WorkflowFilePath = pathPart.Substring(githubDirIndex + 1); // skip leading '/'
|
WorkflowFilePath = pathPart.Substring(markerIndex + 1); // skip leading '/'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -194,5 +194,30 @@ namespace GitHub.Runner.Common.Tests.Worker
|
|||||||
Assert.Equal("my-org/my-repo", ctx.WorkflowRepository);
|
Assert.Equal("my-org/my-repo", ctx.WorkflowRepository);
|
||||||
Assert.Equal(".github/workflows/deploy.yml", ctx.WorkflowFilePath);
|
Assert.Equal(".github/workflows/deploy.yml", ctx.WorkflowFilePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void DeriveWorkflowRefComponents_HandlesDotGithubRepoName()
|
||||||
|
{
|
||||||
|
// Repos can be named ".github" — the marker must be /.github/workflows/ not /.github/
|
||||||
|
var ctx = new JobContext();
|
||||||
|
ctx.WorkflowRef = "octo-org/.github/.github/workflows/ci.yml@refs/heads/main";
|
||||||
|
ctx.DeriveWorkflowRefComponents();
|
||||||
|
|
||||||
|
Assert.Equal("octo-org/.github", ctx.WorkflowRepository);
|
||||||
|
Assert.Equal(".github/workflows/ci.yml", ctx.WorkflowFilePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void DeriveWorkflowRefComponents_TreatsEmptyStringAsUnset()
|
||||||
|
{
|
||||||
|
var ctx = new JobContext();
|
||||||
|
ctx.WorkflowRef = "my-org/my-repo/.github/workflows/deploy.yml@refs/heads/main";
|
||||||
|
ctx.WorkflowRepository = "";
|
||||||
|
ctx.WorkflowFilePath = "";
|
||||||
|
ctx.DeriveWorkflowRefComponents();
|
||||||
|
|
||||||
|
Assert.Equal("my-org/my-repo", ctx.WorkflowRepository);
|
||||||
|
Assert.Equal(".github/workflows/deploy.yml", ctx.WorkflowFilePath);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user