Set up a workflow file

All you need to do is add one release.yml file to your Github repository. I am flabbergasted with the UX of Github Actions! There are many templates you can use, but I decided to use the following one:

name: Release TBB binaries

on:
  release:
    types: [created]

jobs:
  releases-matrix:
    name: Release Go Binary
    runs-on: ubuntu-latest
    strategy:
      matrix:
        # build and publish in parallel: linux/amd64
        goos: [linux]
        goarch: [amd64]
    steps:
      - uses: actions/checkout@v2
      - name: Run tests
        run: go test -v -p=1 -timeout=0 ./...
      - uses: wangyoucao577/go-release-action@v1.16
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}
          goos: ${{ matrix.goos }}
          goarch: ${{ matrix.goarch }}
          project_path: "./cmd/tbb"
          binary_name: "tbb"
          ldflags: "-s -w"
          extra_files: LICENSE Readme.md

  • It triggers the binary build when you publish a new release in Github UI
  • It runs multiple build jobs in parallel (for me, only one job for amd64 Linux). You could add all platforms with goos: [linux, darwin, windows]
  • It starts with actions/checkout v2 to pull the repository code. My repository is public, but you can define all the necessary options like token, ssh-key, ref (branch/tag), and others
  • Runs all the Go tests for all packages consecutively without any timeout; testing PoW blockchain mining requires... patience
  • Extends the community workflow template wangyoucao577/go-release-action so you can do the following steps
  • Builds the tbb binary from ./cmd/tbb/main.go file
  • Injects ldflags settings into the binary build. Flag -s omits the symbol table and debug information, and -w strips the DWARF symbol table from the resulting binary
  • Generates tbb-1.8.6-alpha-linux-amd64.tar.gz and packs the LICENSE and Readme.md inside it

Create a new .github/workflows directory and paste the script there - adjust to your needs. You can also skip some steps like running the tests if you don't have them.

Full example: https://github.com/web3coach/the-blockchain-bar/blob/1.8.6-alpha/.github/workflows/release.yml

Trigger the release

You click the Draft a new release from Github UI, give it a tag, name, described the changes and publish. The Github Actions workflow will take care of testing, building and attaching binaries to it.

trigger Github Actions using a new release

running GA workflow

Final result

You will find your generated binaries attached to the release when the build job finishes. Your Go program is ready to be downloaded by your users.

attached Go released binaries

Get Started with Blockchain Development

Hi, I am writing an eBook on how to build a peer-to-peer system in Go from scratch!

Follow how the main protagonist Andrej, a web developer by day and a bartender by night, learns real-world use of blockchain through the growth of his new business venture: "The Blockchain Bar".

Free chapter