name: ci-pipeline

on:
  push:
    branches: [ "*" ]
  pull_request:
    branches: [ "*" ]

jobs:

  ci:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
      with:
        path: src/sigs.k8s.io/json/        

    - name: Set up Go
      uses: actions/setup-go@v2
      with:
        go-version: "1.x"
        stable: true
        check-latest: true

    - name: Test
      run: |
        cd ${GITHUB_WORKSPACE}/src/sigs.k8s.io/json/
        make test
    - name: Benchmark
      run: |
        cd ${GITHUB_WORKSPACE}/src/sigs.k8s.io/json/
        make benchmark
    - name: Vet
      run: |
        cd ${GITHUB_WORKSPACE}/src/sigs.k8s.io/json/
        make vet
    - name: fmt
      run: |
        cd ${GITHUB_WORKSPACE}/src/sigs.k8s.io/json/
        make fmt
        git diff --exit-code

  apidiff:
    runs-on: ubuntu-latest
    if: github.base_ref
    steps:
      - name: Install Go
        uses: actions/setup-go@v2
        with:
          go-version: '1.x'
      - name: Add GOBIN to PATH
        run: echo "$(go env GOPATH)/bin" >> $GITHUB_PATH
      - name: Install dependencies
        run: go install golang.org/x/exp/cmd/apidiff@latest
      - 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"


