name: Run apidiff

on: [ pull_request ]

permissions:
  contents: read

jobs:
  apidiff:
    runs-on: ubuntu-latest
    if: github.base_ref
    steps:
      - name: Install Go
        uses: actions/setup-go@cdcb36043654635271a94b9a6d1392de5bb323a7 # v5.0.1
        with:
          go-version: 1.21.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@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
        with:
          ref: ${{ github.base_ref }}
          path: "old"
      - name: Checkout new code
        uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
        with:
          path: "new"
      - name: APIDiff
        run: ./_tools/apidiff.sh -d ../old
        working-directory: "new"
