# Syntax reference https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions
# Environment reference https://help.github.com/en/actions/reference/virtual-environments-for-github-hosted-runners
name: cppcheck-premium

on:
  push:
    branches:
      - 'main'
      - 'releases/**'
    tags:
      - '2.*'
  pull_request:

permissions:
  contents: read

jobs:

  build:
    runs-on: ubuntu-22.04 # run on the latest image only

    env:
      PREMIUM_VERSION: 24.2.0

    steps:
      - uses: actions/checkout@v3

      - name: Download cppcheckpremium
        run: |
          wget https://files.cppchecksolutions.com/${{ env.PREMIUM_VERSION }}/ubuntu-22.04/cppcheckpremium-${{ env.PREMIUM_VERSION }}-amd64.tar.gz
          tar xzf cppcheckpremium-${{ env.PREMIUM_VERSION }}-amd64.tar.gz

      - name: Generate a license file
        run: |
          echo cppcheck > cppcheck.lic
          echo 241231 >> cppcheck.lic
          echo 80000 >> cppcheck.lic
          echo 53b72a908d7aeeee >> cppcheck.lic
          echo path:lib >> cppcheck.lic

      - name: Check
        run: |
          cppcheckpremium-${{ env.PREMIUM_VERSION }}/premiumaddon --check-loc-license cppcheck.lic > cppcheck-premium-loc
          cppcheckpremium-${{ env.PREMIUM_VERSION }}/cppcheck -j$(nproc) -D__GNUC__ -D__CPPCHECK__ --suppressions-list=cppcheckpremium-suppressions --platform=unix64 --enable=style --premium=misra-c++-2008 --premium=cert-c++-2016 --inline-suppr --error-exitcode=1 lib
