Uploaded image for project: 'SonarQube'
  1. SonarQube
  2. SONAR-15028

Explain how to analyse C/C++/Objective C with GitHub Actions

    XMLWordPrintable

    Details

    • Type: New Feature
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 9.0
    • Component/s: Web
    • Labels:
      None
    • Edition:
      Developer
    • Production Notes:
      None

      Description

      We want to help users run an analysis for C/C++/Obj C code using GitHub Actions. GitHub Actions supports all 3 OS's, so we need to provide an option to select their target OS.

      For all OS's

      Towards the end of the tutorial, add the following sentence (standard for all new C/C++/Obj C tutorials):

      If you have trouble using the build wrapper, you can check out using a compilation database. Read more about it here.
      You can speed up your analysis by enabling multi-threading and caching. Read more about it here.

      Linux

      name: Build
      on:
        push:
          branches:
            - master
        pull_request:
          types: [opened, synchronize, reopened]
      
      jobs:
        build:
          runs-on: ubuntu-latest
          steps:
            - name: Checkout code
              uses: actions/checkout@v2
              with:
                fetch-depth: 0
      
            - name: Download and install the build wrapper, build the project
              run: |
                mkdir $HOME/.sonar
                curl -sSLo $HOME/.sonar/build-wrapper-linux-x86.zip ${{ secrets.SONAR_HOST_URL }}/static/cpp/build-wrapper-linux-x86.zip
                unzip -o $HOME/.sonar/build-wrapper-linux-x86.zip -d $HOME/.sonar/
               $HOME/.sonar/build-wrapper-linux-x86/build-wrapper-linux-x86-64 --out-dir bw-output <your clean build command>
              env:
                SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}
      
            - name: SonarQube analysis
              uses: SonarSource/sonarqube-scan-action@v1.0.0
              with:
                args: -Dsonar.cfamily.build-wrapper-output=bw-output
              env:
                SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
                SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}
      
      

      macOS

      name: Build
      on:
        push:
          branches:
            - master
        pull_request:
          types: [opened, synchronize, reopened]
      
      jobs:
        build:
          runs-on: macos-latest
          steps:
            - name: Checkout code
              uses: actions/checkout@v2
              with:
                fetch-depth: 0
      
            - name: Download and install the build wrapper
              run: |
                mkdir $HOME/.sonar
                curl -sSLo $HOME/.sonar/build-wrapper-macosx-x86.zip ${{ secrets.SONAR_HOST_URL }}/static/cpp/build-wrapper-macosx-x86.zip
                unzip -o $HOME/.sonar/build-wrapper-macosx-x86.zip -d $HOME/.sonar/
              env:
                SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}
      
            - name: Download and install the SonarScanner
              run: |
                curl -sSLo $HOME/.sonar/sonar-scanner.zip https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-4.6.2.2472-macosx.zip
                unzip -o $HOME/.sonar/sonar-scanner.zip -d $HOME/.sonar/
      
            - name: Build and analyse the project
              run: |
                # Potential improvement : add these paths to the PATH env var.
                $HOME/.sonar/build-wrapper-macosx-x86/build-wrapper-macosx-x86 --out-dir bw-output <your clean build command>
                $HOME/.sonar/sonar-scanner-4.6.2.2472-macosx/bin/sonar-scanner -Dsonar.cfamily.build-wrapper-output=bw-output
              env:
                SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
                SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}
      

      Windows

      name: Build
      on:
        push:
          branches:
            - master
        pull_request:
          types: [opened, synchronize, reopened]
      
      jobs:
        build:
          runs-on: windows-latest
          steps:
            - name: Checkout code
              uses: actions/checkout@v2
              with:
                fetch-depth: 0
      
            - name: Download and install the build wrapper
              shell: powershell
              run: |
                $path = "$HOME/.sonar/build-wrapper-win-x86.zip"
                mkdir $HOME/.sonar
                [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
                (New-Object System.Net.WebClient).DownloadFile("${{ secrets.SONAR_HOST_URL }}/static/cpp/build-wrapper-win-x86.zip", $path)
                Add-Type -AssemblyName System.IO.Compression.FileSystem
                [System.IO.Compression.ZipFile]::ExtractToDirectory($path, "$HOME/.sonar")
              env:
                SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}
      
            - name: Download and install the SonarScanner
              shell: powershell
              run: |
                $path = "$HOME/.sonar/sonar-scanner-cli-4.6.2.2472-windows.zip"
                [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
                (New-Object System.Net.WebClient).DownloadFile("https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-4.6.2.2472-windows.zip", $path)
                Add-Type -AssemblyName System.IO.Compression.FileSystem
                [System.IO.Compression.ZipFile]::ExtractToDirectory($path, "$HOME/.sonar")
      
            - name: Build and analyse the project
              shell: powershell
              run: |
                $env:Path += ";$HOME/.sonar/build-wrapper-win-x86;$HOME/.sonar/sonar-scanner-4.6.2.2472-windows/bin"
                build-wrapper-win-x86-64 --out-dir bw-output <your clean build command>
                sonar-scanner.bat "-Dsonar.cfamily.build-wrapper-output=bw-output"
              env:
                SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
                SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}
      
      

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              jeremy.davis Jeremy Davis
              Reporter:
              wouter.admiraal Wouter Admiraal
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Due:
                Created:
                Updated:
                Resolved: