# Target: test what is not standard at ubuntu latest and is known to
#         have not been fulfilled
# currently:
#  * swig 4.3, ubuntu contains 4.2, Swig_Python_AppendOutput changed functionality
#  * gsl  2.8: bspline changed functionality

name: test if pygsl is compatible with swig-4.3 and gsl-2.8

on:
  push:
    branches: [ "main" ]
  pull_request:
    branches: [ "main" ]

jobs:
  build-swig-add:
    runs-on: ubuntu-latest
    env:
      ACTIONS_RUNNER_DEBUG: true

    steps:
      - name: Checkout repository
        uses: actions/checkout@v4

      - name: Install dependencies
        run: |
          sudo apt-get update
          sudo apt-get install dpkg-dev

      - name: Build swig 4.3
        uses: ./.github/actions/build-deb
        with:
          name: "Swig 4.3"
          artifactName: "swig-4.3"
          # need not be a dir here, but for consistency to other build/test steps
          cachePath: ${{ github.workspace }}/deb/
          sourceDownloadScript: "compat/download-swig4.3.sh"
          sourceTar: "swig4.3_ubuntu_src.tar"
          buildCommands: |
            mkdir -p deb/
            (cd build && dpkg-source -x src/swig*.dsc)
            (cd build/swig-4.3.0 && sudo apt-get build-dep . && dpkg-buildpackage -us -uc)
            mv build/swig_4.3.0-1_amd64.deb ${{ github.workspace }}/deb/swig4.3_arch.deb
            touch ${{ github.workspace }}/deb/swig4.3_arch.deb
            find . -name '*.deb'
          uploadPaths: |
            ${{ github.workspace }}/deb/swig4.3_arch.deb

  build-gsl-add:
    runs-on: ubuntu-latest
    env:
      ACTIONS_RUNNER_DEBUG: true

    steps:
      - name: Checkout repository
        uses: actions/checkout@v4

      - name: Build gsl 2.8
        uses: ./.github/actions/build-deb
        with:
          name: "GSL 2.8"
          artifactName: "gsl-2.8"
          # must be dir, more than one file
          cachePath: ${{ github.workspace }}/deb/
          sourceDownloadScript: "compat/download-gsl-2.8.sh"
          sourceTar: "gsl2.8_ubuntu_src.tar"
          buildCommands: |
            mkdir -p deb/
            (cd build && dpkg-source -x src/gsl*.dsc)
            (cd build/gsl-2.8+dfsg && sudo apt-get build-dep . && dpkg-buildpackage -us -uc)
            # useful to see if package names have changed down the line
            find . -name '*.deb'
            mv build/libgsl28_2.8+dfsg-5.1ubuntu1_amd64.deb      ${{ github.workspace }}/deb/libgsl_2.8_arch.deb
            mv build/libgsl-dev_2.8+dfsg-5.1ubuntu1_amd64.deb    ${{ github.workspace }}/deb/libgsl-dev-2.8_arch.deb
            mv build/libgslcblas0_2.8+dfsg-5.1ubuntu1_amd64.deb  ${{ github.workspace }}/deb/libgslcblas0-2.8_arch.deb
            mv build/gsl-bin_2.8+dfsg-5.1ubuntu1_amd64.deb       ${{ github.workspace }}/deb/gsl-bin_2.8_arch.deb
            # touch ${{ github.workspace }}/deb/libgsl_2.8_arch.deb
            # touch ${{ github.workspace }}/deb/libgsl-dev-2.8_arch.deb
            # touch ${{ github.workspace }}/deb/libgslcblas0-2.8_arch.deb
            # touch ${{ github.workspace }}/deb/gsl-bin_2.8_arch.deb
            ls -l ${{ github.workspace }}/deb/libgsl_2.8_arch.deb
            ls -l ${{ github.workspace }}/deb/libgsl-dev-2.8_arch.deb
            ls -l ${{ github.workspace }}/deb/libgslcblas0-2.8_arch.deb
            ls -l ${{ github.workspace }}/deb/gsl-bin_2.8_arch.deb
          uploadPaths: |
            ${{ github.workspace }}//deb/libgsl_2.8_arch.deb
            ${{ github.workspace }}//deb/libgsl-dev-2.8_arch.deb
            ${{ github.workspace }}//deb/libgslcblas0-2.8_arch.deb
            ${{ github.workspace }}//deb/gsl-bin_2.8_arch.deb

  test-swig-additional:
    runs-on: ubuntu-latest
    needs: build-swig-add

    env:
      ACTIONS_RUNNER_DEBUG: true

    steps:
      - name: Checkout repository
        uses: actions/checkout@v4

      - name: Test swig 4.3
        uses: ./.github/actions/test-artifact
        with:
          artifactName: swig-4.3
          installCommand: "sudo dpkg -i deb/swig4.3_arch.deb"
          dependencies: "libgsl-dev python3-dev python3-pip python3-venv"

  test-gsl-additional:
    runs-on: ubuntu-latest
    needs: build-gsl-add

    env:
      ACTIONS_RUNNER_DEBUG: true

    steps:
      - name: Checkout repository
        uses: actions/checkout@v4

      - name: Test gsl 2.8
        uses: ./.github/actions/test-artifact
        with:
          artifactName: gsl-2.8
          installCommand: "sudo dpkg -i deb/libgsl-dev-2.8_arch.deb deb/libgslcblas0-2.8_arch.deb deb/libgsl_2.8_arch.deb"
          dependencies: "swig python3-dev python3-pip python3-venv"
