name: Generate

on:
  push:
    branches:
      - release-*
      - mq-working-branch-**
  pull_request:
  workflow_call:
    inputs:
      go-version:
        required: true
        type: string
      ref:
        description: 'The branch to run the workflow on'
        required: true
        type: string

env:
  # Users may build our library with GOTOOLCHAIN=local. If they do, and our
  # go.mod file specifies a newer Go version than their local toolchain, their
  # build will break. Run our tests with GOTOOLCHAIN=local to ensure that
  # our library builds with all of the Go versions we claim to support,
  # without having to download a newer one.
  GOTOOLCHAIN: local

permissions:
  contents: read

jobs:
  generate:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
        with:
          ref: ${{ inputs.ref || github.ref }}
      - name: Setup Go and development tools
        uses: ./.github/actions/setup-go
        with:
          go-version: ${{ inputs.go-version }}
          tools-dir: ${{ github.workspace }}/_tools
          tools-bin: ${{ github.workspace }}/bin
      - name: Run generator
        run: |-
          export PATH="${{ github.workspace }}/bin:${PATH}"
          ./scripts/generate.sh
      - name: Check for changes
        run: git diff --exit-code
