-
Notifications
You must be signed in to change notification settings - Fork 23
89 lines (78 loc) · 2.86 KB
/
sonar_checks.yml
File metadata and controls
89 lines (78 loc) · 2.86 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
name: SonarCloud Static Scans (PR)
on:
workflow_run:
workflows:
- Pytest tests
types:
- completed
permissions: read-all
jobs:
sonarcloud:
name: SonarCloud Static Scans (PR)
runs-on: ubuntu-latest
if: github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.event == 'pull_request'
steps:
- name: Checkout Code
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Fetch Code Coverage Report
uses: actions/download-artifact@v4
with:
name: coverage-report
path: coverage-artifact
github-token: ${{ secrets.GITHUB_TOKEN }}
run-id: ${{ github.event.workflow_run.id }}
- name: Fetch PR Number
uses: actions/download-artifact@v4
with:
name: pr_number
path: pr-artifact
github-token: ${{ secrets.GITHUB_TOKEN }}
run-id: ${{ github.event.workflow_run.id }}
- name: Extract and validate PR Number
run: |
cat pr-artifact/pr_number.txt
VALID_PR=$(head -n1 pr-artifact/pr_number.txt | awk '{print $2}' | grep -E '^[0-9]+$') || true
if [ -z "$VALID_PR" ]; then
echo "Invalid PR number (must be a single integer)"
exit 1
fi
echo "PR_NUMBER=$VALID_PR" >> $GITHUB_ENV
- name: Get Additional PR Information
uses: octokit/request-action@v2.x
id: pr_info
with:
route: GET /repos/{repo}/pulls/{number}
repo: ${{ github.event.repository.full_name }}
number: ${{ env.PR_NUMBER }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Set Additional PR Information
run: |
PR_BASE='${{ fromJson(steps.pr_info.outputs.data).base.ref }}'
PR_HEAD='${{ fromJson(steps.pr_info.outputs.data).head.ref }}'
echo "PR_BASE=$PR_BASE" >> $GITHUB_ENV
echo "PR_HEAD=$PR_HEAD" >> $GITHUB_ENV
- name: Checkout Code for PR
run: |
gh pr checkout "$PR_NUMBER"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_NUMBER: ${{ env.PR_NUMBER }}
- name: SonarCloud Scan
uses: SonarSource/sonarqube-scan-action@v7
env:
SONAR_HOST_URL: https://sonarcloud.io
SONAR_ORGANIZATION: ansible
SONAR_PROJECT_KEY: ansible_metrics-utility
SONAR_TOKEN: ${{ secrets.CICD_ORG_SONAR_TOKEN_CICD_BOT }}
with:
projectBaseDir: .
args: >
-Dsonar.python.coverage.reportPaths=coverage-artifact/coverage.xml
-Dsonar.scm.revision=${{ github.event.workflow_run.head_sha }}
-Dsonar.pullrequest.key=${{ env.PR_NUMBER }}
-Dsonar.pullrequest.branch=${{ env.PR_HEAD }}
-Dsonar.pullrequest.base=${{ env.PR_BASE }}
-Dsonar.pullrequest.provider=github