Fix runtime-import path extraction for .github.io repositories#15826
Fix runtime-import path extraction for .github.io repositories#15826
Conversation
- Add test cases for repositories ending with .github.io - Fix path extraction to match /.github/ directory instead of substring - Normalize path separators before searching for .github directory - Prevents incorrect paths like .github.io/.github/workflows/file.md Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
|
@copilot recompile |
Recompiled all 154 workflows successfully. No lock file changes were needed since the fix only affects repositories with The fix has been tested and verified to:
Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
pkg/workflow/compiler_yaml_test.go
Outdated
| }{ | ||
| { | ||
| name: "github_pages_repo", | ||
| repoName: "samueltauil.github.io", |
Replace real username 'samueltauil' with generic 'testuser' and 'username' with 'anotheruser' in TestRuntimeImportPathGitHubIO test cases Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Fixes incorrect runtime-import path extraction when compiling workflows in repositories whose names include .github substrings (notably *.github.io), by switching to a directory-component match for /.github/. Adds a focused unit test to cover GitHub Pages-style repository paths.
Changes:
- Update runtime-import path extraction to match the
/.github/directory component (after normalizing path separators). - Add
TestRuntimeImportPathGitHubIOto validate correct runtime-import path generation for*.github.ioand similar repo names.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| pkg/workflow/compiler_yaml.go | Adjusts runtime-import path extraction logic to avoid substring matches like .github.io. |
| pkg/workflow/compiler_yaml_test.go | Adds regression tests for runtime-import path generation in .github.io repo paths. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| workflowFilePath = workflowBasename | ||
| } | ||
| // +1 to skip the leading slash, so we get ".github/workflows/..." not "/.github/workflows/..." | ||
| workflowFilePath = normalizedPath[githubIndex+1:] |
There was a problem hiding this comment.
The new pattern search only matches paths containing "/.github/" (with a leading slash). If the compiler is invoked with a repository-relative path like ".github/workflows/test.md" (common in CLI flows that glob ".github/workflows/*.md"), githubIndex will be -1 and this will fall back to workflowBasename, producing a runtime-import like {{#runtime-import test.md}} instead of .github/workflows/test.md.
Suggested fix: support .github/ at the start of the normalized path (and optionally ./.github/) in addition to matching /.github/ as a directory boundary (e.g., match (^|/)\.github/ after filepath.ToSlash).
| workflowFilePath = normalizedPath[githubIndex+1:] | |
| workflowFilePath = normalizedPath[githubIndex+1:] | |
| } else if strings.HasPrefix(normalizedPath, ".github/") { | |
| // Handle repository-relative paths like ".github/workflows/test.md" | |
| workflowFilePath = normalizedPath | |
| } else if strings.HasPrefix(normalizedPath, "./.github/") { | |
| // Handle repository-relative paths with leading "./", like "./.github/workflows/test.md" | |
| // Strip the leading "./" so the runtime-import path starts with ".github/" | |
| workflowFilePath = normalizedPath[2:] |
| // Compile the workflow | ||
| compiler := NewCompiler() | ||
| if err := compiler.CompileWorkflow(workflowPath); err != nil { | ||
| t.Fatalf("%s: Compilation failed: %v", tt.description, err) |
There was a problem hiding this comment.
This test only exercises compilation when workflowPath is an absolute path (TempDir + filepath.Join). Since the runtime-import extraction logic depends on how c.markdownPath is formatted, it would be good to add a subtest that compiles the same workflow via a repo-relative path like ".github/workflows/.md" (e.g., os.Chdir(tmpDir) then call CompileWorkflow with the relative path). That would guard against regressions in CLI code paths that pass relative paths.
Plan: Fix runtime-import path generation for .github.io repos
Issue Analysis
When compiling workflows in repositories ending with
.github.io(e.g.,username.github.io), the runtime-import path incorrectly includes.github.ioprefix.Root Cause: Line 325 of
pkg/workflow/compiler_yaml.gousesstrings.Index(c.markdownPath, ".github")which matches.github.ioin the repo path before matching the actual.github/workflowsdirectory.Example:
/home/user/username.github.io/.github/workflows/test.md.githubat position after username, extracts.github.io/.github/workflows/test.md.githubat the directory level, extract.github/workflows/test.mdImplementation Plan
/.github/directory instead of substringChanges Made
Test Added (
pkg/workflow/compiler_yaml_test.go):TestRuntimeImportPathGitHubIO: Tests 4 scenarios including .github.io reposFix Applied (
pkg/workflow/compiler_yaml.go):strings.Index(c.markdownPath, ".github")tostrings.Index(normalizedPath, "/.github/").github/onwards (without leading slash)Testing Results
✅ All unit tests pass
✅ Linting passes
✅ Formatting passes
✅ Manual testing confirms fix:
testuser.github.io→{{#runtime-import .github/workflows/translate-to-ptbr.md}}✓{{#runtime-import .github/workflows/test.md}}✓.github.io/.github/workflows/duplication ✓Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.
✨ PR Review Safe Output Test - Run 22027664548