Files

53 lines
1.2 KiB
YAML

name: Go Format
on:
workflow_call:
inputs:
go-version-file:
description: "Path to go.mod for version resolution"
type: string
default: "go.mod"
run-vet:
description: "Also run go vet"
type: boolean
default: true
jobs:
fmt:
name: gofmt
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: ${{ inputs.go-version-file }}
cache: true
- name: Check formatting
run: |
unformatted=$(gofmt -l .)
if [ -n "$unformatted" ]; then
echo "::error::The following files are not gofmt-formatted:"
echo "$unformatted"
echo ""
echo "Run: gofmt -w ."
exit 1
fi
vet:
name: go vet
runs-on: ubuntu-latest
needs: fmt
if: ${{ inputs.run-vet }}
steps:
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: ${{ inputs.go-version-file }}
cache: true
- name: go vet
run: go vet ./...