name: Checks

on: [push, pull_request]

jobs:
  Unix:
    strategy:
      matrix:
        os: [ubuntu-latest, macos-latest]
        environement: [normal, minified, minimal, minimal-with-xml]
        include:
          - environement: normal
            CXXFLAGS: ""
            RUN_TESTS: "all"
          - environement: minified
            CXXFLAGS: "-DMEDIAINFO_ADVANCED_NO -DMEDIAINFO_ARCHIVE_NO -DMEDIAINFO_DEMUX_NO -DMEDIAINFO_DVDIF_ANALYZE_NO -DMEDIAINFO_EVENTS_NO -DMEDIAINFO_LIBCURL_NO -DMEDIAINFO_LIBMMS_NO -DMEDIAINFO_MD5_NO -DMEDIAINFO_MINIMAL_YES -DMEDIAINFO_MPEGTS_DUPLICATE_NO -DMEDIAINFO_N19_NO -DMEDIAINFO_OTHERTEXT_NO -DMEDIAINFO_TRACE_NO -DMEDIAINFO_READTHREAD_NO -DMEDIAINFO_EXPORT_NO -DMEDIAINFO_TEXT_YES"
            RUN_TESTS: "no"
          - environement: minimal
            CXXFLAGS: "-DMEDIAINFO_ADVANCED_NO -DMEDIAINFO_CONFORMANCE_NO -DMEDIAINFO_REFERENCES_NO -DMEDIAINFO_FILTER_NO -DMEDIAINFO_DUPLICATE_NO -DMEDIAINFO_MACROBLOCKS_NO -DMEDIAINFO_TRACE_NO -DMEDIAINFO_TRACE_FFV1CONTENT_NO -DMEDIAINFO_IBI_NO -DMEDIAINFO_DIRECTORY_NO -DMEDIAINFO_LIBCURL_NO -DMEDIAINFO_LIBMMS_NO -DMEDIAINFO_DVDIF_ANALYZE_NO -DMEDIAINFO_MPEGTS_DUPLICATE_NO -DMEDIAINFO_READTHREAD_NO -DMEDIAINFO_MD5_NO -DMEDIAINFO_SHA1_NO -DMEDIAINFO_SHA2_NO -DMEDIAINFO_EVENTS_NO -DMEDIAINFO_DEMUX_NO -DMEDIAINFO_AES_NO -DMEDIAINFO_FIXITY_NO -DMEDIAINFO_READER_NO -DMEDIAINFO_NEXTPACKET_NO"
            RUN_TESTS: "no"
          - environement: minimal-with-xml
            CXXFLAGS: "-DMEDIAINFO_ADVANCED_NO -DMEDIAINFO_CONFORMANCE_NO -DMEDIAINFO_REFERENCES_NO -DMEDIAINFO_FILTER_NO -DMEDIAINFO_DUPLICATE_NO -DMEDIAINFO_MACROBLOCKS_NO -DMEDIAINFO_TRACE_NO -DMEDIAINFO_TRACE_FFV1CONTENT_NO -DMEDIAINFO_IBI_NO -DMEDIAINFO_DIRECTORY_NO -DMEDIAINFO_LIBCURL_NO -DMEDIAINFO_LIBMMS_NO -DMEDIAINFO_DVDIF_ANALYZE_NO -DMEDIAINFO_MPEGTS_DUPLICATE_NO -DMEDIAINFO_READTHREAD_NO -DMEDIAINFO_MD5_NO -DMEDIAINFO_SHA1_NO -DMEDIAINFO_SHA2_NO -DMEDIAINFO_EVENTS_NO -DMEDIAINFO_DEMUX_NO -DMEDIAINFO_AES_NO -DMEDIAINFO_FIXITY_NO -DMEDIAINFO_NEXTPACKET_NO -DMEDIAINFO_ALL_NO -DMEDIAINFO_MIXML_YES"
            RUN_TESTS: "mixml"
      fail-fast: false
    runs-on: ${{ matrix.os }}
    env:
      S3_KEY: ${{ secrets.S3_KEY }}
      S3_PASS: ${{ secrets.S3_PASS }}
      CXXFLAGS: ${{ matrix.CXXFLAGS }}
      RUN_TESTS: ${{ matrix.RUN_TESTS }}
    steps:
      - name: Checkout
        uses: actions/checkout@v3
        with:
          fetch-depth: 1
      - name: Dependencies
        run: |
          if [ "$RUNNER_OS" == "Linux" ]; then
            sudo apt-get update -y
            sudo apt-get install -y libxml2-utils zlib1g-dev libcurl4-gnutls-dev libmms-dev
          fi
          if [ "$RUNNER_OS" == "macOS" ]; then
            brew install libtool automake pkg-config
          fi
          sudo npm install -g jsonlint
      - name: ZenLib
        run: |
          git -C .. clone --depth=1 https://github.com/MediaArea/ZenLib.git
          pushd ../ZenLib/Project/GNU/Library
            autoreconf -if
            ./configure --enable-static
            make
          popd
      - name: Configure
        run: |
          cd Project/GNU/Library
          autoreconf -if
          ./configure --with-libcurl=runtime
      - name: Build
        run: |
          cd Project/GNU/Library
          make
      - name: Check files
        run: |
          cd Project/GNU/Library
          make clone_regression_files
      - name: Check
        run: |
          cd Project/GNU/Library
          make check
      - name: CMake Build
        if: ${{ matrix.environement == 'normal' }}
        run: |
          mkdir Project/CMake/Build
          cd Project/CMake/Build
          cmake -DBUILD_ZENLIB=1 ..
          make
