Github Actions and GOPATH
The other day I received my beta access to GitHub Actions. To try them out I picked an existing pet project and created a workflow using a Go project template provided by GitHub. As it’s in September 2019, their template defines the sequence of steps: setup Go, checkout code, get dependencies, build. This is not exactly how I used to do it.
My project is a classic Go service ;) meaning: it uses vendoring and doesn’t use Go modules. So no need for “get dependencies” step. And it requires to be inside the GOPATH
. With that, the provided workflow needed some adjustment.
After some trials and errors, I’ve managed to make checkout
step to clone the repo into the correct destination inside the GOPATH
. Here is the final workflow:
name: Run Go test
on: [pull_request]
jobs:
test:
strategy:
matrix:
go-version: [1.12.9]
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v1
with:
go-version: ${{ matrix.go-version }}
- uses: actions/checkout@v1
with:
path: ./src/github.com/${{ github.repository }}
fetch-depth: 5
- run: make test
env:
GOPATH: ${{ runner.workspace }}
Note, how actions/checkout@v1
above uses custom path
input parameter. I set the path to ./src/github.com/${{ github.repository }}
, so the project is checked out to src
directory in the runners’s workspace, which I later pass as the value of GOPATH
to the “make test” step. The leading dot in ./src
seems very important — I’ve spent the majority of the time trying to figure out that part — refer to this issue.
To learn more about those ${{ ··· }}
“macroses” I suggest looking at the Actions’ “Contexts and expression syntax” documentation.