在Gitlab CI中使用gomodules测试Go项目失败;包不在GOROOT中“;
我正在尝试使用下面的.Gitlab-CI.yml在Gitlab CI上构建和测试Go项目:在Gitlab CI中使用gomodules测试Go项目失败;包不在GOROOT中“;,gitlab,go-modules,Gitlab,Go Modules,我正在尝试使用下面的.Gitlab-CI.yml在Gitlab CI上构建和测试Go项目: image: golang:latest stages: - prepare - test - build - package format: stage: prepare script: - make gofmt test: stage: test script: - make test test race condition: sta
image: golang:latest
stages:
- prepare
- test
- build
- package
format:
stage: prepare
script:
- make gofmt
test:
stage: test
script:
- make test
test race condition:
stage: test
script:
- make race
coverage-html:
stage: test
script:
- make cov
build win binary:
stage: build
script:
- make win
build linux binary:
stage: build
script:
- make linux
build mac binary:
stage: build
script:
- make mac
下面是管道中使用的Makefile:
# Go parameters
GOCMD=go
GOBUILD=$(GOCMD) build
GOCLEAN=$(GOCMD) clean
GOTOOL=$(GOCMD) tool
GOTEST=$(GOCMD) test
GOTESTRACE=$(GOTEST) -race
GOGET=$(GOCMD) get
GOFMT=$(GOCMD)fmt
BINARY_NAME=app
BINARY_DARWIN=$(BINARY_NAME)_darwin
BINARY_LINUX=$(BINARY_NAME)_linux
BINARY_WIN=$(BINARY_NAME)_win
all: build linux win
build: ## Download dependecies and Build the default binary
$(GOBUILD) -o $(BINARY_NAME) -v $(CURDIR)/cmd/app
linux: ## Build linux binary
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 $(GOBUILD) cmd/app -o $(BINARY_LINUX) -v $(CURDIR)/cmd/app
win: ## Build windows binary
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 $(GOBUILD) -o $(BINARY_WIN).exe -v $(CURDIR)/cmd/app
mac: ## Build macOs binary
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 $(GOBUILD) -o $(BINARY_DARWIN) -v $(CURDIR)/cmd/app
test: ## Run tests for the project
$(GOTEST) -count=1 -coverprofile=cover.out -short -cover -failfast ./... -v
race: ## Run tests for the project (while detecting race conditions)
$(GOTESTRACE) -coverprofile=cover.out -short -cover -failfast ./...
cov: test ## Run tests with HTML for the project
$(GOTOOL) cover -html=cover.out
gofmt: ## gofmt code formating
@echo Running go formating with the following command:
$(GOFMT) -e -s -w .
我正在使用gomodule
管理依赖项。我很难理解的是,如果我先在build
阶段运行作业,管道就能够下载依赖项并成功地构建二进制文件。但是当运行测试
阶段中的作业时,它们都会失败,并出现以下错误:
main.go:3:8: package app/command is not in GOROOT (/usr/local/go/src/app/command)
make: *** [Makefile:31: test] Error 1
Cleaning up file based variables
ERROR: Job failed: command terminated with exit code 1
在我需要配置的Gitlab CI上测试基于
gomodule
的项目时,是否有其他设置?您是否设法解决了这个问题?原因是什么?你解决问题了吗?原因是什么?