name: Build SWIG bindings

on: [push, pull_request]

env:
  BUILD_TYPE: Release

jobs:
  build:
    name: ${{ matrix.config.name }}
    runs-on: ${{ matrix.config.os }}
    strategy:
      fail-fast: false
      matrix:
        config:
        - {
            name: "Linux SWIG All Bindings",
            os: ubuntu-latest,
            cc: "gcc", cxx: "g++",
            cmake_flags: "-DPYTHON_BINDINGS=ON -DPERL_BINDINGS=ON -DRUBY_BINDINGS=ON -DJAVA_BINDINGS=ON -DCSHARP_BINDINGS=ON -DRUN_SWIG=ON "
          }

    steps:
    - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2

    - name: Install Dependencies (Linux)
      if: runner.os == 'Linux'
      run: |
        sudo apt-get -qq update
        sudo apt-get -qq install ninja-build swig libeigen3-dev libboost-all-dev r-base-core r-base-dev mono-devel

    - name: Configure
      run: |
        mkdir "${{ runner.workspace }}/../build"
        cd "${{ runner.workspace }}/../build"
        cmake $GITHUB_WORKSPACE -GNinja -DCSHARP_EXECUTABLE=mcs -DCMAKE_C_COMPILER=${{matrix.config.cc}} -DCMAKE_CXX_COMPILER=${{matrix.config.cxx}} -DCMAKE_CXX_FLAGS="-Wno-error=deprecated-declarations" ${{matrix.config.cmake_flags}}
      shell: bash
      working-directory: ${{ runner.workspace }}/openbabel

    - name: Build
      run: CC=${{matrix.config.cc}} CXX=${{matrix.config.cxx}} cmake --build .
      shell: bash
      working-directory: ${{ runner.workspace }}/../build

    - name: Packing
      run: |
        tar --exclude-vcs --exclude-backups --exclude='.github*' -cvjf openbabel-latest.tar.bz2 openbabel
      working-directory: ${{ runner.workspace }}

    - name: Upload
      uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
      with:
        path: ${{ runner.workspace }}/openbabel-latest.tar.bz2
        name: openbabel.tar.bz2
