Automation is great (right?!) and it can be so easy these days to run your tests automatically on any new pull request or code change. In this post we outline how you can automatically run your Go (golang) test for your project by using Github Actions. The results will then show within Github and is configured using a yaml file.
To get this running, you will need to create a workflow file (as shown below). Which will essentially do the following:
name:Goon:[push]jobs:build:name:Buildruns-on:ubuntu-lateststeps:- name:Download Gouses:actions/setup-go@v2with:go-version:1.18id:go- name:Check out code into the Go module directoryuses:actions/checkout@v2- name:Get dependenciesrun:| go get -v -t -d ./...- name:Buildenv:GOPROXY:"https://proxy.golang.org"run:go build .- name:Testenv:GOPROXY:"https://proxy.golang.org"AWS_ACCESS_KEY_ID:${{ secrets.AWS_ACCESS_KEY_ID }}AWS_SECRET_ACCESS_KEY:${{ secrets.AWS_SECRET_ACCESS_KEY }}run:go test -v .
Commit this file and push, and it will run automatically for you.
Example
Secrets
Most of the above is as simple as copy and paste, but near the end we have added some example environment variables, AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY. These use Github secrets and allow you pass important/sensitive information to your application/tests.
Edd is a PHP and Go developer who enjoys blogging about his experiences, mostly about creating and coding new things he's working on and is a big beliver in open-source and Linux.