name: Git builds

# Trigger on every git push
on: push

jobs:
  multi:
    runs-on: ${{ matrix.config.os }}
    strategy:
        matrix:
          config:
          - { name: "MacOS Intel", os: macos-15-intel,   cc: "clang", cxx: "clang++"}
          - { name: "MacOS ARM",   os: macos-latest,     cc: "clang", cxx: "clang++"}
          - { name: "Linux ARM",   os: ubuntu-24.04-arm, cc: "gcc",   cxx: "g++"}
        fail-fast: false
    permissions:
      contents: read
      packages: write

    steps:
      - name: Checkout repository
        uses: actions/checkout@v4
      - name: Init options
        run: |
          echo "CC=${{ matrix.config.cc }}"   >> $GITHUB_ENV
          echo "CXX=${{ matrix.config.cxx }}" >> $GITHUB_ENV
      - name: prepare for ubuntu
        if: matrix.config.name == 'Linux ARM'
        run: |
          sudo apt-get update && sudo apt-get install ninja-build libboost-dev libboost-context-dev pybind11-dev
      - name: prepare for MacOS
        if: matrix.config.name == 'MacOS Intel' || matrix.config.name == 'MacOS ARM'
        run: |
          brew install boost eigen pybind11 ninja
          sudo xcode-select -s /Applications/Xcode_16.3.app
      - name: build
        run: |
          mkdir build ; cd build
          cmake -GNinja -Denable_debug=ON -Denable_documentation=OFF -Denable_coverage=OFF \
                -Denable_compile_optimizations=ON -Denable_compile_warnings=ON \
                -Denable_testsuite_smpi_MBI=OFF -Denable_testsuite_McMini=ON \
                -Denable_testsuite_smpi_MPICH3=ON \
                -DCMAKE_DISABLE_SOURCE_CHANGES=ON  -DLTO_EXTRA_FLAG="auto" ..
          ninja tests
          ctest --output-on-failure -j$(nproc)
      - name: Send the failure message
        if: ${{ failure() }}
        uses: mattermost/action-mattermost-notify@master
        with:
          MATTERMOST_WEBHOOK_URL: ${{ secrets.MATTERMOST_WEBHOOK_URL }}
          MATTERMOST_CHANNEL: ${{ secrets.MATTERMOST_CHANNEL}}
          PAYLOAD: |-
            {
             "channel": "bot-office",
             "attachments": [{
               "color": "#FF0000",
               "text": "Failure when building simgrid on ${{ matrix.config.name }}! See ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}",
               "icon": "https://cdn3.iconfinder.com/data/icons/system-basic-vol-4-1/20/icon-note-attention-alt3-512.png"
            }]}
#      - name: Send the success message
#        if: ${{ success() }}
#        uses: mattermost/action-mattermost-notify@master
#        with:
#          MATTERMOST_WEBHOOK_URL: ${{ secrets.MATTERMOST_WEBHOOK_URL }}
#          MATTERMOST_CHANNEL: ${{ secrets.MATTERMOST_CHANNEL}}
#          PAYLOAD: |-
#            {
#             "channel": "bot-office",
#             "attachments": [{
#               "color": "#00FF00",
#               "text": "SimGrid built successfully on ${{ matrix.config.name }}! See ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
#            }]}
