Skip to content

Commit 818f8bf

Browse files
committed
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í <[email protected]> Change-Id: I2635095eec950d392f5ccb6da2147e20f7c83584 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1201440 Reviewed-by: Roger Peppe <[email protected]> TryBot-Result: CUEcueckoo <[email protected]> Unity-Result: CUE porcuepine <[email protected]>
1 parent cad9ae4 commit 818f8bf

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

.github/workflows/trybot.yaml

+3-3
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,6 @@ jobs:
110110
- name: Early git and code sanity checks
111111
if: (matrix.go-version == '1.23.x' && matrix.runner == 'ubuntu-22.04')
112112
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')
116113
- name: Test
117114
if: |-
118115
((github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/heads/release-branch.')) && (! (contains(github.event.head_commit.message, '
@@ -169,6 +166,9 @@ jobs:
169166
echo "Did you forget about refs/attic branches? https://github.com/cue-lang/cue/wiki/Notes-for-project-maintainers"
170167
exit 1
171168
fi
169+
- name: Generate
170+
run: go generate ./...
171+
if: (matrix.go-version == '1.23.x' && matrix.runner == 'ubuntu-22.04')
172172
- name: Check that git is clean at the end of the job
173173
if: always()
174174
run: test -z "$(git status --porcelain)" || (git status; git diff; false)

internal/ci/github/trybot.cue

+6-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ workflows: trybot: _repo.bashWorkflow & {
6767
// so we only need to run them on one of the matrix jobs.
6868
if: _isLatestLinux
6969
},
70-
_goGenerate,
7170
_goTest & {
7271
if: "\(_repo.isProtectedBranch) || !\(_isLatestLinux)"
7372
},
@@ -78,6 +77,12 @@ workflows: trybot: _repo.bashWorkflow & {
7877
for v in _e2eTestSteps {v},
7978
_goCheck,
8079
_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,
8186
_repo.checkGitClean,
8287
]
8388
}

0 commit comments

Comments
 (0)