Skip to content

Commit a98ac6c

Browse files
committed
Make go:lint task compatible with Go 1.16
The update from Go 1.14 to 1.16 broke the task that runs golint. The good news is that the new `go install` command eliminates the need for the workaround of running the `go get golang.org/x/lint/golint` command from outside the project path. The bad news is the `go list` command used to get the path of the golint installation does not work in the "module-aware mode" that is now the default (and will be the only as of Go 1.17): missing go.sum entry for module providing package golang.org/x/lint/golint; to add: go mod download golang.org/x/lint task: Command "go list -f {{".Target}}" golang.org/x/lint/golint" failed: exit status 1 In the end, I gave up on making the task work as before. I think it's better to require the user to install golint and put the installation in the system PATH, displaying a helpful message when this has not been done. We plan to evaluate golangci-lint as a replacement for golint, and perhaps this will change the situation, but for now at least the check is back to functional again.
1 parent 6086530 commit a98ac6c

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

workflow-templates/assets/check-go-task/Taskfile.yml

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,12 @@ tasks:
3030
desc: Lint Go code
3131
cmds:
3232
- |
33-
PROJECT_PATH="$PWD"
34-
# `go get` and `go list` commands must be run from a temporary folder to avoid polluting go.mod
35-
cd "$(mktemp -d "${TMPDIR-${TMP-/tmp}}/task-temporary-XXXXX")"
36-
go get golang.org/x/lint/golint
37-
GOLINT_PATH="$(go list -f '{{"{{"}}.Target{{"}}"}}' golang.org/x/lint/golint || echo "false")"
38-
# `golint` must be run from the module folder
39-
cd "$PROJECT_PATH"
40-
"$GOLINT_PATH" \
33+
if ! which golint &>/dev/null; then
34+
echo "golint not installed or not in PATH. Please install: https://github.com/golang/lint#installation"
35+
exit 1
36+
fi
37+
- |
38+
golint \
4139
{{default "-min_confidence 0.8 -set_exit_status" .GO_LINT_FLAGS}} \
4240
{{default .DEFAULT_GO_PACKAGES .GO_PACKAGES}}
4341

workflow-templates/check-go-task.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ jobs:
8888
repo-token: ${{ secrets.GITHUB_TOKEN }}
8989
version: 3.x
9090

91+
- name: Install golint
92+
run: go install golang.org/x/lint/golint@latest
93+
9194
- name: Check style
9295
run: task --silent go:lint
9396

workflow-templates/dependabot/workflow-template-copies/.github/workflows/check-go-task.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ jobs:
8888
repo-token: ${{ secrets.GITHUB_TOKEN }}
8989
version: 3.x
9090

91+
- name: Install golint
92+
run: go install golang.org/x/lint/golint@latest
93+
9194
- name: Check style
9295
run: task --silent go:lint
9396

0 commit comments

Comments
 (0)