Github ActionsでGolangのテンプレートを作成する
2019年11月12日現在、Github ActionsのGUIからテンプレートを作成すると以下のようなコードが生成される
name: Go
on: [push]
jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.13
uses: actions/setup-go@v1
with:
go-version: 1.13
id: go
- name: Check out code into the Go module directory
uses: actions/checkout@v1
- name: Get dependencies
run: |
go get -v -t -d ./...
if [ -f Gopkg.toml ]; then
curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
dep ensure
fi
- name: Build
run: go build -v .
これをそのまま走らせると以下のように落ちる
Run go get -v -t -d ./...
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
100 5230 100 5230 0 0 32687 0 --:--:-- --:--:-- --:--:-- 32687
ARCH = amd64
OS = linux
Installation requires your GOBIN directory /home/runner/go/bin to exist. Please create it.
##[error]Process completed with exit code 1.
原因
GOPATH
周りの設定がうまく行っていなくGOPATH
に依存するdep
を使うと動かない
ので、設定してあげる
修正
なので以下のように直す
name: Go
on: [push]
jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.11
uses: actions/setup-go@v1
with:
go-version: 1.11
id: go
- name: Check out code into the Go module directory
uses: actions/checkout@v1
- name: Get dependencies and Build
run: |
export GOPATH=$HOME/go
export GOBIN=$(go env GOPATH)/bin
export PATH=$PATH:$GOPATH
export PATH=$PATH:$GOBIN
mkdir -p $GOPATH/pkg
mkdir -p $GOBIN
mkdir -p $GOPATH/src/github.com/$GITHUB_REPOSITORY
mv ./* $GOPATH/src/github.com/$GITHUB_REPOSITORY
cd $GOPATH/src/github.com/$GITHUB_REPOSITORY
go get -v -t -d ./...
if [ -f Gopkg.toml ]; then
curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
dep ensure
fi
cd $GOPATH/src/github.com/$GITHUB_REPOSITORY && go build -v .
GithubActionsはrun毎にdocker run
的なことをやっているみたいなので、Get Dependency
とBuild
を一気に行うようにした
参考
https://github.com/actions/setup-go/issues/12