![](/img/trans.png)
[英]Github actions go test cannot find package error. How can I fix this?
[英]Why does my GitHub Actions script cannot find my internal go package?
我正在学习 Go 并想使用 GitHub 操作。 仅使用一个 package 时一切正常。 但是一旦我定义了多个 package (超过主包),我就卡住了。 在我的桌面上它确实可以编译,但是通过使用 Actions 脚本它不会并最终出现以下错误:
Run go build -v main.go
main.go:4:2: cannot find package "Landsat-Extractor/logger" in any of:
/opt/hostedtoolcache/go/1.14.4/x64/src/Landsat-Extractor/logger (from $GOROOT)
/home/runner/go/src/Landsat-Extractor/logger (from $GOPATH)
##[error]Process completed with exit code 1.
文件结构为:
go
└───src
└───Landsat-Extractor
│ main.go
│
└───logger
| │ logger.go
|
└───.github
└───workflows
| go.yml
在我的本地机器上,GOPATH 设置为之前文件结构的go
。
我的动作脚本 go.yml 是:
name: Go
on:
push:
branches: [ master, feature_githubaction ]
jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: ^1.14
id: go
- name: Check out code into the Go module directory
uses: actions/checkout@v2
- name: Build
run: go build -v main.go
主要的.go是:
package main
import (
"Landsat-Extractor/logger"
)
func main() {
logger.Create()
defer logger.Destroy()
logger.Info("A message")
}
logger.go 是:
package logger
// Create inits the Logger
func Create() {
println("Creating")
}
// Info logs a message
func Info(msg string) {
println(msg)
}
// Destroy closes writers
func Destroy() {
println("Closing")
}
在~/go/src/Landsat-Extractor
运行go mod init
这将有助于解决您的模块导入问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.