on:   # yamllint disable-line rule:truthy
  pull_request:

name: Check semver breaks

jobs:
  PR:
    name: PR Semver - stable toolchain
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
    steps:
      - name: "Checkout repo"
        uses: actions/checkout@v4
        with:
          fetch-depth: 0 # we need full history for cargo semver-checks
      - name: "Install Rustup"
        uses: dtolnay/rust-toolchain@stable
      - name: "Select stable-version"
        run: |
          rustup default $(cat ./.github/workflows/stable-version)
      - name: "Install cargo-binstall"
        uses: cargo-bins/cargo-binstall@main
      - name: "Binstall pinned cargo-semver-checks"
        run: cargo binstall cargo-semver-checks@$(cat ./.github/workflows/cargo-semver-checks-version) --no-confirm
      - name: "Run semver checker script"
        run: ./contrib/check-semver-pr.sh
      - name: Save PR number
        if: ${{ hashFiles('semver-break') != '' }}
        env:
          PR_NUMBER: ${{ github.event.number }}
        run: |
          # check if PR_NUMBER is a number
          if ! [[ "$PR_NUMBER" =~ ^-?[0-9]+$ ]]; then
              echo "$PR_NUMBER is not a number."
              exit 1
          fi
          echo "$PR_NUMBER" > ./semver-break
      - name: "Save breaking state"
        if: ${{ hashFiles('semver-break') != '' }}
        uses: actions/upload-artifact@v4
        with:
          name: semver-break
          path: semver-break

  Feature:
    name: Non additive cargo features - stable toolchain
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
    steps:
      - name: "Checkout repo"
        uses: actions/checkout@v4
      - name: "Install Rustup"
        uses: dtolnay/rust-toolchain@stable
      - name: "Select stable-version"
        run: |
          rustup default $(cat ./.github/workflows/stable-version)
      - name: "Install cargo-binstall"
        uses: cargo-bins/cargo-binstall@main
      - name: "Binstall pinned cargo-semver-checks"
        run: cargo binstall cargo-semver-checks@$(cat ./.github/workflows/cargo-semver-checks-version) --no-confirm
      - name: "Run semver checker script"
        run: ./contrib/check-semver-feature.sh

