Skip to content

[MOS-29972]Updated Sonar analysis workflow configuration - #336

Merged
ckm007 merged 1 commit into
mosip:developfrom
Mahesh-Binayak:patch-1
Jun 10, 2026
Merged

[MOS-29972]Updated Sonar analysis workflow configuration#336
ckm007 merged 1 commit into
mosip:developfrom
Mahesh-Binayak:patch-1

Conversation

@Mahesh-Binayak

@Mahesh-Binayak Mahesh-Binayak commented Jun 3, 2026

Copy link
Copy Markdown

Summary by CodeRabbit

  • Chores
    • Updated CI/CD workflow configuration for improved Maven and SonarCloud analysis setup, including streamlined build settings and enhanced project key derivation logic.

Signed-off-by: Mahesh-Binayak <76687012+Mahesh-Binayak@users.noreply.github.com>
@coderabbitai

coderabbitai Bot commented Jun 3, 2026

Copy link
Copy Markdown

Review Change Stack

Walkthrough

The workflow file is refactored to add explicit input defaults, restructure job setup steps, simplify Maven security configuration, and rewrite SonarCloud analysis scripting with aggressive service key normalization and dynamic project key composition from repository name and normalized service identifiers.

Changes

SonarCloud Analysis Workflow

Layer / File(s) Summary
Workflow inputs and job setup
.github/workflows/maven-sonar-analysis-new.yml
Workflow SONAR_URL input definition includes explicit default; JDK 21 is configured with updated Maven cache restore-keys formatting.
Build environment and security configuration
.github/workflows/maven-sonar-analysis-new.yml
Environment setup exports BRANCH_NAME and GPG_TTY; GPG import is split into a dedicated step with gnupg2 installation; Maven settings.xml is reduced to minimal OSSRH server/profile configuration with GPG executable and passphrase properties.
SonarCloud analysis execution
.github/workflows/maven-sonar-analysis-new.yml
SERVICE_KEY normalization sanitizes characters and trims ./-style prefixes/suffixes; FINAL_NAME combines repository name with normalized key; FULL_PROJECT_KEY is built as ${ORG_KEY}_${FINAL_NAME}; sonar.projectName is set accordingly; Maven working directory defaults to . when unset.
Trailing comments
.github/workflows/maven-sonar-analysis-new.yml
Slack notification block remains commented out with formatting adjustments.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Poem

🐰 Workflows refined with careful care,
Keys normalized, settings laid bare,
From secrets to sanity, step by step,
SonarCloud keeps building its rep! 🚀

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly relates to the main change—updating the Sonar analysis workflow configuration in the GitHub Actions workflow file.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (3)
.github/workflows/maven-sonar-analysis-new.yml (3)

35-43: ⚡ Quick win

Update actions to v4 and set persist-credentials: false.

Static analysis indicates actions/checkout@v3 and actions/setup-java@v3 are outdated. Both have v4 releases with security improvements. Additionally, setting persist-credentials: false on checkout prevents unnecessary credential persistence in the git config.

🔧 Suggested updates
-      - uses: actions/checkout@v3
+      - uses: actions/checkout@v4
+        with:
+          persist-credentials: false

       - name: Set up JDK 21
-        uses: actions/setup-java@v3
+        uses: actions/setup-java@v4
         with:
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.github/workflows/maven-sonar-analysis-new.yml around lines 35 - 43, Update
the GitHub Actions steps to use the v4 releases and disable credential
persistence: change uses: actions/checkout@v3 to uses: actions/checkout@v4 and
add persist-credentials: false to that checkout step; change uses:
actions/setup-java@v3 to uses: actions/setup-java@v4 while keeping existing
inputs (distribution: temurin, java-version: '21', server-id, settings-path)
intact so behavior remains the same.

72-72: ⚡ Quick win

Template injection: inputs.SERVICE_LOCATION used directly in shell.

The raw input value is used in the cd command. If a caller passes a value containing $(...) or backticks, command substitution would occur. While callers are expected to be trusted in workflow_call contexts, using an environment variable with proper quoting is defensive.

🔧 Safer pattern
       - name: Sonar Analysis
+        env:
+          SERVICE_LOCATION: ${{ inputs.SERVICE_LOCATION || '.' }}
+          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+          SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
         run: |
-          SERVICE_KEY=$(echo "${{ inputs.SERVICE_LOCATION }}" | sed 's|^\./||; s|^\.$||; s|[^a-zA-Z0-9]|-|g; s|-\\+|-|g; s|^-||; s|-$||')
+          SERVICE_KEY=$(echo "$SERVICE_LOCATION" | sed 's|^\./||; s|^\.$||; s|[^a-zA-Z0-9]|-|g; s|-\+|-|g; s|^-||; s|-$||')
           FINAL_NAME="${{ github.event.repository.name }}${SERVICE_KEY:+-$SERVICE_KEY}"
           FULL_PROJECT_KEY="${{ secrets.ORG_KEY }}_${FINAL_NAME}"
-          cd "${{ inputs.SERVICE_LOCATION || '.' }}" && \
+          cd "$SERVICE_LOCATION" && \
           mvn -U -B verify sonar:sonar \

Moving the input to an environment variable prevents template injection since the value isn't interpolated into the shell script itself.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.github/workflows/maven-sonar-analysis-new.yml at line 72, The workflow
currently interpolates inputs.SERVICE_LOCATION directly into the shell command
(cd "${{ inputs.SERVICE_LOCATION || '.' }}" && \) allowing potential
shell/template injection; instead set the input into an environment variable
(e.g., SERVICE_LOCATION) via env: and then use the env var in the shell step (cd
"$SERVICE_LOCATION" || cd '.') with proper double quotes so the value is not
template-expanded into the script; update the step that references
inputs.SERVICE_LOCATION to read from the environment variable and ensure the
fallback to '.' is handled in the shell using a safe quoted expression.

52-55: ⚡ Quick win

Avoid direct template interpolation to mitigate injection risk.

${{ github.ref }} is interpolated directly into the shell command. While the risk is lower in a workflow_call context, using an environment variable is safer and avoids potential command injection if a ref contains shell metacharacters.

🔧 Safer pattern using env
       - name: Setup env
-        run: |
-          echo "BRANCH_NAME=$(echo ${{ github.ref }} | sed -e 's,.*/\(.*\),\1,')" >> $GITHUB_ENV
+        run: |
+          echo "BRANCH_NAME=$(echo "$GITHUB_REF" | sed -e 's,.*/\(.*\),\1,')" >> $GITHUB_ENV
           echo "GPG_TTY=$(tty)" >> $GITHUB_ENV

GITHUB_REF is a built-in environment variable that's safer to use than template expansion.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.github/workflows/maven-sonar-analysis-new.yml around lines 52 - 55, In the
"Setup env" step avoid template interpolation of github.ref; instead read the
built-in environment variable GITHUB_REF inside the shell and use that to
compute BRANCH_NAME. Update the command that sets BRANCH_NAME (referencing the
BRANCH_NAME assignment in the "Setup env" step) to use $GITHUB_REF rather than
${{ github.ref }}, and keep the GPG_TTY assignment (GPG_TTY and tty usage)
unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In @.github/workflows/maven-sonar-analysis-new.yml:
- Line 69: The SERVICE_KEY sed pipeline uses the literal sequence s|-\\+|-|g
which matches a backslash plus instead of collapsing consecutive hyphens; update
the sed substitution in the SERVICE_KEY assignment to use a proper regex such as
s|-\+|-|g for GNU sed or s|--*|-|g for POSIX compatibility so multiple
consecutive '-' are collapsed into a single '-' (replace the s|-\\+|-|g token
accordingly).

---

Nitpick comments:
In @.github/workflows/maven-sonar-analysis-new.yml:
- Around line 35-43: Update the GitHub Actions steps to use the v4 releases and
disable credential persistence: change uses: actions/checkout@v3 to uses:
actions/checkout@v4 and add persist-credentials: false to that checkout step;
change uses: actions/setup-java@v3 to uses: actions/setup-java@v4 while keeping
existing inputs (distribution: temurin, java-version: '21', server-id,
settings-path) intact so behavior remains the same.
- Line 72: The workflow currently interpolates inputs.SERVICE_LOCATION directly
into the shell command (cd "${{ inputs.SERVICE_LOCATION || '.' }}" && \)
allowing potential shell/template injection; instead set the input into an
environment variable (e.g., SERVICE_LOCATION) via env: and then use the env var
in the shell step (cd "$SERVICE_LOCATION" || cd '.') with proper double quotes
so the value is not template-expanded into the script; update the step that
references inputs.SERVICE_LOCATION to read from the environment variable and
ensure the fallback to '.' is handled in the shell using a safe quoted
expression.
- Around line 52-55: In the "Setup env" step avoid template interpolation of
github.ref; instead read the built-in environment variable GITHUB_REF inside the
shell and use that to compute BRANCH_NAME. Update the command that sets
BRANCH_NAME (referencing the BRANCH_NAME assignment in the "Setup env" step) to
use $GITHUB_REF rather than ${{ github.ref }}, and keep the GPG_TTY assignment
(GPG_TTY and tty usage) unchanged.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 72d0d10f-36dd-445c-8d0d-7673d15bf1c2

📥 Commits

Reviewing files that changed from the base of the PR and between 6bb3c38 and 0f344b8.

📒 Files selected for processing (1)
  • .github/workflows/maven-sonar-analysis-new.yml

Comment thread .github/workflows/maven-sonar-analysis-new.yml
@ckm007
ckm007 merged commit 7f0be96 into mosip:develop Jun 10, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants