name: C/C++ CI

on:
  push:
    branches: ["main"]
  pull_request:
    branches: ["main"]

jobs:

  build:
    runs-on: ${{ matrix.os }}

    strategy:
      matrix:
        os: [macos-latest]

    steps:
      - name: Check out repository code
        uses: actions/checkout@v4
      - name: Install Dependencies
        run: |
          if [ "${{ matrix.os }}" = "macos-latest" ]; then
            arch -arm64 brew update
            arch -arm64 brew install autoconf-archive autoconf automake libtool m4
            arch -arm64 brew install wxwidgets tinyxml zstd libpng sqlite
            arch -arm64 brew install dylibbundler pkg-config
            arch -arm64 brew install googletest
          elif [ "${{ matrix.os }}" = "ubuntu-latest" ]; then
            sudo apt-get update
            sudo apt-get install autoconf-archive
            sudo apt install libwxgtk3.2-dev || sudo apt install wx3.2-headers || sudo apt install libwxgtk3.0-gtk3-dev || sudo apt install libwxgtk3.0-dev
          fi
      - name: remove local redundancy to build-deps
        run: rm -f mysql* sqlite* && rm -rf clustalw tinyxml
      - name: autogen
        run: ./autogen.sh
      - name: configure
        run: ./configure
      - name: make
        run: make
      - name: running tests
        run: make check
      - name: install asciidoc
        run: |
          if [ "${{ matrix.os }}" = "macos-latest" ]; then
            arch -arm64 brew install asciidoc
          elif [ "${{ matrix.os }}" = "ubuntu-latest" ]; then
            sudo apt install asciidoc
          fi
      - name: build manual.html
        run: asciidoc docs/manual.adoc
      - name: Archive production artifacts
        uses: actions/upload-artifact@v3
        with:
          name: GENtle_${{ matrix.os }}
          path: |
            GENtle
            variables.csv
            codon_catalog.csv
            marker.txt
            default.tab
            docs/manual.html
            docs/images
          retention-days: 10
