name: C/C++ CI

on: [push, pull_request]
concurrency:
  group: ${{ github.head_ref }}
  cancel-in-progress: true

jobs:
    lint:
        name: Format and Lint
        runs-on: ubuntu-latest
        permissions:
          contents: read 
          pull-requests: write 

        steps:
        - name: checkout
          uses: actions/checkout@v4
        
        - name: Run commitlint
          uses: opensource-nepal/commitlint@v1.2.0

        - name: Run linter
          uses: cpp-linter/cpp-linter-action@v2
          id: linter
          env:
            GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          with:
            style: 'file'
            tidy-checks: 'file'
            tidy-review: true
            version: '18'

        - name: Check linter errors
          if: steps.linter.outputs.clang-tidy-checks-failed > 0
          run: exit 1
        
        - name: Check format errors
          if: steps.linter.outputs.clang-format-checks-failed > 0
          run: exit 1
    make:
        name: Compile Project 
        runs-on: ubuntu-latest
        needs: lint

        steps:
        - name: checkout
          uses: actions/checkout@v4
        
        - name: Install Arm GNU Toolchain (arm-none-eabi-gcc)
          uses: carlosperate/arm-none-eabi-gcc-action@v1

        - name: make
          run: make