Skip to content

Commit f4ac23b

Browse files
authored
[AAP-47730] Make SonarQube relocatable (#772)
## Description Following the advice of https://github.com/ansible-automation-platform/cicd-ops/blob/main/doc/sonar.md#sonar-projectproperties, compute the values of the SonarQube projectKey and organization variables at run time. Addresses https://issues.redhat.com/browse/AAP-47730 ## Type of Change <!-- Mandatory: Check one or more boxes that apply --> - [ ] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] Documentation update - [X] Test update - [ ] Refactoring (no functional changes) - [ ] Development environment change - [X] Configuration change ## Self-Review Checklist <!-- These items help ensure quality - they complement our automated CI checks --> - [X] I have performed a self-review of my code - [X] I have added relevant comments to complex code sections - [ ] I have updated documentation where needed - [X] I have considered the security impact of these changes - [ ] I have considered performance implications - [ ] I have thought about error handling and edge cases - [X] I have tested the changes in my local environment ### Steps to Test The very nature of this PR is a test; you'd need to commit it or something like it in order to test. In DAB's case, the affected workflow only runs on a merge, and it's a separate action outside the purview of a PR merge (i.e. even if this fails, it will not affect the ability to merge subsequent PRs). ### Expected Results SonarQube scan results should appear in whatever organization you are running in - i.e. ansible vs. ansible-automation-platform <!-- ### Screenshots/Logs --> <!-- Add if relevant to demonstrate the changes --> --------- Signed-off-by: David Schmidt <[email protected]>
1 parent e241ea4 commit f4ac23b

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

.github/workflows/sonar-pr.yml

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,26 @@ jobs:
5252
env:
5353
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5454

55-
- name: SonarCloud Scan
56-
uses: SonarSource/sonarqube-scan-action@master
55+
- name: 'Extract and export repo owner/name'
56+
shell: bash
57+
run: |
58+
# 1. Read the full slug (owner/repo)
59+
REPO_SLUG="${GITHUB_REPOSITORY}"
60+
# 2. Split into owner and repo
61+
IFS="/" read -r REPO_OWNER REPO_NAME <<< "$REPO_SLUG"
62+
# 3. Export to the workflow environment
63+
echo "REPO_OWNER=$REPO_OWNER" >> $GITHUB_ENV
64+
echo "REPO_NAME=$REPO_NAME" >> $GITHUB_ENV
65+
66+
- name: SonarQube Scan
67+
uses: SonarSource/sonarqube-scan-action@v5
5768
env:
5869
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
59-
SONAR_TOKEN: ${{ secrets.CICD_ORG_SONAR_TOKEN_CICD_BOT }}
70+
SONAR_TOKEN: ${{ secrets[format('{0}', vars.SONAR_TOKEN_SECRET_NAME)] }}
6071
with:
6172
args: >
73+
-Dsonar.projectKey=${{ env.REPO_OWNER }}_${{ env.REPO_NAME }}
74+
-Dsonar.organization=${{ env.REPO_OWNER }}
6275
-Dsonar.scm.revision=${{ github.event.workflow_run.head_sha }}
6376
-Dsonar.pullrequest.key=${{ env.PR_NUMBER }}
6477
-Dsonar.pullrequest.branch=${{ env.PR_HEAD }}

0 commit comments

Comments
 (0)