Skip to content

fix(check-catalog-info): stage before diffing so drift is actually detected - #2298

Open
ricky-undeadcoders wants to merge 1 commit into
mainfrom
rwhitaker/fix-catalog-info-drift-check
Open

fix(check-catalog-info): stage before diffing so drift is actually detected#2298
ricky-undeadcoders wants to merge 1 commit into
mainfrom
rwhitaker/fix-catalog-info-drift-check

Conversation

@ricky-undeadcoders

@ricky-undeadcoders ricky-undeadcoders commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

check-catalog-info.yaml has never worked. It runs make catalog-info.yaml and then:

git diff --staged --exit-code

--staged compares the index against HEAD, and nothing in the job is ever git added — so the diff is always empty and the check passes unconditionally, whatever the generator produced.

What that let through

catalog-info.yaml had drifted by 338 lines. 18 of 39 actions were missing from the catalog entirely , so they never appeared in Backstage:

annotate-coverage, azure-trusted-signing, cleanup-branches, component-change-detection, create-github-app-token, docker-build-push-image, docker-export-digest, docker-import-digests-push-manifest, download-branch-workflow-artifact, go-flaky-tests, issues-update-project-status, run-capslock, signed-commits-info, socket-export-sbom, validate-renovate-config, validate-zizmor-config, wait-for-docker-publish, zizmor-collection-paths

The fix, in two parts

1. Stage before diffing (.github/workflows/check-catalog-info.yaml):

   - name: Check for drift
     run: |
+      git add -A
       if ! git diff --staged --exit-code; then

git diff alone would have covered modified files but still missed newly created ones — which is the case that actually mattered here, since a brand-new action has no catalog entry to modify. Also switched the failure to ::error:: so it surfaces as an annotation rather than a line in the log.

2. Normalize the generator's trailing newline (scripts/generate-catalog-info/main.go).

This part is not cosmetic — without it the fixed check fails on every PR. writeYAML appends a blank line after each document, which reads well between them but leaves a trailing one at EOF, so the generator emits \n\n. The committed file has a single \n, because pre-commit's end-of-file-fixer had been quietly stripping the extra one before every commit.

That mismatch was invisible while the check was broken. Once the check works, CI regenerates the file, gets \n\n back, and the diff shows a one-byte change — so it would have gone from never failing to never passing. I hit exactly this in CI on the first push of this PR.

normalized := append(bytes.TrimRight(output.Bytes(), "\n"), '\n')

Applied at the write site so the - (stdout) path gets the same treatment.

Verification

  • Simulated the fixed check against the drifted tree: correctly fails.
  • pre-commit run end-of-file-fixer --files catalog-info.yaml: Passed.
  • Two consecutive make catalog-info.yaml runs: byte-identical.
  • Regenerated file parses as 39 documents / 39 components, no duplicates.
  • actionlint, gofmt, go vet: clean.

Notes

Of the 351 changed lines, 17 are the actual fix — the rest is generated catalog content clearing three months of accumulated drift.

Found while working on #2276, which added an equivalent drift check for action docs. That one already uses git add -A && git diff --staged --exit-code, and hit the same "generated output must satisfy the formatter" problem with prettier — worth remembering that any generate-and-diff check has both failure modes.

Touches no release-please package, so no version bumps.

@ricky-undeadcoders
ricky-undeadcoders requested a review from a team as a code owner September 10, 2026 16:56
…tected

The check ran `make catalog-info.yaml` and then `git diff --staged
--exit-code`, but nothing was ever added to the index -- so the diff was
always empty and the check passed unconditionally.

It has therefore never caught anything. 18 of 39 actions were missing
from the catalog entirely, including docker-build-push-image and
create-github-app-token, so they did not appear in Backstage at all.

Stages first so both new and modified files are seen, and regenerates
catalog-info.yaml to clear the accumulated drift.

Also normalizes the generator's trailing newline. It emitted a blank line
after every document, including the last, which pre-commit's
end-of-file-fixer then stripped -- so the generated file differed from the
committed one by a single byte and the newly-working check would have
failed on every PR.
@ricky-undeadcoders
ricky-undeadcoders force-pushed the rwhitaker/fix-catalog-info-drift-check branch from cca1586 to 216a6a0 Compare September 10, 2026 20:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant