name: Build

on:
  push:
    branches: [ public ]
  pull_request:
    branches: [ public ]

jobs:
  unix-build:

    runs-on: ubuntu-latest
    defaults:
      run:
        shell: bash
    
    strategy:
      fail-fast: false
      matrix:
        config:
          - name: default build with debug
            options: --enable-debug
          - name: bulid with internal libs
            options: --with-zlib=no --with-libxml2=no
          - name: build without encryption
            options: --disable-encryption

    steps:
    - uses: actions/checkout@v4
    - name: install dependencies
      run: |
        if [ "${{ runner.os }}" = "Linux" ]; then
          sudo apt-get update -qq;
          sudo apt-get install -y autotools-dev pkg-config automake autoconf libtool;
          sudo apt-get install -y zlib1g-dev libxml2-dev;
        elif [ "${{ runner.os }}" = "macOS" ]; then
          brew update > /dev/null;
          brew outdated autoconf || brew upgrade autoconf;
          brew outdated automake || brew upgrade automake;
          brew outdated libtool || brew upgrade libtool;
        fi
    - name: autogen
      run: ./autogen.sh
    - name: configure
      run: ./configure ${{ matrix.config.options }}
    - name: make
      run: make -j `nproc`
    - name: make check
      run: make -j `nproc` check
    - name: make distcheck
      run: make -j `nproc` distcheck
    - name: upload debug artifacts
      uses: actions/upload-artifact@v4
      if: ${{ failure() }}
      with:
        name: test-logs-${{ matrix.runs-on }}
        path: |
          **/tests/test-suite.log
          **/tests/samples/*.log

  win64-build:

    runs-on: windows-latest
    defaults:
      run:
        shell: msys2 {0}
    steps:
    - name: setup-msys2
      uses: msys2/setup-msys2@v2
      with:
        msystem: MINGW64
        path-type: minimal
        update: true
        install: >-
          git
          autotools
          base-devel
          mingw-w64-x86_64-toolchain
          mingw-w64-x86_64-libtool
          mingw-w64-x86_64-libxml2
          mingw-w64-x86_64-zlib
    - name: checkout
      uses: actions/checkout@v4
    - name: autogen
      run: sh ./autogen.sh
    - name: configure
      run: ./configure --enable-debug
    - name: make
      run: make -j$(nproc)
    - name: make check
      run: make -j$(nproc) check
    - name: make distcheck
      run: make -j$(nproc) distcheck
    - name: upload debug artifacts
      uses: actions/upload-artifact@v4
      if: ${{ failure() }}
      with:
        name: test-logs-${{ matrix.runs-on }}
        path: |
          **/tests/test-suite.log
          **/tests/samples/*.log
