name: ABI Check

on:
  push:
    branches: [master]
  pull_request:
  workflow_dispatch:

permissions: read-all

jobs:
  build:
    name: Build ${{ matrix.ref }}
    runs-on: ubuntu-24.04
    strategy:
      fail-fast: false
      matrix:
        ref: [v1.5, v1.6, master]

    steps:
      - uses: actions/checkout@v6
        with:
          ref: ${{ matrix.ref }}

      - name: Install deps
        run: |
          sudo apt-get update
          sudo apt-get install -y --no-install-recommends \
            qt6-base-dev libqt6core5compat6-dev \
            zlib1g-dev libbz2-dev

      - name: Configure
        run: |
          cmake -B build \
            -DCMAKE_BUILD_TYPE=RelWithDebInfo \
            -DBUILD_SHARED_LIBS=ON \
            -DQUAZIP_ENABLE_TESTS=OFF \
            -DQUAZIP_QT_MAJOR_VERSION=6

      - name: Build
        run: cmake --build build

      - name: Collect artifacts
        run: |
          mkdir -p artifacts/lib artifacts/include
          cp -L build/quazip/libquazip1-qt6.so artifacts/lib/
          cp quazip/*.h artifacts/include/

      - uses: actions/upload-artifact@v7
        with:
          name: abi-${{ matrix.ref }}
          path: artifacts/
          retention-days: 1

  abidiff:
    name: ${{ matrix.base }} vs ${{ matrix.head }}
    needs: build
    runs-on: ubuntu-24.04
    strategy:
      fail-fast: false
      matrix:
        include:
          - base: v1.5
            head: v1.6
          - base: v1.6
            head: master
          - base: v1.5
            head: master

    steps:
      - name: Install abigail-tools
        run: |
          sudo apt-get update
          sudo apt-get install -y --no-install-recommends abigail-tools

      - uses: actions/download-artifact@v8
        with:
          name: abi-${{ matrix.base }}
          path: base/

      - uses: actions/download-artifact@v8
        with:
          name: abi-${{ matrix.head }}
          path: head/

      - name: abidiff ${{ matrix.base }} → ${{ matrix.head }}
        run: |
          abidiff \
            --headers-dir1 base/include \
            --headers-dir2 head/include \
            base/lib/libquazip1-qt6.so \
            head/lib/libquazip1-qt6.so || true
