Toshimaru's Blog

Go Release Automation with goreleaser + GitHub Actions

I created a workflow to automate my go CLI tool with goreleaser + GitHub actions.

Tools I used

What I want to do

When a new tag is pushed, I’d like to release new go binary with goreleaser.

$ git tag -a v0.1.0 -m "First release"
$ git push origin v0.1.0 # => want to release v0.1.0

Trigger TagCreated-Event

I want to trigger an event - <A new tag is pushed>. How can I do this on GitHub Actions?

The example:

name: Release with goreleaser
      - "!*"
      - "v*.*.*"

The points are:

  • Disabling an event - <A new branch is pushed>
  • Enabling an event - <A new tag named v*.*.* is pushed>

Release Workflow Definition

Release Workflow is:

  1. Set up Go
  2. Check out Code
  3. Run goreleaser command using goreleaser/goreleaser-action

The workflow definition sample is:

    runs-on: ubuntu-latest
    name: goreleaser
    - name: Set up Go
      uses: actions/setup-go@v1
        go-version: 1.13
      id: go
    - name: Check out code into the Go module directory
      uses: actions/checkout@v1
    - name: goreleaser
      uses: goreleaser/goreleaser-action@master
        args: release
        GITHUB_TOKEN: ${{ secrets.CUSTOM_GITHUB_TOKEN }}

I use CUSTOM_GITHUB_TOKEN because I need to update another repository for homebrew in release process.

If you don’t need an additional permission for another repository, you can use default GITHUB_TOKEN.

GitHub automatically creates a GITHUB_TOKEN secret to use in your workflow.

ref. Virtual environments for GitHub Actions - GitHub Help

Tips: No tag found. Snapshot forced

If no tag is found, snapshot option is forced.

console.log(`⚠️ No tag found. Snapshot forced`);
if (!args.includes('--snapshot')) {
  snapshot = ' --snapshot';


Whole Sample

You can watch whole sample on my repository: