forked from nrfconnect/sdk-nrf
-
Notifications
You must be signed in to change notification settings - Fork 0
67 lines (61 loc) · 2.42 KB
/
sonar-analysis.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
name: SonarCloud Analysis
on:
workflow_run:
workflows: ["SonarCloud"]
types:
- completed
workflow_dispatch:
inputs:
debug_run_id:
description: "Run ID for debugging purposes"
required: true
default: ""
jobs:
sonar:
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Download artifacts
uses: dawidd6/action-download-artifact@v6
with:
workflow: sonarcloud.yml
run_id: ${{ inputs.debug_run_id }}
#run_id: ${{ github.event.workflow_run.id }}
- name: Extract Variables from File
run: |
# Directly extract values using grep
HEAD_SHA=$(grep '^HEAD_SHA=' build_env.txt | cut -d '=' -f 2)
PR_NUMBER=$(grep '^PR_NUMBER=' build_env.txt | cut -d '=' -f 2)
PR_BRANCH=$(grep '^PR_BRANCH=' build_env.txt | cut -d '=' -f 2)
BASE_REF=$(grep '^BASE_REF=' build_env.txt | cut -d '=' -f 2)
# Export values for later steps
echo "HEAD_SHA=$HEAD_SHA" >> $GITHUB_ENV
echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_ENV
echo "PR_BRANCH=$PR_BRANCH" >> $GITHUB_ENV
echo "BASE_REF=$BASE_REF" >> $GITHUB_ENV
- name: SonarCloud Analysis
uses: SonarSource/sonarqube-scan-action@v4
if: env.PR_NUMBER == '' # Main branch
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
with:
args: >
--define sonar.cfamily.compile-commands="nrf/build_wrapper_output/compile_commands.json"
--define project.settings=sonar-project.properties
--define sonar.inclusions=**/*.c,**/*.h
--define sonar.scm.revision=${{ env.HEAD_SHA }}
- name: SonarCloud Analysis
uses: SonarSource/sonarqube-scan-action@v4
if: env.PR_NUMBER != '' # Only run if PR_NUMBER is set
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
with:
args: >
--define sonar.cfamily.compile-commands="build_wrapper_output/compile_commands.json"
--define project.settings=sonar-project.properties
--define sonar.inclusions=**/*.c,**/*.h
--define sonar.scm.revision=${{ env.HEAD_SHA }}
--define sonar.pullrequest.key=${{ env.PR_NUMBER }}
--define sonar.pullrequest.branch=${{ env.PR_BRANCH }}
--define sonar.pullrequest.base=${{ env.BASE_REF }}