Skip to content

Commit b77cc0f

Browse files
committed
Force appropriate version for go mod tidy compatibility check
`go mod tidy` has an inexplicable default behavior: https://go.dev/ref/mod#go-mod-tidy >By default, go mod tidy will check that the selected versions of modules do not change when the module graph is loaded > by the Go version immediately preceding the version indicated in the go directive. The `go` directive indicates the version of Go the project is written for. The `go mod tidy` command should not fail if the module is configured in a manner that is incompatible with an unsupported Go version. So it is necessary use use the `-compat=1.17` flag to cause the `go mod tidy` command to behave correctly and check for compatibility with the version of Go that is in use. Previously, I had thought that `go mod tidy` was straightforward enough that it did not make sense to wrap it in a task. This is no longer true, so it is moved to the `go:tidy` task so that the developer does not need to think about what obscure flags are required to make it behave correctly and to be aligned with the results of the "Check Go" CI workflow.
1 parent f89e08f commit b77cc0f

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

.github/workflows/check-go-task.yml

+9-2
Original file line numberDiff line numberDiff line change
@@ -222,9 +222,16 @@ jobs:
222222
with:
223223
go-version: ${{ env.GO_VERSION }}
224224

225+
- name: Install Task
226+
uses: arduino/setup-task@v1
227+
with:
228+
repo-token: ${{ secrets.GITHUB_TOKEN }}
229+
version: 3.x
230+
225231
- name: Run go mod tidy
226-
working-directory: ${{ matrix.module.path }}
227-
run: go mod tidy
232+
env:
233+
GO_MODULE_PATH: ${{ matrix.module.path }}
234+
run: task go:tidy
228235

229236
- name: Check whether any tidying was needed
230237
run: git diff --color --exit-code

Taskfile.yml

+10
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ tasks:
7373
- task: go:generate
7474
- task: go:fix
7575
- task: go:format
76+
- task: go:tidy
7677
- task: markdown:fix
7778
- task: python:format
7879
- task: shell:format
@@ -266,6 +267,15 @@ tasks:
266267
- poetry run pytest tests
267268
- poetry run pytest ruledocsgen/tests
268269

270+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-go-task/Taskfile.yml
271+
go:tidy:
272+
desc: Refresh dependency metadata
273+
dir: "{{default .DEFAULT_GO_MODULE_PATH .GO_MODULE_PATH}}"
274+
vars:
275+
GO_VERSION: 1.17
276+
cmds:
277+
- go mod tidy -compat={{.GO_VERSION}}
278+
269279
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-go-task/Taskfile.yml
270280
go:vet:
271281
desc: Check for errors in Go code

0 commit comments

Comments
 (0)