Skip to content

Commit 64e97d9

Browse files
authored
add dynamic project config on SonarCloud (#2004)
1 parent 07f314f commit 64e97d9

2 files changed

Lines changed: 21 additions & 3 deletions

File tree

.github/workflows/code_coverage.yml

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ jobs:
7070
# See https://sonarsource.atlassian.net/browse/SONARPY-1203
7171
- name: Fix paths in coverage file
7272
run: |
73-
sed -i 's,/home/runner/work/ansible-wisdom-service/ansible-wisdom-service/,/github/workspace/,g' coverage.xml
73+
sed -i "s,/home/runner/work/${{ github.event.repository.name }}/${{ github.event.repository.name }}/,/github/workspace/,g" coverage.xml
7474
7575
##################
7676
# TypeScript tests
@@ -119,11 +119,29 @@ jobs:
119119
#####################
120120
# SonarCloud coverage
121121
#####################
122+
- name: Extract repo owner and name
123+
shell: bash
124+
env:
125+
GH_TOKEN: ${{ github.token }}
126+
run: |
127+
if [ "${{ github.event.repository.fork }}" = "true" ]; then
128+
PARENT_REPO_SLUG=$(gh api repos/${{ github.repository }} | jq -r '.parent.full_name')
129+
IFS="/" read -r REPO_OWNER REPO_NAME <<< "$PARENT_REPO_SLUG"
130+
else
131+
IFS="/" read -r REPO_OWNER REPO_NAME <<< "${GITHUB_REPOSITORY}"
132+
fi
133+
echo "REPO_OWNER=$REPO_OWNER" >> $GITHUB_ENV
134+
echo "REPO_NAME=$REPO_NAME" >> $GITHUB_ENV
135+
122136
- name: SonarCloud Scan
123137
uses: SonarSource/sonarqube-scan-action@master
124138
env:
125139
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
126140
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
141+
with:
142+
args: >
143+
-Dsonar.projectKey=${{ env.REPO_OWNER }}_${{ env.REPO_NAME }}
144+
-Dsonar.organization=${{ env.REPO_OWNER }}
127145
128146
####################
129147
# OpenAPI file check

sonar-project.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
sonar.projectKey=ansible_ansible-wisdom-service
2-
sonar.organization=ansible
1+
# sonar.projectKey and sonar.organization are set dynamically
2+
# in .github/workflows/code_coverage.yml based on the repo owner and name
33

44
# Django specific settings
55
sonar.python.django.managePath=ansible_ai_connect/manage.py

0 commit comments

Comments
 (0)