Skip to content

Commit

Permalink
CPP-4575 Update examples to use the new GitHub action for C and C++
Browse files Browse the repository at this point in the history
  • Loading branch information
friedbyalice authored Mar 21, 2024
1 parent 1580b2e commit aaed1c3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 25 deletions.
27 changes: 4 additions & 23 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,15 @@ jobs:
name: Build
runs-on: macos-latest
env:
SONAR_SCANNER_VERSION: 5.0.1.3006 # Find the latest version in the "Mac OS" link on this page:
# https://docs.sonarqube.org/latest/analysis/scan/sonarscanner/
SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }} # Value stored in a Github secret
BUILD_WRAPPER_OUT_DIR: build_wrapper_output_directory # Directory where build-wrapper output will be placed
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: Cache SonarQube packages
uses: actions/cache@v3
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- name: Download and set up sonar-scanner
env:
SONAR_SCANNER_DOWNLOAD_URL: https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-${{ env.SONAR_SCANNER_VERSION }}-macosx.zip
run: |
mkdir -p $HOME/.sonar
curl -sSLo $HOME/.sonar/sonar-scanner.zip ${{ env.SONAR_SCANNER_DOWNLOAD_URL }}
unzip -o $HOME/.sonar/sonar-scanner.zip -d $HOME/.sonar/
echo "$HOME/.sonar/sonar-scanner-${{ env.SONAR_SCANNER_VERSION }}-macosx/bin" >> $GITHUB_PATH
- name: Download and set up build-wrapper
- name: Install sonar-scanner and build-wrapper
uses: sonarsource/sonarqube-github-c-cpp@v1
env:
BUILD_WRAPPER_DOWNLOAD_URL: ${{ env.SONAR_HOST_URL }}/static/cpp/build-wrapper-macosx-x86.zip
run: |
curl -sSLo $HOME/.sonar/build-wrapper-macosx-x86.zip ${{ env.BUILD_WRAPPER_DOWNLOAD_URL }}
unzip -o $HOME/.sonar/build-wrapper-macosx-x86.zip -d $HOME/.sonar/
echo "$HOME/.sonar/build-wrapper-macosx-x86" >> $GITHUB_PATH
SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }} # SonarQube URL is stored in a GitHub secret
- name: Run build-wrapper
run: |
mkdir build
Expand All @@ -48,5 +28,6 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONARQUBE_TOKEN }} # Put the name of your token here
SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }} # SonarQube URL is stored in a GitHub secret
run: |
sonar-scanner --define sonar.cfamily.build-wrapper-output="${{ env.BUILD_WRAPPER_OUT_DIR }}"
3 changes: 1 addition & 2 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ It is very easy to analyze a C, C++ and Objective-C project with SonarQube:
. Create a `sonar-project.properties` file to store your configuration
. In your `.github/workflows/build.yml` file:
.. Set the environment variable `SONAR_SERVER_URL` to your server url (e.g.: https://example.com:9000)
.. Download the https://docs.sonarqube.org/latest/analysis/scan/sonarscanner/[Sonar Scanner]
.. Download the https://docs.sonarqube.org/latest/analyzing-source-code/languages/c-family/#using-build-wrapper[Build Wrapper]
.. Download the Sonar Scanner and Build Wrapper using https://github.com/SonarSource/sonarqube-github-c-cpp[the SonarQube Scan for C and C++ Github Action]
.. Wrap your compilation with the Build Wrapper
.. Run `sonar-scanner` as the final step
. Ensure that your token is stored as a secret in your repository (`SONARQUBE_TOKEN` in this example project). If you don't have a token yet, you can generate a new one in SonarQube (see https://docs.sonarqube.org/latest/user-guide/user-token/[Generating and Using Tokens]).
Expand Down

0 comments on commit aaed1c3

Please sign in to comment.