- 
                Notifications
    You must be signed in to change notification settings 
- Fork 75
fix(*): Use go env GOPATH for install golangci-lint #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| /cc @bbbmj | 
| DOCKER_LABELS ?= git-describe="$(shell date -u +v%Y%m%d)-$(shell git describe --tags --always --dirty)" | ||
|  | ||
| # Golang standard bin directory. | ||
| GOPATH ?= $(shell go env GOPATH) | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
在流水线执行的时候,代码构建阶段的环境没有装 go,而是通过启 go 容器运行的,会有问题。
之前将 PKGS 变量去掉,就是基于这个原因
@zhujian7 确认一下
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
没有装 go 的话,GOPATH 也是另外设置的好像?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
或许安装到项目的 bin 目录也是个不错的选择?
# install it into ./bin/
curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh| sh -s vX.Y.Z
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makefile 不兼容本地环境么?新安装的 golang 本地是不一定会设置 GOPATH 环境变量的。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
使用 GOPATH:
- 基础镜像不需要装 go
- 流水线需要额外设置 GOPATH
- 每个研发自己的电脑,需要装 go 并设置 GOPATH
使用 go env GOPATH:
- 基础镜像需要装 go
- 流水线不需要额外设置 GOPATH
- 每个研发自己的电脑,只需要装 go,不需要设置 GOPATH
综合看,我觉得设置成 go env GOPATH 可能好一点?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不用纠结吧,加个判断,存在 go 就 go env GOPATH,不存在就按照之前的
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Meoop 乐乐说的这种方式可以吗?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
en,和上面写法比较类似吧,GOPATH ?= $(shell go env GOPATH),如果有 GOPATH 这个环境变量,就不会执行 shell 了,也就不检测 go 存不存在,只有不存在 GOPATH 的时候才去调用 go 命令。
| /hold | 
| 流水线上肯定不存在这个问题,本地开发环境的话,建议手动设置 GOPATH(一次性操作)。因此,没有必要通过  | 
| 说实话,我并不认为 “本地开发环境的话,建议手动设置 GOPATH(一次性操作)” 是一个好的方案... 如果远程是通过启动一个 Golang 镜像去跑 lint ,那还不如直接用 golangci-lint 镜像呢,还少一次 curl。 | 
| 我们不是准备切换到 go module 了么,到时候 GOPATH 直接基本就没用了;那么这段过渡时间是否值得改这个? | 
| 
 @lsytj0413 这个改动就是由于系统不设置 GOPATH 这个环境变量导致的,切换到 go module,GOPATH 这个环境变量估计也没有人会去设置了,到时候根据 $GOPATH 环境变量去保存 golangci-lint 二进制就会出现问题($GOPATH 为空,下载到 /bin 下,普通用户是没有权限的)。 | 
| 验证完了,对  /cc @Meoop @supereagle @bbbmj | 
| @zhujian7: GitHub didn't allow me to request PR reviews from the following users: Meoop. Note that only caicloud members and repo collaborators can review this PR, and authors cannot review their own PRs. In response to this: 
 Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the caicloud/tools repository. | 
| /lgtm | 
GOPATH environment variable may be empty, go env GOPATH will work for all cases.
| /reopen | 
| /lgtm | 
| [APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: bbbmj, supereagle The full list of commands accepted by this bot can be found here. The pull request process is described here 
Needs approval from an approver in each of these files:
 
 Approvers can indicate their approval by writing  | 
| @Meoop please cherry-pick to https://github.com/caicloud/nirvana-template-project | 
| 
 I will update Makefile for this project including my changes. | 
| Cherry pick to caicloud/nirvana-template-project by caicloud/nirvana-template-project#6 | 

What this PR does / why we need it:
在新版本的 Golang 中,GOPATH 环境变量可以不设置,当系统未设置 GOPATH 环境变量时,golangci-lint 将安装到 /bin 目录下,安装错位置。使用
go env GOPATH命令获取 GOPATH 路径可以应对所有的场景。参考 golangci-lint 将
GOPATH换成go env GOPATH: golangci/golangci-lint#319Which issue(s) this PR is related to (optional, link to 3rd issue(s)):
Fixes #
Reference to #
Special notes for your reviewer:
/cc @bbbmj
Release note: