Go
Go is a statically typed, compiled programming language; feel free to browse the Foundation hosted projects written in Go.
Build and test
Install Go with actions/setup-go, reading the version from go.mod. The action also caches Go modules and build output by default:
name: CI
on:
pull_request:
push:
branches: [main]
permissions:
contents: read
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- uses: actions/setup-go@d8cbb8045d7f43706b9177cceb36c1f91a6644d5 # v7.1.0
with:
go-version-file: go.mod
- run: go vet ./...
- run: go test ./...
Releasing Go modules
Go modules have no package registry to upload to: a version is published by pushing a semantic version Git tag, such as v1.2.3, to the repository. The Go module proxy and pkg.go.dev then serve that version. See the Go modules reference for how versions and major version suffixes work.
Release binaries with GoReleaser
To attach compiled binaries to a GitHub release, use GoReleaser with the GoReleaser GitHub Action. GoReleaser creates the GitHub release with the workflow's GITHUB_TOKEN, so the job needs contents: write. It also needs the full Git history (fetch-depth: 0) to build the changelog.
The following workflow runs when a v* tag is pushed. It also creates artifact attestations for the archives listed in GoReleaser's checksums file, which needs id-token: write and attestations: write:
name: Release
on:
push:
tags:
- 'v*'
permissions:
contents: read
jobs:
goreleaser:
runs-on: ubuntu-latest
permissions:
contents: write # create the GitHub release
id-token: write # artifact attestations
attestations: write # artifact attestations
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0
persist-credentials: false
- uses: actions/setup-go@d8cbb8045d7f43706b9177cceb36c1f91a6644d5 # v7.1.0
with:
go-version-file: go.mod
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@a4f02ab5355a589de60d917a659ce617ed19b3de # v7.3.0
with:
distribution: goreleaser
version: "~> v2"
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Attest build provenance
uses: actions/attest-build-provenance@4d101475d8b20a2381f78447822ac1eab6504dd8 # v4.2.2
with:
subject-checksums: dist/checksums.txt
For example, morphir-go runs a pre-release validation job and then GoReleaser when a v* tag is pushed.