![](/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.