Skip to content

Manual SonarCloud Analysis #3

Manual SonarCloud Analysis

Manual SonarCloud Analysis #3

Workflow file for this run

name: Manual SonarCloud Analysis
on:
workflow_dispatch:
inputs:
pr_id:
description: 'Pull Request ID to analyze'
required: true
type: string
jobs:
sonar-analysis:
name: SonarCloud Analysis for PR
runs-on: ubuntu-latest
steps:
- name: Get PR details
id: pr
uses: actions/github-script@v7
with:
script: |
const pr = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: ${{ inputs.pr_id }}
});
core.setOutput('head_ref', pr.data.head.ref);
core.setOutput('base_ref', pr.data.base.ref);
core.setOutput('head_sha', pr.data.head.sha);
- uses: actions/checkout@v5
with:
ref: ${{ steps.pr.outputs.head_sha }}
fetch-depth: 0
- name: Set up Python 3.13
uses: actions/setup-python@v6
with:
python-version: "3.13"
- name: Install dependencies
run: |
pip install pipenv
pipenv install --dev
- name: Test
run: pipenv run pytest -v --cov=./ --cov-report xml
- name: Fix code coverage path
working-directory: ./
run: sed -i 's@'$GITHUB_WORKSPACE'@/github/workspace/@g' coverage.xml
- name: SonarCloud Scan
uses: sonarsource/[email protected]
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
if: env.SONAR_TOKEN != ''
with:
args: >
-Dsonar.pullrequest.key=${{ inputs.pr_id }}
-Dsonar.pullrequest.branch=${{ steps.pr.outputs.head_ref }}
-Dsonar.pullrequest.base=${{ steps.pr.outputs.base_ref }}