Repository navigation
Description
Analysis
When a source-managed workflow has an imports: field, gh aw update removes every frontmatter comment, reorders the top-level keys and reindents block scalars. This happens even when no import path changes.
processImportsWithWorkflowSpec in pkg/cli/imports.go always ends with reconstructWorkflowFileFromMap, which re-marshals the parsed frontmatter with MarshalWithFieldOrder. It does this whether or not it rewrote an import. Since #74359 the same function also runs on all three merge inputs.
This hits a common setup. Upstream templates often document opt-in imports as a commented-out imports: block, and consumers add a local shared import, for example for package registry auth. After the first update, the consumer copy loses all of its setup comments.
The ADR for #74359 lists this as Alternative 1, "Stop rewriting imports into canonical YAML on update", and defers it because it needs a format-preserving editor. Most workflows don't need one, because their imports are already in final form.
Reproduce
- Install a workflow with
gh aw addwhose frontmatter has comments. - Add a local import that exists in the repository, for example
imports: [shared/local.md]. - Change the upstream workflow, then run
gh aw update.
Actual: all frontmatter comments are removed and the keys are reordered.
Expected: the comments and the order are kept. Only source: and the upstream changes differ.
Reproduced on v1.0.1. The same code is on main at 5bb18f5.
Implementation plan
- In
processImportsWithWorkflowSpec(pkg/cli/imports.go), track whether any import entry changed. If none did, returncontentunchanged. - Add tests to
pkg/cli/imports_test.go:- Frontmatter with comments and local-only imports is returned byte-for-byte unchanged.
- A relative import that needs rewriting still gets rewritten.
- Check that the merge normalisation from Prevent repeat-update conflicts in source-managed workflows #74359 still prevents format-only conflicts when the imports don't change.
Follow-up: when an import does change, edit only that line in the raw imports: block, like updateTopLevelFieldInFrontmatterRaw does for source:, instead of re-marshalling the whole frontmatter.
Activity