Skip to content

Commit 420e400

Browse files
authored
Merge pull request #45 from Chisanan232/develop
🎉🎊🍾 [New Feature] Add new reusable GA workflow about SonarQube scan and analyze.
2 parents 0be9442 + de8569f commit 420e400

File tree

5 files changed

+90
-1
lines changed

5 files changed

+90
-1
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
###################################################################################################################################
2+
#
3+
# Workflow Description:
4+
# Trigger SonarQube cloud service to scan entire project to check code quality, security, etc.
5+
#
6+
# Workflow input parameters:
7+
# * General arguments:
8+
# * download_path: The path to download testing coverage reports via 'actions/download-artifact@v3'.
9+
#
10+
# * Secret arguments:
11+
# * sonar_token: The API token for triggering SonarQube cloud service.
12+
#
13+
# Workflow running output:
14+
# No and do nothing.
15+
#
16+
###################################################################################################################################
17+
18+
name: SoarQube cloud scan and analyse project
19+
20+
on:
21+
workflow_call:
22+
inputs:
23+
download_path:
24+
description: "The path to download testing coverage reports via 'actions/download-artifact@v3'."
25+
type: string
26+
required: false
27+
default: ./
28+
29+
secrets:
30+
sonar_token:
31+
description: "The API token for uploading testing coverage report to Coveralls."
32+
required: true
33+
34+
35+
jobs:
36+
upload_test_cov_report:
37+
runs-on: ubuntu-latest
38+
steps:
39+
- uses: actions/checkout@v3
40+
with:
41+
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
42+
43+
- name: Download code coverage result files which has be handled by different test type process
44+
uses: actions/download-artifact@v3
45+
with:
46+
name: test_coverage_xml_report
47+
path: ${{ inputs.download_path }}
48+
49+
- name: SonarCloud Scan
50+
uses: SonarSource/sonarcloud-github-action@master
51+
env:
52+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
53+
SONAR_TOKEN: ${{ secrets.sonar_token }}

.github/workflows/test_pyproject_ci_multi-tests_by_poetry.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,16 @@ jobs:
112112
upload-to-codacy: true
113113

114114

115+
sonarqube_finish:
116+
# name: Trigger SoarQube service to scan and analyse project
117+
needs: [all-test_codecov]
118+
uses: ./.github/workflows/sonarqube_scan.yaml
119+
secrets:
120+
sonar_token: ${{ secrets.SONAR_TOKEN }}
121+
# with:
122+
# download_path: ${{ inputs.download_path }}
123+
124+
115125
pre-building_test:
116126
# name: Check about it could work finely by installing the Python package with setup.py file
117127
# if: github.event_name == 'push' && (github.ref_name == 'release' || github.ref_name == 'master')

.github/workflows/test_python_project_ci_one-test.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,16 @@ jobs:
9191
upload-to-codacy: true
9292

9393

94+
sonarqube_finish:
95+
# name: Trigger SoarQube service to scan and analyse project
96+
needs: [unit-test_codecov]
97+
uses: ./.github/workflows/sonarqube_scan.yaml
98+
secrets:
99+
sonar_token: ${{ secrets.SONAR_TOKEN }}
100+
# with:
101+
# download_path: ${{ inputs.download_path }}
102+
103+
94104
pre-building_test:
95105
# name: Check about it could work finely by installing the Python package with setup.py file
96106
needs: [codecov_finish, coveralls_finish, codacy_finish]

scripts/ci/get-all-tests.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ get_all_test_subpackage() {
3030
then
3131
# Still has test subpackage won't scan
3232
declare test_path="$test_subpkg*/"
33-
declare -a test_subpkg_array=( $(ls -d "$test_path" | grep -v '__pycache__') )
33+
# shellcheck disable=SC2086
34+
declare -a test_subpkg_array=( $(ls -d $test_path | grep -v '__pycache__') )
3435

3536
if [ ${#test_subpkg_array[@]} != 0 ];
3637
then

sonar-project.properties

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
sonar.projectKey=Chisanan232_GitHub-Action_Reusable_Workflows-Python
2+
sonar.organization=chisanan232
3+
4+
# This is the name and version displayed in the SonarCloud UI.
5+
sonar.projectName=GitHub-Action_Reusable_Workflows-Python
6+
sonar.projectVersion=4.0.0
7+
8+
# Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows.
9+
sonar.sources=.github/workflows/,scripts/,test_gh_workflow/
10+
11+
# Python test coverage settings
12+
sonar.python.coverage.reportPaths=coverage*.xml
13+
14+
# Encoding of the source code. Default is default system encoding
15+
sonar.sourceEncoding=UTF-8

0 commit comments

Comments
 (0)