1+ name : SonarCloud Scan
2+
3+ on :
4+ workflow_call :
5+ inputs :
6+ # Project identification
7+ app-name :
8+ description : ' Application name (must match sonar.projectKey in sonar-project.properties)'
9+ type : string
10+ required : true
11+
12+ # Node configuration
13+ node-version :
14+ description : ' Node.js version (ignored if use-asdf is true)'
15+ type : string
16+ default : ' 20'
17+ use-asdf :
18+ description : ' Use asdf-vm for version management (reads from .tool-versions)'
19+ type : boolean
20+ default : false
21+
22+ # Runner configuration
23+ runner :
24+ description : ' Runner for SonarCloud scan'
25+ type : string
26+ default : ' [self-hosted, ci-universal]'
27+
28+ # Coverage configuration
29+ coverage-artifact-name :
30+ description : ' Name of coverage artifact to download (optional, e.g., coverage-12345)'
31+ type : string
32+ default : ' '
33+
34+ # Timeout configuration
35+ timeout :
36+ description : ' Job timeout (minutes)'
37+ type : number
38+ default : 10
39+
40+ secrets :
41+ GH_TOKEN :
42+ required : true
43+ SONAR_CLOUD_TOKEN :
44+ required : true
45+
46+ permissions :
47+ contents : read
48+
49+ jobs :
50+ sonarcloud :
51+ name : 🔍 SonarCloud Analysis
52+ runs-on : ${{ fromJSON(inputs.runner) }}
53+ timeout-minutes : ${{ inputs.timeout }}
54+
55+ steps :
56+ - name : Check out Git repository
57+ uses : actions/checkout@v4
58+ with :
59+ fetch-depth : 0 # Required for SonarCloud to analyze git history
60+
61+ - name : Setup Node with Cache
62+ uses : Typeform/.github/shared-actions/setup-node-with-cache@v1
63+ with :
64+ node-version : ${{ inputs.node-version }}
65+ use-asdf : ${{ inputs.use-asdf }}
66+ GH_TOKEN : ${{ secrets.GH_TOKEN }}
67+
68+ - name : Download coverage artifacts
69+ if : inputs.coverage-artifact-name != ''
70+ uses : actions/download-artifact@v4
71+ with :
72+ name : ${{ inputs.coverage-artifact-name }}
73+ path : coverage/
74+ continue-on-error : true
75+
76+ - name : SonarCloud Scan
77+ uses : SonarSource/sonarqube-scan-action@v6
78+ with :
79+ args : >
80+ -Dsonar.projectVersion=${{ github.run_id }}
81+ env :
82+ GITHUB_TOKEN : ${{ secrets.GH_TOKEN }}
83+ SONAR_TOKEN : ${{ secrets.SONAR_CLOUD_TOKEN }}
84+ LC_ALL : " C.UTF-8"
0 commit comments