# This is a basic workflow to help you get started with Actions

name: Multi-Architecture Build

# Controls when the action will run. 
on:
  # Triggers the workflow on all push or pull request events
  push:
  pull_request:

  # Allows you to run this workflow manually from the Actions tab
  workflow_dispatch:

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
  # This workflow contains a single job called "build"
  build_multiarch:
    # The type of runner that the job will run on
    runs-on: ${{ matrix.os }}
    continue-on-error: true
    env:
      COMPILER: ${{ matrix.compiler }}
      BUILD_OS: ${{ matrix.os }}

    strategy:
      fail-fast: false
      matrix:
        compiler: ['gcc-i386-cross', 'clang-i386-cross', 'gcc-mips64-cross', 'gcc-arm32-cross', 'gcc-arm64-cross',  'gcc-arm32-qemu-cross', 'gcc-arm64-qemu-cross', 'clang-arm32-qemu-cross', 'clang-arm64-qemu-cross']
        os: [ubuntu-22.04]

    # 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
        with:
          submodules: recursive

      # Cache the compiler cache
      - name: Cache the compiler cache
        uses: actions/cache@v4
        if: endsWith(matrix.compiler, '-qemu-cross')
        with:
          path: ccache
          key: ccache-${{ matrix.os }}-${{ matrix.compiler }}-${{ github.run_id }}
          restore-keys: |
            ccache-${{ matrix.os }}-${{ matrix.compiler }}

      - name: Start Docker container
        if: endsWith(matrix.compiler, '-cross')
        run: sh -x scripts/build/start_container.sh

      - name: Install dependencies
        run: sh -x scripts/build/install_depends.sh

      - name: Zero out compiler cache stats
        if: endsWith(matrix.compiler, '-qemu-cross')
        run: scripts/build/zero_ccache_stats.sh

      - name: Build
        run: sh -x scripts/build/do_build.sh

      - name: Print compiler cache stats
        if: endsWith(matrix.compiler, '-qemu-cross')
        run: scripts/build/print_ccache_stats.sh

  notify:
    runs-on: ubuntu-latest
    needs: build_multiarch
    steps:
      - name: Notify slack fail
        if: failure() && github.repository == 'OpenSIPS/opensips'
        env:
          SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
        uses: voxmedia/github-action-slack-notify-build@v1
        with:
          channel: devel
          status: FAILED
          color: danger