this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

internal/ci: `go generate` after `go test`

Some packages like ./encoding/jsonschema use `go generate` to produce
testdata files, which is an entirely reasonable use case.
Because these files get overwritten every time, getting new modtimes,
this causes `go test ./...` to treat the test input files as changed,
and so CI never reuses a cached test run of the jsonschema package.

For this reason, as well as to avoid confusion with developers looking
at CI failures (which has happened twice already), test and check first,
and generate after. In the happy case, where code generation is clean,
this results in no change in behavior other than more test cache hits.
In the case where the user forgot to re-run `go generate`,
CI will still fail, just a little bit later, which is fine.

Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
Change-Id: I2635095eec950d392f5ccb6da2147e20f7c83584
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1201440
Reviewed-by: Roger Peppe <rogpeppe@gmail.com>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>

+9 -4
+3 -3
.github/workflows/trybot.yaml
··· 110 110 - name: Early git and code sanity checks 111 111 if: (matrix.go-version == '1.23.x' && matrix.runner == 'ubuntu-22.04') 112 112 run: go run ./internal/ci/checks 113 - - name: Generate 114 - run: go generate ./... 115 - if: (matrix.go-version == '1.23.x' && matrix.runner == 'ubuntu-22.04') 116 113 - name: Test 117 114 if: |- 118 115 ((github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/heads/release-branch.')) && (! (contains(github.event.head_commit.message, ' ··· 169 166 echo "Did you forget about refs/attic branches? https://github.com/cue-lang/cue/wiki/Notes-for-project-maintainers" 170 167 exit 1 171 168 fi 169 + - name: Generate 170 + run: go generate ./... 171 + if: (matrix.go-version == '1.23.x' && matrix.runner == 'ubuntu-22.04') 172 172 - name: Check that git is clean at the end of the job 173 173 if: always() 174 174 run: test -z "$(git status --porcelain)" || (git status; git diff; false)
+6 -1
internal/ci/github/trybot.cue
··· 67 67 // so we only need to run them on one of the matrix jobs. 68 68 if: _isLatestLinux 69 69 }, 70 - _goGenerate, 71 70 _goTest & { 72 71 if: "\(_repo.isProtectedBranch) || !\(_isLatestLinux)" 73 72 }, ··· 78 77 for v in _e2eTestSteps {v}, 79 78 _goCheck, 80 79 _checkTags, 80 + // Run code generation towards the very end, to ensure it succeeds and makes no changes. 81 + // Note that doing this before any Go tests or checks may lead to test cache misses, 82 + // as Go uses modtimes to approximate whether files have been modified. 83 + // Moveover, Go test failures on CI due to changed generated code are very confusing 84 + // as the user might not notice that checkGitClean is also failing towards the end. 85 + _goGenerate, 81 86 _repo.checkGitClean, 82 87 ] 83 88 }