Repository navigation
Description
Summary
gh aw update 3-way merges an installed workflow correctly, then re-serializes the whole frontmatter from a map. Every YAML comment is dropped, keys are reordered by PriorityWorkflowFields, and lists are reflowed. In our case the upstream change was 30 lines across 9 workflows, and the resulting diff was about 1,200 lines. The merged result compiles and runs the same, but the explanatory comments that installed workflows carry are lost on every update. This only happens when the merge has no conflicts; the conflict path keeps the text.
Root cause
pkg/cli/update_merge.go (same in v1.0.1 and main at 0c48a33):
- Line 245, no-conflict path:
processIncludesInContent(mergedStr, ...). - That calls
processImportsWithWorkflowSpec(pkg/cli/imports.go:40). Whenever the frontmatter hasimports:, it parses the frontmatter into a map, rewrites import paths, and at line 158 re-marshals the entire frontmatter withworkflow.MarshalWithFieldOrder(frontmatter, constants.PriorityWorkflowFields), then rebuilds the file (line 167). It does this even when no import path changes, for example when every import is remote and SHA-pinned, or a local file thatisLocalFileForUpdatekeeps. UpdateFieldInFrontmatter(mergedStr, "source", ...)at line 260 already preserves raw lines, so it isn't the cause.
Reproduction
- Install a workflow with
gh aw add owner/repo/workflows/x.md@v1.0.0. Its frontmatter should have comments and animports:list with a remoteuses:entry. - Edit one local line, for example
on.bots. - Upstream publishes v1.0.1, changing one line elsewhere.
- Run
gh aw update --cool-down 0. The merge succeeds, but the file loses all#comments and its keys come out sorted (on,permissions,if,network,imports, ...).
Running git merge-file by hand on the same three inputs gives the expected minimal diff, with comments intact.
Implementation plan
- In
pkg/cli/imports.goprocessImportsWithWorkflowSpec: if no import path changes afterresolveOneImportPath, returncontentunchanged. - When paths do change, rewrite only the affected
imports:entries inresult.FrontmatterLines, replacing the path text on those lines, instead of re-marshalling the map. Keep the map-based code only as a fallback for import shapes the line editor can't handle. - Add tests in
pkg/cli/imports_test.go:- frontmatter with comments plus local and remote imports, nothing to rewrite → output identical to input;
- one relative import rewritten → only that line changes, comments and key order kept.
- Add a test in a new
pkg/cli/update_merge_test.go: a conflict-free merge of a commented workflow keeps its comments.
Acceptance criteria
gh aw update on a commented workflow with imports: produces the same diff as git merge-file, plus the source: line. No comment is lost and no key moves.
Activity