-
Notifications
You must be signed in to change notification settings - Fork 0
115 lines (98 loc) · 3.94 KB
/
Copy pathsonarsource-scan.yml
File metadata and controls
115 lines (98 loc) · 3.94 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
name: SonarCloud Analysis
on:
push:
branches:
- dev
- test
- main
pull_request:
types: [opened, synchronize, reopened]
workflow_dispatch:
permissions:
checks: write
contents: read
pull-requests: write
security-events: write
jobs:
sonarcloud:
name: SonarCloud
runs-on: ubuntu-latest
environment: ${{ github.ref_name == 'main' && 'main' || github.ref_name == 'test' && 'test' || 'dev' }}
steps:
- name: Set up JDK 17
uses: actions/setup-java@v5
with:
java-version: 17
distribution: 'temurin'
- uses: actions/checkout@v6
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: Setup .NET
uses: actions/setup-dotnet@v5
with:
dotnet-version: '9.0.x'
- name: Set up Node.js
uses: actions/setup-node@v6
with:
node-version: '22'
cache: 'npm'
cache-dependency-path: applications/Grants.ApplicantPortal/src/Grants.ApplicantPortal.Frontend/package-lock.json
- name: Cache SonarCloud packages
uses: actions/cache@v5
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- name: Cache SonarCloud scanner
id: cache-sonar-scanner
uses: actions/cache@v5
with:
path: ./.sonar/scanner
key: ${{ runner.os }}-sonar-scanner
restore-keys: ${{ runner.os }}-sonar-scanner
- name: Install SonarCloud scanner
if: steps.cache-sonar-scanner.outputs.cache-hit != 'true'
run: |
dotnet tool install --global dotnet-sonarscanner
- name: Set version for SonarCloud
run: |
VERSION="${{ vars.GRANTS_BUILD_VERSION }}"
echo "Debug: GRANTS_BUILD_VERSION variable value: '$VERSION'"
if [ -n "$VERSION" ]; then
echo "BUILD_VERSION=$VERSION" >> $GITHUB_ENV
echo "Using project version: $VERSION"
# Replace ${BUILD_VERSION} with actual value
sed -i "s/\${BUILD_VERSION}/$VERSION/g" applications/Grants.ApplicantPortal/sonar-project.properties
else
echo "GRANTS_BUILD_VERSION variable not set - removing sonar.projectVersion property"
# Remove the projectVersion line entirely if no version is available
sed -i "/sonar.projectVersion=/d" applications/Grants.ApplicantPortal/sonar-project.properties
fi
- name: Clear npm cache
run: npm cache clean --force
- name: Install Node.js dependencies
working-directory: ./applications/Grants.ApplicantPortal/src/Grants.ApplicantPortal.Frontend
run: npm ci --no-audit --prefer-offline
- name: Build Angular frontend
working-directory: ./applications/Grants.ApplicantPortal/src/Grants.ApplicantPortal.Frontend
run: npm run build:dev
- name: Restore .NET dependencies
working-directory: ./applications/Grants.ApplicantPortal/src/Grants.ApplicantPortal.Backend
run: dotnet restore Grants.ApplicantPortal.API.sln
- name: Build .NET solution
working-directory: ./applications/Grants.ApplicantPortal/src/Grants.ApplicantPortal.Backend
run: dotnet build Grants.ApplicantPortal.API.sln --no-restore
- name: SonarCloud sonar.projectVersion
run: |
echo "BUILD_VERSION environment variable: $BUILD_VERSION"
echo "Updated sonar-project.properties:"
cat applications/Grants.ApplicantPortal/sonar-project.properties | grep "sonar.projectVersion" || echo "No projectVersion set"
- name: SonarCloud Scan
uses: SonarSource/sonarqube-scan-action@v7
with:
projectBaseDir: applications/Grants.ApplicantPortal
args: >
-Dsonar.verbose=true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}