Go CI
Complete Go project continuous integration workflow, including multi-version matrix, build, test, vet and coverage.
name: Go CI
on:
push:
branches:
- main
- 'feature/**'
paths:
- '**.go'
- 'go.mod'
- 'go.sum'
pull_request:
branches:
- main
concurrency:
max: 1
exceed-action: QUEUE
permissions:
repository: read
jobs:
test:
name: Go ${{ matrix.go-version }} Test
runs-on: {ubuntu-24,x64,small}
strategy:
matrix:
go-version: ['1.21', '1.22', '1.23']
fail-fast: false
max-parallel: 3
steps:
- name: Checkout code
uses: checkout
- name: Setup Go ${{ matrix.go-version }}
uses: setup-go
with:
go-version: ${{ matrix.go-version }}
cache: true
- name: Go Vet Code Check
run: go vet ./...
- name: Go fmt Format Check
run: |
output=$(gofmt -l .)
if [ -n "$output" ]; then
echo "The following files are not properly formatted:"
echo "$output"
exit 1
fi
- name: Download Dependencies
run: go mod download
- name: Dependency Integrity Check
run: go mod verify
- name: Go Unit Test
run: go test -v -race -count=1 ./...
- name: Go Test Coverage
run: |
go test -race -coverprofile=coverage.out -covermode=atomic ./...
go tool cover -func=coverage.out
- name: Coverage Summary
if: ${{ always }}
run: |
echo "## Go Test Coverage - Go ${{ matrix.go-version }}" >> $ATOMGIT_STEP_SUMMARY
go tool cover -func=coverage.out >> $ATOMGIT_STEP_SUMMARY
build:
name: Go Build
needs: test
runs-on: {ubuntu-24,x64,small}
steps:
- name: Checkout code
uses: checkout
- name: Setup Go
uses: setup-go
with:
go-version: '1.23'
cache: true
- name: Build Binary
run: go build -v -o bin/app ./cmd/app
- name: Upload Artifact
uses: upload-artifact
with:
name: go-binary
path: bin/
retention-days: 7