forked from codebymad/github-example-package
-
Notifications
You must be signed in to change notification settings - Fork 0
63 lines (49 loc) · 2.14 KB
/
Copy pathCheck.yml
File metadata and controls
63 lines (49 loc) · 2.14 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
name: SonarCloud Analysis
on:
push:
branches:
- main
jobs:
sonarcloud-analysis:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Set up JDK
uses: actions/setup-java@v2
with:
java-version: '11'
- name: Run SonarCloud analysis
run: sonar-scanner
- name: Install jq
run: sudo apt-get install -y jq
- name: Retrieve SonarCloud details
id: sonarcloud-details
run: |
# Extract the project key from SonarCloud analysis
project_key=$(grep 'sonar.projectKey' sonar-project.properties | cut -d'=' -f2)
# Fetch the quality gate details using SonarCloud API
response=$(curl -s "https://sonarcloud.io/api/qualitygates/project_status?projectKey=${project_key}")
# Extract relevant details from the response
quality_gate_status=$(echo "${response}" | jq -r '.projectStatus.status')
quality_gate_conditions=$(echo "${response}" | jq -r '.projectStatus.conditions[] | select(.metricKey == "alert_status")')
# Extract threshold value from the conditions
threshold=$(echo "${quality_gate_conditions}" | jq -r '.errorThreshold')
# Output the details for further usage
echo "::set-output name=quality_gate_status::${quality_gate_status}"
echo "::set-output name=threshold::${threshold}"
- name: Compare SonarCloud result with threshold
run: |
# Threshold value for the quality gate
threshold=${{ steps.sonarcloud-details.outputs.threshold }}
# Quality gate status
quality_gate_status=${{ steps.sonarcloud-details.outputs.quality_gate_status }}
if [[ "${quality_gate_status}" == "ERROR" ]]; then
echo "Quality gate failed. SonarCloud analysis did not meet the threshold."
exit 1
elif [[ "${quality_gate_status}" == "OK" ]]; then
echo "Quality gate passed. SonarCloud analysis meets the threshold."
else
echo "Unable to determine the quality gate status."
exit 1
fi