---
name: 'libfuse ABI check against previous major release'

on:
  push:
    branches:
      - master
      - 'fuse-[0-9]+.[0-9]+*'  # This will match branches like 3.17, 3.18, 4.0, etc.
  pull_request:
    branches:
      - master
      - 'fuse-[0-9]+.[0-9]+*'
permissions:
  contents: read

jobs:
  abi:
    runs-on: '${{ matrix.os }}'
    strategy:
      matrix:
        os:
          - ubuntu-latest

    steps:
      - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
        with:
          path: current
          fetch-depth: 0  # Fetch all history and tags

      - name: Install dependencies (Ubuntu)
        if: runner.os == 'Linux'
        run: |
          ./current/.github/workflows/install-ubuntu-dependencies.sh --abicheck

      - name: Determine previous major release tag
        id: prev_release
        run: |
          cd current
          PREV_TAG=$(.github/workflows/find_previous_release_tag.sh)
          echo "prev_tag=$PREV_TAG" >> $GITHUB_OUTPUT

      - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
        with:
          path: previous
          ref: ${{ steps.prev_release.outputs.prev_tag }}

      - uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
        with:
          python-version: '3.12'

      - name: Install Python dependencies
        run: |
          pip install -r current/requirements.txt

      - name: Run ABI check
        run: |
          echo "Previous release tag: ${{ steps.prev_release.outputs.prev_tag }}"
          current/.github/workflows/abicheck.sh --current-dir current --previous-dir previous
