-
Notifications
You must be signed in to change notification settings - Fork 1
222 lines (201 loc) · 9.2 KB
/
check_calls.yml
File metadata and controls
222 lines (201 loc) · 9.2 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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
name: SonarQube API health check
on:
pull_request:
branches: [ main ]
push:
branches: [ main ]
workflow_dispatch:
jobs:
sonarqube-api:
runs-on: ubuntu-latest
services:
sonarqube:
image: sonarqube:latest
ports:
- 9000:9000
options: >-
--health-cmd="curl -f http://localhost:9000/api/system/status || exit 1"
--health-interval=10s
--health-timeout=5s
--health-retries=60
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Wait for sonar to be up
run: |
for i in {1..120}; do
STATUS=$(curl -s http://localhost:9000/api/system/status | jq -r '.status' || true)
if [ "$STATUS" = "UP" ]; then echo "SonarQube UP"; break; fi
echo "Status: $STATUS..."
sleep 5
done
- name: Create temporal admin token
run: |
export TOKEN_NAME="ci-token-$(date +%s)"
AUTH="-u admin:admin"
curl -sS $AUTH -X POST "http://localhost:9000/api/user_tokens/generate?name=$TOKEN_NAME" | jq -r '.token' > token.txt
echo "SONAR_TOKEN=$(cat token.txt)" >> $GITHUB_ENV
- name: Prepare Dummy Project
run: |
mkdir -p dummy
echo 'console.log(eval("1+1"))' > dummy/index.js
cat > dummy/sonar-project.properties << 'EOF'
sonar.projectKey=dummy.project
sonar.projectName=Dummy Project
sonar.sources=.
sonar.exclusions=**/*
sonar.token=${SONAR_TOKEN}
sonar.host.url=http://localhost:9000
EOF
- name: Install Sonar Scanner
run: |
sudo apt-get update -y
sudo apt-get install -y unzip default-jre
curl -L -o scanner.zip https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-5.0.1.3006-linux.zip
unzip scanner.zip
SCANNER_DIR=$(find . -type d -name "sonar-scanner-*" | head -n 1)
echo "$SCANNER_DIR/bin" >> $GITHUB_PATH
- name: Run Sonar Scanner
run: |
./sonar-scanner-*/bin/sonar-scanner \
-Dsonar.projectKey=dummy.project \
-Dsonar.sources=. \
-Dsonar.exclusions=**/* \
-Dsonar.host.url=http://localhost:9000 \
-Dsonar.login=${{ env.SONAR_TOKEN }}
- name: API Testing
env:
SONAR_TOKEN: ${{ env.SONAR_TOKEN }}
run: |
set -euo pipefail
AUTH="Authorization: Basic $(echo -n ${SONAR_TOKEN}: | base64 -w0)"
response=$(mktemp)
#/api/navigation/component?component=
url="http://localhost:9000/api/navigation/component?component=dummy.project"
code=$(curl -sS -H "$AUTH" -o "$response" -w "%{http_code}" "$url")
if (( code >= 400 && code < 600 )); then
echo "Error in $url (HTTP $code)"
echo "--- Body ---"
cat "$response"
echo "------------"
exit 1
fi
echo "$url OK (HTTP $code)"
#/api/measures/component?metricKeys=reliability_rating,software_quality_maintainability_rating,security_rating,security_review_rating&component=
url="http://localhost:9000/api/measures/component?metricKeys=reliability_rating,software_quality_maintainability_rating,security_rating,security_review_rating&component=dummy.project"
code=$(curl -sS -H "$AUTH" -o "$response" -w "%{http_code}" "$url")
if (( code >= 400 && code < 600 )); then
echo "Error in $url (HTTP $code)"
echo "--- Body ---"
cat "$response"
echo "------------"
exit 1
fi
echo "$url OK (HTTP $code)"
#/api/qualitygates/project_status?projectKey=
url="http://localhost:9000/api/qualitygates/project_status?projectKey=dummy.project"
code=$(curl -sS -H "$AUTH" -o "$response" -w "%{http_code}" "$url")
if (( code >= 400 && code < 600 )); then
echo "Error in $url (HTTP $code)"
echo "--- Body ---"
cat "$response"
echo "------------"
exit 1
fi
echo "$url OK (HTTP $code)"
#/api/measures/component?metricKeys=duplicated_lines_density,comment_lines_density,ncloc,complexity,cognitive_complexity,coverage&component=
url="http://localhost:9000/api/measures/component?metricKeys=duplicated_lines_density,comment_lines_density,ncloc,complexity,cognitive_complexity,coverage&component=dummy.project"
code=$(curl -sS -H "$AUTH" -o "$response" -w "%{http_code}" "$url")
if (( code >= 400 && code < 600 )); then
echo "Error in $url (HTTP $code)"
echo "--- Body ---"
cat "$response"
echo "------------"
exit 1
fi
echo "$url OK (HTTP $code)"
#/api/measures/component?metricKeys=duplicated_lines_density,comment_lines_density,ncloc,complexity,cognitive_complexity,coverage&component=
url="http://localhost:9000/api/measures/component?metricKeys=duplicated_lines_density,comment_lines_density,ncloc,complexity,cognitive_complexity,coverage&component=dummy.project"
code=$(curl -sS -H "$AUTH" -o "$response" -w "%{http_code}" "$url")
if (( code >= 400 && code < 600 )); then
echo "Error in $url (HTTP $code)"
echo "--- Body ---"
cat "$response"
echo "------------"
exit 1
fi
echo "$url OK (HTTP $code)"
#/api/measures/component?metricKeys=reliability_remediation_effort,security_remediation_effort,sqale_index&component=
url="http://localhost:9000/api/measures/component?metricKeys=reliability_remediation_effort,security_remediation_effort,sqale_index&component=dummy.project"
code=$(curl -sS -H "$AUTH" -o "$response" -w "%{http_code}" "$url")
if (( code >= 400 && code < 600 )); then
echo "Error in $url (HTTP $code)"
exit 1
fi
echo "$url OK (HTTP $code)"
#/api/measures/component?metricKeys=ncloc_language_distribution&component=
url="http://localhost:9000/api/measures/component?metricKeys=ncloc_language_distribution&component=dummy.project"
code=$(curl -sS -H "$AUTH" -o "$response" -w "%{http_code}" "$url")
if (( code >= 400 && code < 600 )); then
echo "Error in $url (HTTP $code)"
echo "--- Body ---"
cat "$response"
echo "------------"
exit 1
fi
echo "$url OK (HTTP $code)"
#/api/hotspots/search?status=TO_REVIEW&ps=500&pageIndex=0&project=
url="http://localhost:9000/api/hotspots/search?status=TO_REVIEW&ps=500&pageIndex=0&project=dummy.project"
code=$(curl -sS -H "$AUTH" -o "$response" -w "%{http_code}" "$url")
if (( code >= 400 && code < 600 )); then
echo "Error in $url (HTTP $code)"
echo "--- Body ---"
cat "$response"
echo "------------"
exit 1
fi
echo "$url OK (HTTP $code)"
#/api/issues/search?types=BUG&facets=severities&componentKeys=
url="http://localhost:9000/api/issues/search?types=BUG&facets=severities&componentKeys=dummy.project"
code=$(curl -sS -H "$AUTH" -o "$response" -w "%{http_code}" "$url")
if (( code >= 400 && code < 600 )); then
echo "Error in $url (HTTP $code)"
echo "--- Body ---"
cat "$response"
echo "------------"
exit 1
fi
echo "$url OK (HTTP $code)"
#/api/issues/search?types=VULNERABILITY&facets=severities&componentKeys=
url="http://localhost:9000/api/issues/search?types=VULNERABILITY&facets=severities&componentKeys=dummy.project"
code=$(curl -sS -H "$AUTH" -o "$response" -w "%{http_code}" "$url")
if (( code >= 400 && code < 600 )); then
echo "Error in $url (HTTP $code)"
echo "--- Body ---"
cat "$response"
echo "------------"
exit 1
fi
echo "$url OK (HTTP $code)"
#/api/issues/search?types=CODE_SMELL&facets=severities&componentKeys=
url="http://localhost:9000/api/issues/search?types=CODE_SMELL&facets=severities&componentKeys=dummy.project"
code=$(curl -sS -H "$AUTH" -o "$response" -w "%{http_code}" "$url")
if (( code >= 400 && code < 600 )); then
echo "Error in $url (HTTP $code)"
echo "--- Body ---"
cat "$response"
echo "------------"
exit 1
fi
echo "$url OK (HTTP $code)"
#/api/issues/search?issueStatuses=OPEN&ps=500&pageIndex=0&componentKeys=
url="http://localhost:9000/api/issues/search?issueStatuses=OPEN&ps=500&pageIndex=0&componentKeys=dummy.project"
code=$(curl -sS -H "$AUTH" -o "$response" -w "%{http_code}" "$url")
if (( code >= 400 && code < 600 )); then
echo "Error in $url (HTTP $code)"
echo "--- Body ---"
cat "$response"
echo "------------"
exit 1
fi
echo "$url OK (HTTP $code)"