Skip to content

Sonar add coverage

Sonar add coverage #11

name: Sonar Cloud Analysis
concurrency:
group: sonarcloud-${{ github.ref }}
cancel-in-progress: true
on:
workflow_dispatch:
pull_request:
types: [closed]
branches: ['master']
release:
types:
- published
jobs:
unit-tests:
name: SonarCloud / Unit Tests
timeout-minutes: 30
if: ${{ ((github.event.pull_request.merged == true && github.base_ref == 'master') ||
(github.event_name == 'workflow_dispatch' ||
github.event_name == 'release'))
&& vars.IS_INDITEXTECH_REPO == 'true' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.sha }}
- name: Install UV
uses: astral-sh/setup-uv@0c5e2b8115b80b4c7c5ddf6ffdd634974642d182 # v5
with:
enable-cache: true
- name: Sync project
run: uv sync --frozen --all-extras --dev --python 3.10
- name: Unit tests execution
run: uv run pytest --cov-report term --cov-report xml:coverage-unit.xml --cov=.
- name: Integration tests execution
run: uv run pytest -m integration --cov-report term --cov-report xml:coverage-integration.xml --cov=.
env:
TEAMS_APP_ID: ${{ vars.TEAMS_APP_ID }}
TEAMS_APP_PASSWORD: ${{ secrets.TEAMS_APP_PASSWORD }}
TEAMS_APP_TYPE: ${{ vars.TEAMS_APP_TYPE }}
TEAMS_APP_TENANT_ID: ${{ vars.TEAMS_APP_TENANT_ID }}
TEAM_ID: ${{ vars.TEAM_ID }}
TEAMS_CHANNEL_ID: ${{ vars.TEAMS_CHANNEL_ID }}
TEST_THREAD_ID: ${{ vars.TEST_THREAD_ID }}
TEST_MESSAGE_ID: ${{ vars.TEST_MESSAGE_ID }}
TEST_USER_NAME: ${{ vars.TEST_USER_NAME }}
- name: Store project information
shell: bash
id: version
run: |
VERSION=$(uv run pyproject-info project.version | tr -d '"'); echo "app-version=$VERSION" >> "$GITHUB_OUTPUT"
NAME=$(uv run pyproject-info project.name | tr -d '"'); echo "app-name=$NAME" >> "$GITHUB_OUTPUT"
echo "github-repository=$(echo $GITHUB_REPOSITORY | cut -d'/' -f2)" >> "$GITHUB_OUTPUT"
- name: SonarCloud / Run SonarCloud action
uses: sonarsource/sonarqube-scan-action@v4
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
with:
projectBaseDir: .
args: >
-Dsonar.organization=inditextech
-Dsonar.projectKey=InditexTech_${{ steps.version.outputs.github-repository }}
-Dsonar.projectName=${{ steps.version.outputs.app-name }}
-Dsonar.projectVersion=${{ steps.version.outputs.app-version }}
-Dsonar.branch.name=${{ github.base_ref || github.ref_name }}
-Dsonar.host.url="https://sonarcloud.io/"
-Dsonar.verbose=true
-Dsonar.token=${SONAR_TOKEN}
-Dsonar.python.version=3.10
-Dsonar.python.coverage.reportPaths=coverage*.xml