name: Checks

on:
  push:
  workflow_dispatch:
  pull_request:

jobs:
  unit_tests:
    strategy:
      matrix:
        include:
          - runs-on: ubuntu-latest
            target: linux_amd64
          - runs-on: windows-latest
            target: windows_amd64
          - runs-on: macos-latest
            target: darwin_amd64
      fail-fast: false

    name: "Unit Tests on ${{ matrix.target }}"
    runs-on: "${{ matrix.runs-on }}"
    steps:
      - name: "Disable git crlf conversions"
        if: ${{ runner.os == 'Windows' }}
        # HCL preserves the input line endings when processing a heredoc,
        # and our tests for heredocs are written to expect the result for
        # the source code as checked in to the repository, so git's normal
        # tampering with the line endings would invalidate those tests.
        run: |
          git config --global core.autocrlf false
      - name: "Fetch source code"
        uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
      - name: Install Go
        uses: actions/setup-go@cdcb36043654635271a94b9a6d1392de5bb323a7 # v5.0.1
        with:
          go-version-file: go.mod
      - name: Go test
        run: |
          go test ./... -race

  copyright:
    name: "copyright headers"
    runs-on: ubuntu-latest
    steps:
      - name: "Fetch source code"
        uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
      - name: Install Go
        uses: actions/setup-go@cdcb36043654635271a94b9a6d1392de5bb323a7 # v5.0.1
        with:
          go-version-file: go.mod
      - name: "copyright headers check"
        run: |
          make copyrightcheck

  govet:
    name: "go vet"
    runs-on: ubuntu-latest
    steps:
      - name: "Fetch source code"
        uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
      - name: Install Go
        uses: actions/setup-go@cdcb36043654635271a94b9a6d1392de5bb323a7 # v5.0.1
        with:
          go-version-file: go.mod
      - name: "go vet"
        run: |
          make vetcheck

  gofmt:
    name: "gofmt"
    runs-on: ubuntu-latest
    steps:
      - name: "Fetch source code"
        uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
      - name: Install Go
        uses: actions/setup-go@cdcb36043654635271a94b9a6d1392de5bb323a7 # v5.0.1
        with:
          go-version-file: go.mod
      - name: "gofmt"
        run: |
          make fmtcheck
