name: Test

# Default to 'contents: read', which grants actions to read commits.
#
# If any permission is set, any permission not included in the list is
# implicitly set to "none".
#
# see https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#permissions
permissions:
  contents: read

on: [push, pull_request]

concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

jobs:
  test:
    strategy:
      matrix:
        go: ["1.18.x", "1.22.x", "1.23.x"]
        platform: [ubuntu-latest, windows-latest, macos-latest]
    runs-on: ${{ matrix.platform }}
    steps:
    - name: Install Go ${{ matrix.go }}
      uses: actions/setup-go@v5
      with:
        go-version: ${{ matrix.go }}
    - name: Checkout code
      uses: actions/checkout@v4
    - name: Test
      run: go test -v ./...
  lint:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v4
      - name: go mod tidy
        run: |
          go mod tidy
          git diff --exit-code
      - name: Lint
        run: |
          docker run --rm -v ./:/go/src/github.com/moby/term -w /go/src/github.com/moby/term \
            golangci/golangci-lint:v1.62.2 golangci-lint run -v \
            -E gofmt \
            -E misspell \
            -E revive
