2022-01-14 20:08:29 +08:00
|
|
|
name: sonar-scan
|
|
|
|
|
|
|
|
on:
|
|
|
|
push:
|
|
|
|
branches: [master]
|
2022-01-18 08:07:42 +08:00
|
|
|
pull_request:
|
2022-01-14 20:08:29 +08:00
|
|
|
branches: [master]
|
|
|
|
|
2023-11-23 05:28:18 +08:00
|
|
|
# Cancel old PR builds when pushing new commits.
|
|
|
|
concurrency:
|
|
|
|
group: scan-${{ github.event.pull_request.number || github.ref }}
|
|
|
|
cancel-in-progress: true
|
|
|
|
|
2022-01-14 20:08:29 +08:00
|
|
|
jobs:
|
|
|
|
sonar-scan:
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
env:
|
2023-11-23 18:56:32 +08:00
|
|
|
SONAR_SCANNER_VERSION: 5.0.1.3006
|
2022-01-14 20:08:29 +08:00
|
|
|
SONAR_SERVER_URL: "https://sonarcloud.io"
|
|
|
|
BUILD_WRAPPER_OUT_DIR: build_wrapper_output_directory # Directory where build-wrapper output will be placed
|
|
|
|
steps:
|
|
|
|
- uses: actions/checkout@v2
|
|
|
|
with:
|
|
|
|
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
|
2022-03-25 02:16:45 +08:00
|
|
|
submodules: recursive
|
2023-11-23 18:56:32 +08:00
|
|
|
- name: Set up JDK 17
|
2022-01-14 20:08:29 +08:00
|
|
|
uses: actions/setup-java@v1
|
|
|
|
with:
|
2023-11-23 18:56:32 +08:00
|
|
|
java-version: 17
|
2022-01-14 20:08:29 +08:00
|
|
|
- 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 }}-linux.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 }}-linux/bin" >> $GITHUB_PATH
|
|
|
|
- name: Download and set up build-wrapper
|
|
|
|
env:
|
|
|
|
BUILD_WRAPPER_DOWNLOAD_URL: ${{ env.SONAR_SERVER_URL }}/static/cpp/build-wrapper-linux-x86.zip
|
|
|
|
run: |
|
|
|
|
curl -sSLo $HOME/.sonar/build-wrapper-linux-x86.zip ${{ env.BUILD_WRAPPER_DOWNLOAD_URL }}
|
|
|
|
unzip -o $HOME/.sonar/build-wrapper-linux-x86.zip -d $HOME/.sonar/
|
|
|
|
echo "$HOME/.sonar/build-wrapper-linux-x86" >> $GITHUB_PATH
|
|
|
|
- name: Install dependencies and prepare build
|
2022-01-18 08:07:42 +08:00
|
|
|
run: |
|
|
|
|
.github/scripts/sonar-prepare
|
2022-01-14 20:08:29 +08:00
|
|
|
- name: Run build-wrapper
|
2022-01-18 08:07:42 +08:00
|
|
|
run: |
|
|
|
|
build-wrapper-linux-x86-64 --out-dir ${{ env.BUILD_WRAPPER_OUT_DIR }} .github/scripts/sonar-build
|
2022-01-14 20:08:29 +08:00
|
|
|
- name: Run sonar-scanner
|
2022-01-18 08:07:42 +08:00
|
|
|
if: github.event_name == 'push'
|
2022-01-14 20:08:29 +08:00
|
|
|
env:
|
|
|
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
|
2022-01-17 18:01:26 +08:00
|
|
|
run: 'sonar-scanner --define sonar.host.url="${{ env.SONAR_SERVER_URL }}" --define sonar.cfamily.build-wrapper-output="${{ env.BUILD_WRAPPER_OUT_DIR }}"'
|