-
Notifications
You must be signed in to change notification settings - Fork 185
Fix runtime-import path extraction for .github.io repositories #15826
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1111,3 +1111,112 @@ Test content.` | |
| t.Error("Found ANSI escape sequences in generated YAML file") | ||
| } | ||
| } | ||
|
|
||
| // TestRuntimeImportPathGitHubIO tests that repositories ending with .github.io | ||
| // generate correct runtime-import paths without duplicating the .github.io suffix | ||
| func TestRuntimeImportPathGitHubIO(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
| repoName string // simulated repo name in path | ||
| expected string | ||
| description string | ||
| }{ | ||
| { | ||
| name: "github_pages_repo", | ||
| repoName: "testuser.github.io", | ||
| expected: "{{#runtime-import .github/workflows/translate-to-ptbr.md}}", | ||
| description: "GitHub Pages repo should not duplicate .github.io in runtime-import path", | ||
| }, | ||
| { | ||
| name: "another_github_pages_repo", | ||
| repoName: "anotheruser.github.io", | ||
| expected: "{{#runtime-import .github/workflows/test.md}}", | ||
| description: "Another GitHub Pages repo should work correctly", | ||
| }, | ||
| { | ||
| name: "normal_repo", | ||
| repoName: "myrepo", | ||
| expected: "{{#runtime-import .github/workflows/workflow.md}}", | ||
| description: "Normal repo without .github.io should work as before", | ||
| }, | ||
| { | ||
| name: "repo_with_github_in_name", | ||
| repoName: "my-github-project", | ||
| expected: "{{#runtime-import .github/workflows/test.md}}", | ||
| description: "Repo with 'github' in name should only match .github directory", | ||
| }, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| // Create a temporary directory that simulates the repo structure | ||
| // with repo name in the path | ||
| tmpBase := testutil.TempDir(t, "runtime-import-path-test") | ||
| tmpDir := filepath.Join(tmpBase, tt.repoName) | ||
|
|
||
| // Create .github/workflows directory | ||
| workflowDir := filepath.Join(tmpDir, ".github", "workflows") | ||
| if err := os.MkdirAll(workflowDir, 0755); err != nil { | ||
| t.Fatalf("Failed to create workflow directory: %v", err) | ||
| } | ||
|
|
||
| // Determine workflow filename from expected path | ||
| expectedParts := strings.Split(tt.expected, " ") | ||
| if len(expectedParts) < 2 { | ||
| t.Fatalf("Invalid expected format: %s", tt.expected) | ||
| } | ||
| workflowFilePath := strings.TrimSuffix(expectedParts[1], "}}") | ||
| workflowBasename := filepath.Base(workflowFilePath) | ||
|
|
||
| // Create a simple workflow file | ||
| workflowPath := filepath.Join(workflowDir, workflowBasename) | ||
| workflowContent := `--- | ||
| on: push | ||
| engine: copilot | ||
| --- | ||
|
|
||
| # Test Workflow | ||
|
|
||
| This is a test workflow.` | ||
|
|
||
| if err := os.WriteFile(workflowPath, []byte(workflowContent), 0644); err != nil { | ||
| t.Fatalf("Failed to write workflow file: %v", err) | ||
| } | ||
|
|
||
| // Compile the workflow | ||
| compiler := NewCompiler() | ||
| if err := compiler.CompileWorkflow(workflowPath); err != nil { | ||
| t.Fatalf("%s: Compilation failed: %v", tt.description, err) | ||
|
Comment on lines
+1186
to
+1189
|
||
| } | ||
|
|
||
| // Calculate lock file path | ||
| lockFile := strings.TrimSuffix(workflowPath, ".md") + ".lock.yml" | ||
|
|
||
| // Read the generated lock file | ||
| lockContent, err := os.ReadFile(lockFile) | ||
| if err != nil { | ||
| t.Fatalf("Failed to read lock file: %v", err) | ||
| } | ||
|
|
||
| lockContentStr := string(lockContent) | ||
|
|
||
| // Check that the runtime-import path is correct | ||
| if !strings.Contains(lockContentStr, tt.expected) { | ||
| t.Errorf("%s: Expected to find '%s' in lock file", tt.description, tt.expected) | ||
|
|
||
| // Find what runtime-import was actually generated | ||
| lines := strings.Split(lockContentStr, "\n") | ||
| for _, line := range lines { | ||
| if strings.Contains(line, "{{#runtime-import") { | ||
| t.Logf("Found runtime-import: %s", strings.TrimSpace(line)) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // Also verify that .github.io is NOT duplicated in the path | ||
| if strings.Contains(lockContentStr, ".github.io/.github/workflows") { | ||
| t.Errorf("%s: Found incorrect path with duplicated .github.io prefix", tt.description) | ||
| } | ||
| }) | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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"),
githubIndexwill be -1 and this will fall back toworkflowBasename, 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/afterfilepath.ToSlash).