# see https://github.com/marketplace/actions/sonarcloud-scan-for-c-and-c#usage
name: Sonar Check

on:
  push:
    branches:
      - dev
  # pull_request:
  #   types: [opened, synchronize, reopened]

jobs:
  build:
    name: Build and analyze
    if: github.repository == 'emsesp/EMS-ESP32'
    runs-on: ubuntu-latest
    env:
      BUILD_WRAPPER_OUT_DIR: bw-output
    steps:
      - name: Checkout repository
        uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - name: Install sonar-scanner and build-wrapper
        uses: SonarSource/sonarcloud-github-c-cpp@v2

      - name: Run build-wrapper
        run:  build-wrapper-linux-x86-64 --out-dir ${{ env.BUILD_WRAPPER_OUT_DIR }} make all

      - name: Run sonar-scanner
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
        run: sonar-scanner --define sonar.cfamily.compile-commands="${{ env.BUILD_WRAPPER_OUT_DIR }}/compile_commands.json"
