Skip to content

ci: fail vendor check when vendor/, go.mod or go.sum drift#517

Closed
frobware wants to merge 3 commits into
bpfman:mainfrom
frobware:fix/ci-verify-clean-vendors
Closed

ci: fail vendor check when vendor/, go.mod or go.sum drift#517
frobware wants to merge 3 commits into
bpfman:mainfrom
frobware:fix/ci-verify-clean-vendors

Conversation

@frobware
Copy link
Copy Markdown
Contributor

@frobware frobware commented May 5, 2026

The Check clean vendors step in .github/workflows/pull_request.yml ran go mod vendor and discarded the result. A pull request that left vendor/, go.mod or go.sum out of sync with the module graph would still pass this check.

This was not theoretical. PR #516 illustrates the exact failure mode: the contributor ran go mod vendor locally, updated go.mod/go.sum/vendor/modules.txt, but did not git add three newly created top-level directories under vendor/:

  • vendor/github.com/spf13/afero/
  • vendor/golang.org/x/text/runes/
  • vendor/sigs.k8s.io/controller-runtime/tools/

The resulting tree builds against the module proxy but fails when consumed with -mod=vendor, which is what make test ends up doing via go run sigs.k8s.io/controller-runtime/tools/setup-envtest. CI on #516 has not yet executed (workflow is in action_required pending maintainer approval, so the breakage is latent rather than red.

Change

Run go mod vendor and then assert with git status --porcelain that no tracked modifications and no untracked entries remain under vendor/, go.mod or go.sum. On failure, print the offending paths and the diff so the workflow log makes the cause obvious.

git diff --exit-code alone is insufficient: it ignores untracked files, which is precisely the failure mode we need to catch. The bundle verification step a few lines below uses git diff --exit-code because regenerating the bundle modifies tracked files only; vendor regeneration can also create new directories, so it needs the stricter check.

Verification

Reproducer against PR #516's tree on a clean checkout:

$ gh pr checkout 516
$ go mod vendor
$ git status --porcelain vendor go.mod go.sum
?? vendor/github.com/spf13/afero/
?? vendor/golang.org/x/text/runes/
?? vendor/sigs.k8s.io/controller-runtime/tools/

With this PR's check inlined, the workflow would have exited 1 with the three offending paths printed.

Test plan

The "Check clean vendors" step previously ran `go mod vendor` but
discarded the result, so a pull request could leave `vendor/`,
`go.mod` or `go.sum` out of sync with the module graph and CI would
still pass.  In particular, when a contributor runs `go mod vendor`
locally but forgets to `git add` newly created vendor directories,
the resulting tree builds against the module proxy yet fails when
later consumed with `-mod=vendor`.

Run `go mod vendor` and then assert with `git status --porcelain` that
no tracked changes and no untracked entries remain under `vendor/`,
`go.mod` or `go.sum`.  `git diff --exit-code` alone is insufficient
because it ignores untracked files, which is precisely the failure
mode we need to catch.  On failure, print the offending paths and the
diff to make the cause obvious in the workflow log.

Signed-off-by: Andrew McDermott <amcdermo@redhat.com>
Copy link
Copy Markdown
Contributor

@alebedev87 alebedev87 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one small suggestion.

Comment thread .github/workflows/pull_request.yml
frobware and others added 2 commits May 5, 2026 13:23
Co-authored-by: Andrey Lebedev <alebedev87@gmail.com>
Signed-off-by: Andrew McDermott <amcdermo@redhat.com>
The "Check clean vendors" step runs `go mod tidy` followed by
`go mod vendor`, but the diagnostic emitted on drift only mentioned
`go mod vendor`.  Update the message to name both commands so the
workflow log makes the full reproducer self-evident.

Signed-off-by: Andrew McDermott <amcdermo@redhat.com>
@frobware
Copy link
Copy Markdown
Contributor Author

frobware commented May 5, 2026

Going with #516.

@frobware frobware closed this May 5, 2026
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.

2 participants