How to test your Go packages with GitHub Actions

Tom Elliott
average-coder
Published in
2 min readMay 12, 2019

Actions are a GitHub feature — currently in beta — that allows you to add workflows to your repositories to execute automated tasks (such as CI/CD) on each commit. In this post, we’ll see how to set up a workflow to execute unit tests in a Go package.

Gopher meets Octocat

Your workflows are executed within Docker containers, so you can configure Actions with any tooling required. Actions can also be made available to the community via GitHub Marketplace. Helpfully Cedric Kring has already provided an Action for Go builds, so we can use this to get going.

You can define your workflows using the GitHub web UI, or by creating the config files manually. We’ll be doing the latter. To add a workflow to your repository, create a file called .github/main.workflow with the following contents:

workflow "Unit Tests" {
resolves = ["cedrickring/golang-action@1.3.0"]
on = "push"
}

action "cedrickring/golang-action@1.3.0" {
uses = "cedrickring/golang-action@1.3.0"
}

This defines a workflow called “Unit Tests” that executes on every push, and runs the action cedrickring/golang-action at version 1.3.0.

Commit and push this change. You will now see an indicator next to your commits to show the result of running your Workflow.

Successful workflow execution on latest commit

These indicators also appear with pull requests.

Failed workflow execution on pull request

This is just scratching the surface of what you can do with Actions, but getting started couldn’t be easier! To find out more, take a look at the documentation on developer.github.com.

--

--