name: Test
on: [push, pull_request]
jobs:
  test:
    strategy:
      matrix:
        go-versions: [1.14.x, 1.15.x, 1.16.x, 1.17.x]
        platform: [ubuntu-latest, macos-latest, windows-latest]
    runs-on: ${{ matrix.platform }}
    steps:
    - name: Install Go
      uses: actions/setup-go@v1
      with:
        go-version: ${{ matrix.go-version }}
    - name: Checkout code
      uses: actions/checkout@v2
    - name: Test
      run: |
        go get -t -v ./...
        go test -v -race ./...
        cd hack/tools && go test -v -race ./...
  lint:
    runs-on: ubuntu-latest
    steps:
      - name: Install Go
        uses: actions/setup-go@v1
      - name: Checkout code
        uses: actions/checkout@v2
      - name: Lint
        run: |
          docker run --rm -v `pwd`:/go/src/k8s.io/klog -w /go/src/k8s.io/klog \
            golangci/golangci-lint:v1.23.8 golangci-lint run --disable-all -v \
            -E govet -E misspell -E gofmt -E ineffassign -E golint
  apidiff:
    runs-on: ubuntu-latest
    if: github.base_ref
    steps:
      - name: Install Go
        uses: actions/setup-go@v1
        with:
          go-version: 1.13.x
      - name: Add GOBIN to PATH
        run: echo "PATH=$(go env GOPATH)/bin:$PATH" >>$GITHUB_ENV
      - name: Install dependencies
        run: GO111MODULE=off go get golang.org/x/exp/cmd/apidiff
      - name: Checkout old code
        uses: actions/checkout@v2
        with:
          ref: ${{ github.base_ref }}
          path: "old"
      - name: Checkout new code
        uses: actions/checkout@v2
        with:
          path: "new"
      - name: APIDiff
        run: ./hack/verify-apidiff.sh -d ../old
        working-directory: "new"
