name: unittest-macos
# autotools build on homebrew. unittests with address sanitizers. with openmp.
on:
  #push:
  schedule:
    - cron: 0 0 * * *

jobs:
  sanitizers:
    name: ${{ matrix.config.name }}
    runs-on: ${{ matrix.config.os }}
    strategy:
      fail-fast: false
      matrix:
        config:
          - { name: macos-10.15-clang-unittest, os: macos-10.15, cxx: clang++ }
          - { name: macos-10.15-gcc-unittest, os: macos-10.15, cxx: g++ }

    steps:
    - uses: actions/checkout@v2
      with:
        submodules: recursive

    - name: Install dependencies (MacOS Homebrew)
      run: |
           brew install autoconf automake libarchive
           brew install leptonica cairo pango
           brew install cabextract

    - name: Setup
      run: |
           mkdir -p m4
           ./autogen.sh

    - name: Configure (MacOS Homebrew)
      run: |
           ./configure '--disable-shared' '--with-pic' \
                'CXX=${{ matrix.config.cxx }}' \
                'CXXFLAGS=-g -O2 -fsanitize=address,undefined' \
                "PKG_CONFIG_PATH=$(brew --prefix)/opt/icu4c/lib/pkgconfig:$(brew --prefix)/opt/libarchive/lib/pkgconfig:$(brew --prefix)/opt/libffi/lib/pkgconfig"

    - name: Make and Install Tesseract
      run: |
           make
           sudo make install

    - name: Make and Install Training Tools
      run: |
           make training
           sudo make training-install

    - name: Display Tesseract and Training Tools Version
      run: |
           tesseract -v
           lstmtraining -v
           text2image -v
      if: success() || failure()

    - name: Download fonts, tessdata and langdata required for tests
      run: |
           git clone https://github.com/egorpugin/tessdata tessdata_unittest
           cp tessdata_unittest/fonts/* test/testing/
           mv tessdata_unittest/* ../

    - name: Run Tesseract on phototest.tif and devatest.png
      run: |
           tesseract test/testing/phototest.tif -  --tessdata-dir ../tessdata
           tesseract test/testing/devatest.png - -l hin+eng  --tessdata-dir ../tessdata

    - name: Make and run Unit Tests
      run: |
           make check

    - name: Display Unit Tests Report and compiler version
      run: |
           cat test-suite.log
           ${{ matrix.config.cxx }} --version
           git log -3 --pretty=format:'%h %ad %s | %an'
      if: always()