Skip to content

More cleanup + fixes for workflows #2

More cleanup + fixes for workflows

More cleanup + fixes for workflows #2

Workflow file for this run

name: test
on:
push:
branches: [main]
pull_request:
workflow_dispatch:
permissions:
contents: read
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
# Native build + test on every platform that has a hosted runner. The
# prebuilt archives under libmagic/ are static, so there is nothing to
# install -- but each platform has its own #cgo LDFLAGS line, and the only
# way to know a line is complete is to link it.
test:
name: test ${{ matrix.name }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- {name: linux/amd64, os: ubuntu-latest}
# Hosted arm64 Linux. Free for public repos; private repos need a
# paid plan, in which case drop this entry.
- {name: linux/arm64, os: ubuntu-24.04-arm}
- {name: macos/amd64, os: macos-13}
- {name: macos/arm64, os: macos-14}
- {name: windows/amd64, os: windows-latest}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: go.mod
cache: true
# The runner images ship mingw-w64, but where gcc lands has moved
# around, so find it rather than assume it is on PATH.
- name: Locate a C compiler (Windows)
if: runner.os == 'Windows'
shell: pwsh
run: |
if (Get-Command gcc -ErrorAction SilentlyContinue) { exit 0 }
$cands = @(
'C:\mingw64\bin',
'C:\ProgramData\mingw64\mingw64\bin',
'C:\Strawberry\c\bin'
) | Where-Object { Test-Path (Join-Path $_ 'gcc.exe') }
if ($cands.Count -eq 0) {
choco install -y --no-progress mingw
$cands = @('C:\ProgramData\mingw64\mingw64\bin')
}
$cands[0] | Out-File -Append -Encoding utf8 $env:GITHUB_PATH
- name: Environment
shell: bash
run: |
go version
go env GOOS GOARCH CGO_ENABLED CC
gcc --version || cc --version || true
- name: Build
run: go build ./...
- name: Vet
run: go vet ./...
# -race is what backs the "safe to share a handle" claim in the docs:
# TestConcurrent drives one cookie from 16 goroutines.
- name: Test
run: go test -race -count=1 -v ./...
- name: Smoke test cmd/file
run: go run ./cmd/file testdata/gif.gif testdata/utf8.txt testdata/xlsx.xlsx