-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.yml
56 lines (45 loc) · 1.97 KB
/
action.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
name: SonarQube Quality Gate Report Generator
description: Generates report out of SonarQube QualityGate data
author: Skitsanos, https://github.com/skitsanos
inputs:
SONAR_TOKEN:
required: true
description: SonarQube token
SONAR_HOST_URL:
required: true
description: SonarQube URL
SONAR_PROJECT:
required: true
description: SonarQube project name
GITHUB_TOKEN:
required: true
description: GitHub Token
outputs:
RUN_ID:
value: ${{ steps.generate-report.outputs.RUN_ID }}
description: Report unique ID
PREVIEW_URL:
value: ${{ steps.generate-report.outputs.PREVIEW_URL }}
description: URL to preview the report
runs:
using: composite
steps:
- shell: bash
name: Install jq
run: |
sudo apt-get -qq install jq
- uses: actions/github-script@v6
id: urlParser
with:
script: |
const sonarUrl = new (require('url')).URL('${{inputs.SONAR_HOST_URL}}');
return {protocol: sonarUrl.protocol, host: sonarUrl.host}
- shell: bash
id: generate-report
run: |
curl "${{ fromJson(steps.urlParser.outputs.result).protocol }}//${{ inputs.SONAR_TOKEN }}:@${{ fromJson(steps.urlParser.outputs.result).host }}/api/issues/search?componentKeys=${{inputs.SONAR_PROJECT}}&resolved=no" | jq '.issues[] | {key, message, severity, component, textRange}' | jq -s '{issues: ., repo: "${{github.repository}}", pr: "${{github.event.number}}", project: "${{inputs.SONAR_PROJECT}}"}' >report.json
RUN_ID=$(curl -H "Content-Type: application/json" --data @report.json "https://sonarqube-reporting.netlify.app/api/quality-gate" | jq -r '.result._key')
echo "RUN_ID=$RUN_ID" >> $GITHUB_ENV
echo "PREVIEW_URL=https://sonarqube-reporting.netlify.app/quality-gate/$RUN_ID" >> $GITHUB_ENV
echo "::set-output name=RUN_ID::$RUN_ID"
echo "::set-output name=PREVIEW_URL::https://sonarqube-reporting.netlify.app/quality-gate/$RUN_ID"