resolveWorkspaceRoot returns the workspace root directory given the path to a workflow markdown file. ImportPaths are relative to the workspace root (e.g. ".github/workflows/shared/foo.md"), so the workspace root is the directory that contains ".github/".
(markdownPath string)
| 1088 | // file. ImportPaths are relative to the workspace root (e.g. ".github/workflows/shared/foo.md"), |
| 1089 | // so the workspace root is the directory that contains ".github/". |
| 1090 | func resolveWorkspaceRoot(markdownPath string) string { |
| 1091 | normalized := filepath.ToSlash(markdownPath) |
| 1092 | if before, _, ok := strings.Cut(normalized, "/.github/"); ok { |
| 1093 | // Absolute or non-root-relative path: strip everything from "/.github/" onward. |
| 1094 | return filepath.FromSlash(before) |
| 1095 | } |
| 1096 | if strings.HasPrefix(normalized, constants.GithubDir) { |
| 1097 | // Path already starts at the workspace root. |
| 1098 | return "." |
| 1099 | } |
| 1100 | // Fallback: use the directory containing the workflow file. |
| 1101 | return filepath.Dir(markdownPath) |
| 1102 | } |