name: Go CI
'on':
  pull_request:
  push:
    branches: [main]
permissions:
  contents: read
concurrency:
  group: ci-${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true
jobs:
  verify:
    runs-on: ubuntu-24.04
    timeout-minutes: 15
    env:
      GOTOOLCHAIN: local
    steps:
      - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
        with:
          persist-credentials: false
      - uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
        with:
          go-version: '1.27.2'
          cache: false
      - run: go test ./...
      - run: go test -race ./...
      - run: go vet ./...
      - name: Build once
        if: github.event_name == 'push' && github.ref == 'refs/heads/main'
        run: |
          mkdir -p dist
          CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -trimpath -buildvcs=false -o dist/app .
          (cd dist && sha256sum app > SHA256SUMS)
          go version -m dist/app > dist/build-info.txt
      - name: Save reviewed-branch artifact
        if: github.event_name == 'push' && github.ref == 'refs/heads/main'
        uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
        with:
          name: app-${{ github.sha }}-${{ github.run_id }}
          path: dist/
          if-no-files-found: error
          retention-days: 7
