name: MaxOS

on:
  pull_request:
    types: [opened, synchronize, reopened]
  
jobs:
  build_engine:
    name: Build NLP-ENGINE
    runs-on: macOS-latest

    env:
      VCPKG_DEFAULT_TRIPLET: arm64-osx
    steps:
      - uses: actions/checkout@v3
        with:
          submodules: true

      - name: Vcpkg bootstrap Shell
        run: ./bootstrap-vcpkg.sh
        shell: bash
        working-directory: vcpkg
        
      - name: List $RUNNER_WORKSPACE before build
        run: find $RUNNER_WORKSPACE
        shell: bash
        
      - name: Install autoconf-archive
        run: brew install autoconf-archive

      - name: Install Brew
        run: brew install automake

      - name: Install 3rd Party
        run: ./vcpkg install
        working-directory: vcpkg

      - name: List $RUNNER_WORKSPACE before build
        run: find $RUNNER_WORKSPACE
        shell: bash

      - name: Make build directory
        run: mkdir build

      - name: Generate Solution MacOs
        run: cmake -DCMAKE_BUILD_TYPE=Release -DVCPKG_BUILD_TYPE=release -B build -S . -DCMAKE_CXX_FLAGS=-std=c++11 -DCMAKE_TOOLCHAIN_FILE='${{ github.workspace }}/vcpkg/scripts/buildsystems/vcpkg.cmake'

      - name: Cmake Build all targets MaxOs
        run: cmake --build build/ --target all

      - name: Test executable --version
        run: ./bin/nlp --version || true

      # Upload nlpm.exe
      - name: Upload nlpm.exe
        uses: actions/upload-artifact@v4
        with:
          name: nlpm.exe
          path: bin/nlpm.exe

      - name: Copy libicutu.a to libicutum.a
        run: cp vcpkg_installed/arm64-osx/lib/libicutu.a vcpkg_installed/arm64-osx/lib/libicutum.a
        shell: bash

      - name: Upload libicutum.a
        uses: actions/upload-artifact@v4
        with:
          name: libicutum.a
          path: vcpkg_installed/arm64-osx/lib/libicutum.a

      - name: Copy libicuuc.a to libicuucm.a
        run: cp vcpkg_installed/arm64-osx/lib/libicuuc.a vcpkg_installed/arm64-osx/lib/libicuucm.a
        shell: bash

      - name: Upload libicuucm.a
        uses: actions/upload-artifact@v4
        with:
          name: libicuucm.a
          path: vcpkg_installed/arm64-osx/lib/libicuucm.a                              
          
      - name: Checkout Analyzers repo
        uses: actions/checkout@v3
        with:
          repository: VisualText/analyzers
          submodules: recursive
          path: analyzers
                 
      - name: List runner workspace
        run: find $RUNNER_WORKSPACE
        shell: bash

      - name: Run English Parser
        run: ./bin/nlp -ANA ./analyzers/parse-en-us -WORK ./ ./analyzers/parse-en-us/input/doj.txt -DEV || true

      - name: Full English Test
        uses: LouisBrunner/diff-action@v0.2.0
        with:
          old: .github/workflows/tests/parse-en-us/final.tree
          new: ./analyzers/parse-en-us/input/doj.txt_log/final.tree
          mode: addition
          tolerance: same
          output: parse-en-us-diff-mac.txt
