mirror of
https://github.com/actions/runner.git
synced 2026-04-13 02:48:06 +08:00
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;
|
||||
}
|
||||
|
||||
// Format: owner/repo/path/to/file.yml@ref
|
||||
// Format: owner/repo/.github/workflows/file.yml@ref
|
||||
var atIndex = workflowRef.IndexOf('@');
|
||||
var pathPart = atIndex >= 0 ? workflowRef.Substring(0, atIndex) : workflowRef;
|
||||
|
||||
// Split into owner/repo and file path at the .github/ boundary
|
||||
var githubDirIndex = pathPart.IndexOf("/.github/");
|
||||
if (githubDirIndex < 0)
|
||||
// Split at /.github/workflows/ to correctly handle repos named ".github"
|
||||
// e.g. "octo-org/.github/.github/workflows/ci.yml" → repo="octo-org/.github"
|
||||
var marker = "/.github/workflows/";
|
||||
var markerIndex = pathPart.IndexOf(marker);
|
||||
if (markerIndex < 0)
|
||||
{
|
||||
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(".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