From 06c7c0094fada35c1708e66c44dbbe5e43f4f154 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D8=B4=D8=B1=D9=83=D8=A9=20=D8=AE=D8=A8=D9=8A=D8=B1=20?= =?UTF-8?q?=D8=A7=D9=84=D9=85=D8=AD=D8=AF=D9=88=D8=AF=D8=A9?= Date: Sat, 27 Sep 2025 21:25:25 +0300 Subject: [PATCH] Update github action file --- .github/workflows/sonarqube.yml | 59 ++++++++++++++++++++++----------- 1 file changed, 39 insertions(+), 20 deletions(-) diff --git a/.github/workflows/sonarqube.yml b/.github/workflows/sonarqube.yml index 9a5223bbe..b8a1be9e1 100644 --- a/.github/workflows/sonarqube.yml +++ b/.github/workflows/sonarqube.yml @@ -24,7 +24,9 @@ on: - master_openeducat_erp-14.0.1.0 - master_odex25_ensan - master_odex25_donation - + pull_request: + branches: + - "**" jobs: sonar: @@ -32,28 +34,45 @@ jobs: steps: - name: Checkout code uses: actions/checkout@v4 + with: + fetch-depth: 0 - name: Run SonarScanner run: | - export BRANCH_NAME="${GITHUB_REF#refs/heads/}" - export SAFE_BRANCH_NAME="${BRANCH_NAME//\//_}" - export PROJECT_KEY="odex25_standard_modules_${SAFE_BRANCH_NAME}" - export PROJECT_NAME="Standard Modules ${SAFE_BRANCH_NAME^}" - export SOURCE_FOLDER_NAME="${BRANCH_NAME#master_}" - export PROJECT_VERSION="1.0" - export SONAR_HOST_URL=${{ secrets.SONAR_HOST_URL }} - export SONAR_TOKEN=${{ secrets.SONAR_TOKEN }} - - sonar-scanner \ - -Dsonar.projectKey="$PROJECT_KEY" \ - -Dsonar.projectName="$PROJECT_NAME" \ - -Dsonar.projectVersion="$PROJECT_VERSION" \ - -Dsonar.sources="$SOURCE_FOLDER_NAME" \ - -Dsonar.inclusions="**/*.py, **/*.xml, **/*.js, **/*.html, **/*.css" \ - -Dsonar.exclusions="**/__manifest__.py, **/migrations/**, **/__pycache__/**" \ - -Dsonar.sourceEncoding="UTF-8" \ - -Dsonar.host.url="$SONAR_HOST_URL" \ - -Dsonar.login="$SONAR_TOKEN" + if [ "${{ github.event_name }}" == "pull_request" ]; then + BRANCH_NAME="${GITHUB_HEAD_REF}" + BASE_BRANCH="${GITHUB_BASE_REF}" + PR_KEY="${{ github.event.pull_request.number }}" + else + BRANCH_NAME="${GITHUB_REF#refs/heads/}" + fi + + SONAR_HOST_URL=${{ secrets.SONAR_HOST_URL }} + SONAR_TOKEN=${{ secrets.SONAR_TOKEN }} + + echo "Running SonarQube analysis for branch/PR: $BRANCH_NAME" + + SONAR_CMD="sonar-scanner \ + -Dsonar.projectKey=odex25_standard_modules \ + -Dsonar.projectName=\"Odex25 Standard Modules\" \ + -Dsonar.sources=. \ + -Dsonar.inclusions=**/*.py,**/*.xml,**/*.js,**/*.html,**/*.css \ + -Dsonar.exclusions=**/__manifest__.py,**/migrations/**,**/__pycache__/** \ + -Dsonar.sourceEncoding=UTF-8 \ + -Dsonar.host.url=$SONAR_HOST_URL \ + -Dsonar.login=$SONAR_TOKEN" + + if [ "${{ github.event_name }}" == "pull_request" ]; then + SONAR_CMD="$SONAR_CMD \ + -Dsonar.pullrequest.key=$PR_KEY \ + -Dsonar.pullrequest.branch=$BRANCH_NAME \ + -Dsonar.pullrequest.base=$BASE_BRANCH" + else + SONAR_CMD="$SONAR_CMD \ + -Dsonar.branch.name=$BRANCH_NAME" + fi + + eval $SONAR_CMD - name: Cleanup workspace if: always()