ci: detect more than one unformatted file in the gofmt check - #2695
Open
thanderoy wants to merge 2 commits into
Open
ci: detect more than one unformatted file in the gofmt check#2695thanderoy wants to merge 2 commits into
thanderoy wants to merge 2 commits into
Conversation
The gofmt check used an unquoted command substitution:
if [ ! -z $(gofmt -l .) ]
With two or more unformatted files the expansion word-splits, so the
test becomes `[ ! -z a.go b.go ]`, which is not a valid expression.
`[` fails with "binary operator expected" and exits non-zero, the `if`
takes the false branch, and the step passes. The check therefore only
ever caught the case of exactly one unformatted file.
Quote the substitution so the file list stays a single word, and use
`-n` instead of `! -z`. Also pass `-s`, so the check enforces the same
thing its own error message and the `format` make target tell
contributors to run.
Five files on master are currently unformatted and pass CI. They are
reformatted in the following commit, without which this check would
fail on this very branch.
These five files are unformatted on master. The gofmt check could not see them, because it only detected a single unformatted file at a time until the previous commit. This is the output of `make format` with no hand edits. The diff is struct field alignment and one binary expression spacing change: `git diff -w` is empty.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
The gofmt check in
test.ymlsilently passes whenever more than one file is unformatted, so it has never enforced formatting in practice.auth/.github/workflows/test.yml
Line 42 in 2399fe5
The command substitution is unquoted, so the file list word-splits into separate arguments to
[:[exit[ ! -z ][ ! -z a.go ][ ! -z a.go b.go ]binary operator expectedWith two or more files,
[never evaluates the expression — it errors on the unexpected second operand and exits non-zero, theiftakes the false branch, and the step exits 0. The failure is invisible in the log unless you read theset -xtrace closely, because the step is green.As of 2399fe5, five files on master are unformatted and pass CI:
How
Two commits, separable on purpose:
ci: detect more than one unformatted file in the gofmt check- quotes the substitution so the list stays one word, and uses-nrather than! -z.ci: run make format- the five files above, so the now-working check passes on this branch.The check has to be fixed and the tree formatted in the same PR: fixing the check alone makes CI fail on the PR that fixes it.
Verified:
gofmt -s -l .is empty,go build ./...,go vet ./...andstaticcheckare clean, and the tests for the touched packages (internal/api/provider,internal/conf/...) pass.Notes for review
-sto the check. The check ran plaingofmt -l, while its own error message and theformatmake target both specifygofmt -s -w. It was checking something narrower than it asked for.make formatoutput with no hand edits just struct field alignment, plus one binary expression spacing change incustom_oauth_claims_test.go.git diff -won that commit is empty, and the diffstat is symmetric (37 insertions, 37 deletions). It should be reviewable at a glance, and is easy to drop and regenerate if it conflicts with anything in flight..github/workflows/.