name: CI

# .github/workflows/ci.yml 2025-12-09
# Controls when the action will run. Triggers the workflow on push or pull request
# events but only for the master branch (or test branch github_ci push)
on:
  push:
    branches: [ master, github_ci ]
  pull_request:
    branches: [ master ]

env:
  # Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
  BUILD_TYPE: Release

jobs:
  build-ubuntu:
    runs-on: ubuntu-latest

    # Steps represent a sequence of tasks that will be executed as part of the job
    steps:
    # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
    - uses: actions/checkout@v4

    - name: Install libpng-dev
      run: sudo apt-get install libpng-dev

    - name: Install GS1 Syntax Engine
      run: git clone --depth=1 https://github.com/gs1/gs1-syntax-engine && cd gs1-syntax-engine/src/c-lib && make lib && sudo make install

    - name: Install locale
      shell: bash
      run: sudo locale-gen de_DE.UTF-8 && sudo update-locale

    - name: Install Qt5
      uses: jurplel/install-qt-action@v4
      with:
        version: 5.15.2
        dir: .

    - name: Create Build Environment
      shell: bash
      run: git config --global --add safe.directory ${GITHUB_WORKSPACE} && cmake -E make_directory build

    - name: Configure CMake
      working-directory: build
      shell: bash
      run: CMAKE_PREFIX_PATH=$QT_ROOT_DIR cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DZINT_TEST=ON -DZINT_STATIC=ON

    - name: Build
      working-directory: build
      shell: bash
      run: cmake --build . -j8 --config $BUILD_TYPE

    - name: Test
      working-directory: build
      shell: bash
      run: LD_LIBRARY_PATH=$LD_LIBRARY_PATH:"$(pwd)/backend" PATH=$PATH:"$(pwd)/frontend" QT_QPA_PLATFORM=offscreen ctest -V -C $BUILD_TYPE

  build-ubuntu-debug:
    runs-on: ubuntu-latest

    env:
      BUILD_TYPE: Debug

    steps:
    - uses: actions/checkout@v4

    - name: Install libpng-dev
      run: sudo apt-get install libpng-dev

    - name: Install GS1 Syntax Engine
      run: git clone --depth=1 https://github.com/gs1/gs1-syntax-engine && cd gs1-syntax-engine/src/c-lib && make lib && sudo make install

    - name: Install locale
      shell: bash
      run: sudo locale-gen de_DE.UTF-8 && sudo update-locale

    - name: Install Qt6
      uses: jurplel/install-qt-action@v4
      with:
        version: 6.9.0
        dir: .

    - name: Create Build Environment
      shell: bash
      run: git config --global --add safe.directory ${GITHUB_WORKSPACE} && cmake -E make_directory build

    - name: Configure CMake
      working-directory: build
      shell: bash
      run: CMAKE_PREFIX_PATH=$QT_ROOT_DIR cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DZINT_TEST=ON -DZINT_STATIC=ON -DZINT_QT6=ON

    - name: Build
      working-directory: build
      shell: bash
      run: cmake --build . -j8 --config $BUILD_TYPE

    - name: Test
      working-directory: build
      shell: bash
      run: LD_LIBRARY_PATH=$LD_LIBRARY_PATH:"$(pwd)/backend" PATH=$PATH:"$(pwd)/frontend" QT_QPA_PLATFORM=offscreen ctest -V -C $BUILD_TYPE

  build-windows-32bit:
    runs-on: windows-latest

    steps:
    - uses: actions/checkout@v4

    - name: Create Build Environment
      shell: bash
      run: git config --global --add safe.directory ${GITHUB_WORKSPACE} && cmake -E make_directory build

    - name: Install zlib
      shell: bash
      run: |
        git clone --depth=1 https://github.com/madler/zlib.git zlib && cd zlib
        cmake -B build -A Win32 -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DZLIB_BUILD_TESTING=OFF -DZLIB_BUILD_SHARED=OFF -DZLIB_BUILD_MINIZIP=OFF -DZLIB_INSTALL_COMPAT_DLL=OFF
        cmake --build build --config $BUILD_TYPE
        cmake -E rename build/$BUILD_TYPE/zs.lib zlib.lib
        cmake -E rename build/zconf.h zconf.h

    - name: Install libpng
      shell: bash
      run: |
        git clone --depth=1 https://git.code.sf.net/p/libpng/code lpng && cd lpng
        cmake -B build -A Win32 -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DPNG_SHARED=OFF -DPNG_TESTS=OFF -DPNG_TOOLS=OFF -DZLIB_ROOT="${GITHUB_WORKSPACE}/zlib"
        cmake --build build --config $BUILD_TYPE
        cmake -E rename build/$BUILD_TYPE/libpng16_static.lib libpng.lib
        cmake -E rename build/pnglibconf.h pnglibconf.h

    - name: Install GS1 Syntax Engine
      shell: bash
      run: |
        git clone --depth=1 https://github.com/gitlost/gs1-syntax-engine && cd gs1-syntax-engine/src/c-lib
        cmake -B build -A Win32 -DCMAKE_BUILD_TYPE=$BUILD_TYPE
        cmake --build build --config $BUILD_TYPE
        cmake -E rename build/$BUILD_TYPE/gs1encoders.lib gs1encoders.lib

    - name: Install Qt5
      uses: jurplel/install-qt-action@v4
      with:
        version: 5.15.2
        arch: win32_msvc2019
        dir: .

    - name: Configure CMake
      working-directory: build
      shell: bash
      run: |
        cmake $GITHUB_WORKSPACE -A Win32 -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DZINT_TEST=ON -DZINT_STATIC=ON -DZLIB_ROOT="${GITHUB_WORKSPACE}/zlib" -DPNG_ROOT="${GITHUB_WORKSPACE}/lpng" -DGS1SE_PATH="${GITHUB_WORKSPACE}/gs1-syntax-engine/src/c-lib"

    - name: Build
      working-directory: build
      shell: bash
      run: cmake --build . -j8 --config $BUILD_TYPE

    - name: Test
      working-directory: build
      shell: bash
      run: PATH=$PATH:"$(pwd)/backend/$BUILD_TYPE:$(pwd)/frontend/$BUILD_TYPE:$(pwd)backend_qt/$BUILD_TYPE" QT_QPA_PLATFORM=offscreen ctest -V -C $BUILD_TYPE

  build-windows-64bit:
    runs-on: windows-latest

    steps:
    - uses: actions/checkout@v4

    - name: Create Build Environment
      shell: bash
      run: git config --global --add safe.directory ${GITHUB_WORKSPACE} && cmake -E make_directory build

    - name: Install zlib
      shell: bash
      run: |
        git clone --depth=1 https://github.com/madler/zlib.git zlib && cd zlib
        cmake -B build -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DZLIB_BUILD_TESTING=OFF -DZLIB_BUILD_SHARED=OFF -DZLIB_BUILD_MINIZIP=OFF -DZLIB_INSTALL_COMPAT_DLL=OFF
        cmake --build build --config $BUILD_TYPE
        cmake -E rename build/$BUILD_TYPE/zs.lib zlib.lib
        cmake -E rename build/zconf.h zconf.h

    - name: Install libpng
      shell: bash
      run: |
        git clone --depth=1 https://git.code.sf.net/p/libpng/code lpng && cd lpng
        cmake -B build -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DPNG_SHARED=OFF -DPNG_TESTS=OFF -DPNG_TOOLS=OFF -DZLIB_ROOT="${GITHUB_WORKSPACE}/zlib"
        cmake --build build --config $BUILD_TYPE
        cmake -E rename build/$BUILD_TYPE/libpng16_static.lib libpng.lib
        cmake -E rename build/pnglibconf.h pnglibconf.h

    - name: Install GS1 Syntax Engine
      shell: bash
      run: |
        git clone --depth=1 https://github.com/gitlost/gs1-syntax-engine && cd gs1-syntax-engine/src/c-lib
        cmake -B build -DCMAKE_BUILD_TYPE=$BUILD_TYPE
        cmake --build build --config $BUILD_TYPE
        cmake -E rename build/$BUILD_TYPE/gs1encoders.lib gs1encoders.lib

    - name: Install Qt6
      uses: jurplel/install-qt-action@v4
      with:
        version: 6.9.2
        dir: .

    - name: Configure CMake
      working-directory: build
      shell: bash
      run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DZINT_TEST=ON -DZINT_STATIC=ON -DZINT_QT6=ON -DZLIB_ROOT="${GITHUB_WORKSPACE}/zlib" -DPNG_ROOT="${GITHUB_WORKSPACE}/lpng" -DGS1SE_PATH="${GITHUB_WORKSPACE}/gs1-syntax-engine/src/c-lib"

    - name: Build
      working-directory: build
      shell: bash
      run: cmake --build . -j8 --config $BUILD_TYPE

    - name: Test
      working-directory: build
      shell: bash
      run: PATH=$PATH:"$(pwd)/backend/$BUILD_TYPE:$(pwd)/frontend/$BUILD_TYPE:$(pwd)backend_qt/$BUILD_TYPE" QT_QPA_PLATFORM=offscreen ctest -V -C $BUILD_TYPE

  build-macOS:
    runs-on: macOS-latest

    steps:
    - uses: actions/checkout@v4

    - name: Create Build Environment
      shell: bash
      run: git config --global --add safe.directory ${GITHUB_WORKSPACE} && cmake -E make_directory build

    - name: Install libpng
      shell: bash
      run: brew install libpng

    - name: Install Qt5
      shell: bash
      run: brew install qt5

    - name: Install GS1 Syntax Engine
      run: git clone --depth=1 https://github.com/gs1/gs1-syntax-engine && cd gs1-syntax-engine/src/c-lib && make lib && (sudo make install || true)

    - name: Configure CMake
      working-directory: build
      shell: bash
      run: PATH=$PATH:/opt/homebrew/opt/qt@5/bin cmake $GITHUB_WORKSPACE -DCMAKE_C_FLAGS='-I /usr/local/include' -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DZINT_TEST=ON -DZINT_STATIC=ON

    - name: Build
      working-directory: build
      shell: bash
      run: SDKROOT="$(xcrun --sdk macosx --show-sdk-path)" cmake --build . -j8 --config $BUILD_TYPE

    - name: Test
      working-directory: build
      shell: bash
      run: LD_LIBRARY_PATH=$LD_LIBRARY_PATH:"$(pwd)/backend" PATH=$PATH:"$(pwd)/frontend" ctest -V -C $BUILD_TYPE

  build-macOS-sanitize:
    runs-on: macOS-latest

    steps:
    - uses: actions/checkout@v4

    - name: Create Build Environment
      shell: bash
      run: git config --global --add safe.directory ${GITHUB_WORKSPACE} && cmake -E make_directory build

    - name: Configure CMake
      working-directory: build
      shell: bash
      run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DZINT_TEST=ON -DZINT_SANITIZE=ON -DZINT_USE_PNG=OFF -DZINT_USE_QT=OFF

    - name: Build
      working-directory: build
      shell: bash
      run: SDKROOT="$(xcrun --sdk macosx --show-sdk-path)" cmake --build . -j8 --config $BUILD_TYPE

    - name: Test
      working-directory: build
      shell: bash
      run: LD_LIBRARY_PATH=$LD_LIBRARY_PATH:"$(pwd)/backend" PATH=$PATH:"$(pwd)/frontend" ctest -V -C $BUILD_TYPE

  build-freebsd:
    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v4

    - name: Build FreeBSD
      id: build-freebsd
      uses: vmactions/freebsd-vm@v1
      with:
        usesh: true
        mem: 4096
        prepare: pkg install -y git cmake gmake gcc graphics/png qt5-core qt5-uitools qt5-buildtools qt5-qmake qt5-svg qt5-testlib
        run: |
          set -e
          git config --global --add safe.directory ${GITHUB_WORKSPACE}
          cmake -E make_directory build
          cmake -B build -DCMAKE_BUILD_TYPE=Release -DZINT_TEST=ON
          cmake --build build --config Release
          cd build
          QT_QPA_PLATFORM=offscreen ctest -V
