Skip to content

theory/go-dist-action

Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Repository files navigation

GitHub Action to List Go Platforms

⚖️ MIT 🎬 Action 🧪 Test

This action creates a JSON array of Go-supported platform objects. The output of go tool dist list -json generates the initial list, but various inputs allow for the winnowing of the list. The action also adds an OS-relevant emoji and GitHub runner to each object.

Here's an example:

name: 🏗️ Build
on:
  push:
jobs:
  list:
    name: 📋 List Platforms
    runs-on: ubuntu-latest
    outputs:
      platforms: ${{ steps.list.outputs.platforms }}
    steps:
      - name: Checkout
        uses: actions/checkout@v4
      - name: Setup Go
        uses: actions/setup-go@v5
        with: { go-version-file: go.mod }
      - name: List Platforms
        id: list
        uses: theory/go-dist-action@v0
        with:
          exclude-arch: wasm 386

  build:
    name: ${{ matrix.go.emoji }} Build ${{ matrix.go.GOOS }}/${{ matrix.go.GOARCH }}
    needs: list
    runs-on: ${{ matrix.go.runner }}-latest
    strategy:
      matrix:
        go: ${{ fromJson(needs.list.outputs.platforms) }}
    env:
      GOOS: ${{ matrix.go.GOOS }}
      GOARCH: ${{ matrix.go.GOARCH }}
    steps:
      - name: Checkout
        uses: actions/checkout@v4
      - name: Setup Go
        uses: actions/setup-go@v5
        with: { go-version-file: go.mod }
      - name: Build
        run: go build -o my_app-${{ matrix.go.GOOS }}-${{ matrix.go.GOARCH }} cmd/my_app.go
        continue-on-error: ${{ !matrix.go.FirstClass }}

The first job, list, uses the action to output a list of Go-supported platforms, excluding the wasm and 386 architectures. Note that it first installs the version of Go relevant to the project. The outputs section maps the action output to the job output named platforms. This job runs on an Ubuntu runner, but it should work equally well on any runner that supports Go.

The second job, build, depends on the list job, and parses its output into the go matrix value. With the matrix set, it customizes the build name and GitHub runner and sets the GOOS and GOARCH environment variables, which determine the platform for which go build compiles the binary. The Build step also sets continue-on-error to true for non-first-class platforms. This ensures that all first class platforms must compile without error, but ignores errors from non-first class platform builds.

Input Parameters

This action takes the following parameters:

Key Type Default Description
exclude-os string "" Space-delimited list of OSes to exclude
exclude-arch: string "" Space-delimited list of architectures to exclude
first-class-only boolean false Set to true to list only first-class ports
with-cgo-only boolean false Set to true to list only cgo-enabled ports

Output Parameters

Key Type Description
list JSON JSON array of platform objects

Each object in the array has the following keys:

Key Type Description
GOOS string The OS name
GOARCH: string The architecture name
CgoSupported boolean True if the platform supports cgo
FirstClass boolean True if the platform is considered a first-class port
runner string A likely GitHub runner: ubuntu, macos, or windows
emoji string A single emoji relevant to the OS name

Example:

  {
    "GOOS": "linux",
    "GOARCH": "arm64",
    "CgoSupported": true,
    "FirstClass": true,
    "runner": "ubuntu",
    "emoji": "🐧"
  }

About

GitHub action to generate a list of Platforms supported by Go

Resources

License

Stars

Watchers

Forks

Packages

No packages published