Skip to content

gh aw update drops every frontmatter comment and reorders keys on a conflict-free merge #73073

Done

Description

@kdowswell

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 has imports:, it parses the frontmatter into a map, rewrites import paths, and at line 158 re-marshals the entire frontmatter with workflow.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 that isLocalFileForUpdate keeps.
  • UpdateFieldInFrontmatter(mergedStr, "source", ...) at line 260 already preserves raw lines, so it isn't the cause.

Reproduction

  1. Install a workflow with gh aw add owner/repo/workflows/x.md@v1.0.0. Its frontmatter should have comments and an imports: list with a remote uses: entry.
  2. Edit one local line, for example on.bots.
  3. Upstream publishes v1.0.1, changing one line elsewhere.
  4. 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

  1. In pkg/cli/imports.go processImportsWithWorkflowSpec: if no import path changes after resolveOneImportPath, return content unchanged.
  2. When paths do change, rewrite only the affected imports: entries in result.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.
  3. 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.
  4. 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions