GitHub Actions

On this page

setup-gomagi installs a gomagi release, checks it against checksums.txt and puts it on PATH. gomagi runs your tests with the go command, so set up Go first.

Pull requests #

Mutate only the lines a pull request changes and fail it when the score drops below a floor. --diff compares with the base branch, so the checkout needs history.

name: Mutation
on:
  pull_request:
permissions:
  contents: read
jobs:
  mutation:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v7
        with:
          fetch-depth: 0
      - uses: actions/setup-go@v7
        with:
          go-version-file: go.mod
      - uses: nao1215/setup-gomagi@v0
      - run: gomagi run --diff "origin/${{ github.base_ref }}" --min-score 80 --output gomagi.html ./...
      - uses: actions/upload-artifact@v7
        if: always()
        with:
          name: gomagi-report
          path: gomagi.html

Set the floor a little below the score of a full run of your module. Equivalent mutants cannot be killed, so 100 is rarely reachable.

How long the job takes depends on your tests more than on the number of mutants. Each mutant runs the tests that reach its line, and a mutant those tests let live runs the whole suite unless it never changes a value there. gomagi’s own pull request #6 (commit 61b823b) changed lines that held 104 mutants, and the job took 25 minutes on ubuntu-latest with --workers 4 and GOMAXPROCS 4. 20 of those minutes went to internal/engine, whose 51 tests each build and run a fixture module; every other package took under a minute. If one package has a suite that slow, leave it out of the pull request’s patterns and mutate it in a scheduled full run.

A full run split across jobs #

--shard K/N gives each job of a matrix its share of the mutants; the shares together hold every mutant once.

jobs:
  mutation:
    strategy:
      matrix:
        shard: [1, 2, 3, 4]
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v7
      - uses: actions/setup-go@v7
        with:
          go-version-file: go.mod
      - uses: nao1215/setup-gomagi@v0
      - run: gomagi run --shard ${{ matrix.shard }}/4 --output gomagi-${{ matrix.shard }}.json ./...

Reusing results between runs #

--cache stores the result of each package in the user cache directory, ~/.cache/gomagi on a Linux runner, and a later run reuses it while nothing the result depends on has changed: the package’s files and testdata, where its symbolic links point, the files of the packages its tests build from the module or from a module that a replace directive points at a local directory, go.mod, go.sum, the go settings and the go.work of a workspace, the mutants selected, the flags that change outcomes and the gomagi binary itself. It also checks what the tests read in every run, with a mutant or without, which the test binary logs as it does for go test’s cache: the environment variables they looked up, GODEBUG, and the files and directories inside the module they opened or looked at, by content rather than modification time, so a fresh checkout still hits. A test process that crashes, as one whose test panics because of a mutant, never writes its log; such a mutant runs again on every later run while the others come from the cache, and a crash without a mutant leaves the package out of the cache with a note. It is off by default and works the same on a laptop and on a runner. Keep the directory between workflow runs with actions/cache:

      - uses: actions/cache@v6
        with:
          path: ~/.cache/gomagi
          key: gomagi-${{ github.sha }}
          restore-keys: gomagi-
      - run: gomagi run --cache ./...

What the log does not show can still change an outcome without changing the result’s key, as with go test’s cache: files outside the module, a network service, the clock, an environment variable read while the package initializes, before the log starts, and what a child process the test starts reads. Leave the cache off for packages whose tests depend on those.

setup-gomagi inputs #

InputDefaultMeaning
versionlatestthe release to install, such as v1.2.3 or 1.2.3
github-tokengithub.tokentoken for the GitHub API and downloads
install-dir$HOME/.gomagi/binwhere the binary goes
verify-checksumtruecheck the archive against checksums.txt
verify-attestationfalseverify the build provenance with gh attestation verify
add-to-pathtrueadd the install directory to PATH

Its outputs are version, bin-path and install-dir.