name: non-regression tests

on: [pull_request]

jobs:
  win:
    runs-on: windows-2016
    strategy:
      matrix:
        arch: [x86_64, i686]
        ui: [cli, gui]
        printf: [fmtdbg, normal]
        include:
          - arch: x86_64
            msystem: MINGW64
            grep: x86-64
          - arch: i686
            msystem: MINGW32
            grep: 386
          - ui: cli
            clionly: --with-cli-only
          - printf: fmtdbg
            debugprintf: --with-debug-printf-format
    defaults:
      run:
        shell: msys2 {0}
    steps:
    - uses: msys2/setup-msys2@v2
      with:
        msystem: ${{ matrix.msystem }}
        update: false
        install: git diffutils make pkg-config mingw-w64-${{ matrix.arch }}-glib2 mingw-w64-${{ matrix.arch }}-gcc mingw-w64-${{ matrix.arch }}-ghostscript mingw-w64-${{ matrix.arch }}-ntldd-git man zip
    - name: install GUI prereqs
      if: matrix.ui == 'gui'
      run: pacman -S --noconfirm mingw-w64-${{ matrix.arch }}-gtk2
    - name: git config
      run: git config --global core.autocrlf input
      shell: bash
    - uses: actions/checkout@v2
    - name: configure
      run: |
          echo running ./configure ${{ matrix.clionly }} ${{ matrix.debugprintf }} --with-werror
          ./configure ${{ matrix.clionly }} ${{ matrix.debugprintf }}    --with-werror
    - name: make
      run: nproc && make -j$(nproc)
    - name: check executable
      run: |
          ./dvdisaster.exe --version
          file dvdisaster.exe
          if ./dvdisaster.exe --version | grep dirty; then exit 1; fi
          file dvdisaster.exe | grep -q '${{ matrix.grep }}, for MS Windows'
    - name: check executable (GUI)
      if: matrix.ui == 'gui'
      run: |
          ./dvdisaster.exe --version
          if ./dvdisaster.exe --version | grep NOGUI; then exit 1; fi
    - name: check executable (CLI)
      if: matrix.ui == 'cli'
      run: |
          ./dvdisaster.exe --version
          ./dvdisaster.exe --version | grep NOGUI
    - name: try to prepare dist
      run: ./.github/workflows/make-dist.sh ${{ github.ref }}
    - name: run regression tests
      if: matrix.printf == 'normal'
      env:
        REGTEST_NO_UTF8: 1
      run: mkdir /var/tmp/regtest && ./regtest/runtests.sh

  linux:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        ui: [cli, gui]
        printf: [fmtdbg, normal]
        include:
          - ui: cli
            clionly: --with-cli-only
          - printf: fmtdbg
            debugprintf: --with-debug-printf-format
    steps:
    - uses: actions/checkout@v2
    - name: install prerequisites
      env:
        DEBIAN_FRONTEND: noninteractive
      run: sudo apt-get update && sudo apt-get install -y libglib2.0-dev ghostscript man jq
    - name: install prerequisites (GUI)
      if: matrix.ui == 'gui'
      env:
        DEBIAN_FRONTEND: noninteractive
      run: sudo apt-get install -y libgtk2.0-dev
    - name: configure
      run: |
          echo ./configure ${{ matrix.clionly }} ${{ matrix.debugprintf }} --with-werror
          ./configure ${{ matrix.clionly }} ${{ matrix.debugprintf }} --with-werror
    - name: make
      run: nproc && make -j$(nproc)
    - name: check executability
      run: ./dvdisaster --version
    - name: check executable (GUI)
      if: matrix.ui == 'gui'
      run: |
          ./dvdisaster --version
          if ./dvdisaster --version | grep NOGUI; then exit 1; fi
    - name: check executable (CLI)
      if: matrix.ui == 'cli'
      run: |
          ./dvdisaster --version
          ./dvdisaster --version | grep NOGUI
    - name: prepare dist
      run: ./.github/workflows/make-dist.sh ${{ github.ref }}
    - name: regression tests
      if: matrix.printf == 'normal'
      env:
        REGTEST_NO_UTF8: 1
      run: mkdir /var/tmp/regtest && ./regtest/runtests.sh
