Skip to content

About

GitHub Action that converts SonarQube issues to SARIF for GitHub Code Scanning.

Topics

Resources

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Repository files navigation

SonarQube → GitHub Security Tab

CI GitHub Marketplace License: MIT

What is this?

SonarQube can analyze code, but it does not give you the GitHub experience most teams actually want: pull request annotations, a check run summary, and SARIF that GitHub can ingest. This action fills that gap.

It fetches issues from the SonarQube REST API, converts them to SARIF, writes a file for github/codeql-action/upload-sarif, creates a GitHub Check Run, and can post a PR summary comment. In pull requests, it narrows the feedback to files changed in the PR so reviewers are not buried in the entire backlog.

If you already run SonarQube and want the results to show up where developers work, this is the missing piece.

Supported editions

The action works against the SonarQube REST API and is edition-agnostic:

Edition Works? Notes
Community (CE) Yes Full support. No branch analysis in SonarQube itself.
Developer (DE) Yes Branch and PR analysis available on the SonarQube side.
Enterprise (EE) Yes Same API surface.
Data Center (DC) Yes Same API surface.
SonarCloud Partial API differs; not officially tested.

For Developer Edition and above, SonarQube itself can perform true PR analysis. The branch input lets you target a specific branch when fetching issues, which pairs well with DE/EE branch analysis.

Quick Start

This is the happy path. Run SonarQube, convert the results, and upload SARIF only on non-PR events.

name: SonarQube Analysis

on:
  push:
    branches: [main]
  pull_request:

jobs:
  analyze:
    runs-on: ubuntu-latest
    permissions:
      security-events: write
      checks: write
      pull-requests: write

    steps:
      - uses: actions/checkout@v6
        with:
          fetch-depth: 0

      - name: SonarQube Scan
        uses: sonarsource/sonarqube-scan-action@v7
        env:
          SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
          SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}

      - name: Convert SonarQube issues to SARIF
        uses: vmvarela/sonarqube-sarif@v1
        with:
          sonar-host-url: ${{ secrets.SONAR_HOST_URL }}
          sonar-token: ${{ secrets.SONAR_TOKEN }}

      - name: Upload SARIF
        if: github.event_name != 'pull_request'
        uses: github/codeql-action/upload-sarif@v4
        with:
          sarif_file: sonarqube.sarif

What happens when it runs?

  • On any run, the action fetches SonarQube issues, converts them to SARIF, writes the file, and exposes counts as outputs.
  • If a GitHub token is available, it also creates a Check Run with up to 50 annotations.
  • In PR context, it filters issues to changed files and can upsert a summary PR comment.
  • On push to the default branch, you usually upload the SARIF file so GitHub Security reflects the branch that matters.

That split is deliberate. PRs need review feedback; the Security tab needs a stable view of the default branch.

Recommended workflow

Use this action in two modes:

  1. Pull requests: rely on the Check Run and optional PR comment.
  2. Default branch pushes: upload the generated SARIF to GitHub code scanning.

On Community Edition, SonarQube does not do true PR analysis — it analyzes the project state it knows about. This action filters the results to changed files, which is useful for review but is not the same as "only issues introduced by this PR."

On Developer Edition and above, SonarQube can analyze branches and PRs natively. Pair the branch input with SonarQube's branch analysis for more precise results.

Inputs you will probably care about

These are the knobs most teams end up using:

Input Default Why you would change it
project-key repository name Your SonarQube project key does not match the repo name.
branch unset Target a specific SonarQube branch (useful for DE/EE/DC).
min-severity INFO Ignore low-severity noise.
fail-on-severity unset Turn findings into a failing check.
wait-for-processing true Disable polling if your token lacks Execute Analysis permission.
processing-delay 0 Wait a fixed number of seconds before fetching issues.
pr-comment auto-enabled in PRs Silence the PR comment if you only want the Check Run.
include-resolved false Include resolved issues in the SARIF output.
include-hotspots false Also export Security Hotspots (requires SonarQube >= 9.8).
output-file sonarqube.sarif Write the SARIF file somewhere else.
skip-preflight false Disable startup validation for offline or air-gapped setups.
pin-to-analysis false Only export findings from this workflow's own scan.
report-task-path — Path to report-task.txt; required by pin-to-analysis.

Note on processing-delay: the delay is applied in both modes — as a standalone wait when wait-for-processing: false, and also at the start of the polling loop when wait-for-processing: true. This lets you insert a fixed warm-up period even when polling is enabled.

Full input reference

Input Default Notes
sonar-host-url — Required. Must be http:// or https://.
sonar-token — Required. Needs SonarQube Browse permission.
project-key repo name Falls back to the GitHub repository name.
output-file sonarqube.sarif Directories are created if needed.
branch unset Pass explicitly when you need a branch-specific SonarQube query.
wait-for-processing true Polls SonarQube until analysis completes or times out.
max-wait-time 300 Timeout, in seconds, for polling.
polling-interval 10 Interval, in seconds, between polling attempts.
processing-delay 0 Fixed delay (seconds, max 600) applied before fetching issues. Also runs before the polling loop when wait-for-processing: true.
min-severity INFO One of INFO, MINOR, MAJOR, CRITICAL, BLOCKER.
include-resolved false Includes resolved issues in the fetched dataset.
include-hotspots false Fetch Security Hotspots via /api/hotspots/search and include them (requires SonarQube >= 9.8).
pr-comment auto Enabled automatically when running in a PR context; set explicitly to true or false to override.
fail-on-severity unset Fails the Check Run when issues at or above the threshold exist.
github-token github.token Used for Check Runs, PR comments, and PR file lookup.
skip-preflight false Skip startup checks (URL reachability, token, project key).
pin-to-analysis false Wait for this scan's exact task and verify it is still the latest analysis before exporting. See below.
report-task-path — Required when pin-to-analysis: true. No default; see below.

Note on include-hotspots: opt-in, and it requires SonarQube >= 9.8 because it queries /api/hotspots/search. The endpoint returns at most 10,000 hotspots: the action warns and truncates in normal mode, and reports incomplete-fetch under pin-to-analysis. SonarQube 2026.4 deprecates the endpoint, where hotspots become security issues.

Pinning the export to your own scan

By default the action exports whichever findings are current when it fetches. If another analysis lands in between, the SARIF attached to your commit can describe someone else's scan.

Set pin-to-analysis: true on default-branch runs to tie the export to the task this scan submitted:

- name: SonarQube scan
  run: sonar-scanner
- uses: vmvarela/sonarqube-sarif@v1
  id: export
  with:
    sonar-host-url: ${{ secrets.SONAR_HOST_URL }}
    sonar-token: ${{ secrets.SONAR_TOKEN }}
    pin-to-analysis: true
    report-task-path: .scannerwork/report-task.txt
- uses: github/codeql-action/upload-sarif@v3
  if: steps.export.outputs.export-status == 'ok'
  with:
    sarif_file: ${{ steps.export.outputs.sarif-file }}

Pinned mode waits for the task's analysisId, then requires it to match the project's latest analysis and that analysis' revision to match GITHUB_SHA and the checked-out HEAD. It reuses max-wait-time and polling-interval for the task poll, and the export step must run in the repository root so the action can read the checked-out HEAD. It rejects, without writing SARIF or creating check runs and PR comments, when:

export-status Meaning
not-default-branch The run is not a push to the default branch (PRs and tags included).
invalid-metadata report-task.txt is unreadable, incomplete, or names another project/server.
branch-override-not-supported pin-to-analysis queries the main branch, so it does not accept the branch input.
permission-denied The token lacks Execute Analysis or Browse.
task-failed The task failed, was canceled, timed out, or is unknown to SonarQube.
no-analysis The project has no analysis yet.
stale-analysis A newer analysis of the project superseded this scan.
revision-mismatch The analysis has no revision, or it differs from the workflow commit.
incomplete-fetch The export could not fetch every issue window completely.

report-task.txt has no default because its location is build-tool specific (.scannerwork, build/sonar, target/sonar). The scan and the export must run in the same job, or pass the file from the scan job as an artifact.

Pinned mode is a best-effort identity check, not a snapshot: SonarQube's issue index is live, so manual issue edits made while the export runs are not detected. Do not run concurrent scans of the same project while exporting.

Pinned mode requires Browse and Execute Analysis on the SonarQube project, and GitHub's default branch name must match the SonarQube project's main branch.

Real examples

Use a severity gate when you want review feedback for everything, but only fail the job on serious findings.

- uses: vmvarela/sonarqube-sarif@v1
  with:
    sonar-host-url: ${{ secrets.SONAR_HOST_URL }}
    sonar-token: ${{ secrets.SONAR_TOKEN }}
    min-severity: MAJOR
    fail-on-severity: CRITICAL

If your SonarQube token cannot query Compute Engine status, skip polling and wait a fixed amount of time instead.

- uses: vmvarela/sonarqube-sarif@v1
  with:
    sonar-host-url: ${{ secrets.SONAR_HOST_URL }}
    sonar-token: ${{ secrets.SONAR_TOKEN }}
    wait-for-processing: false
    processing-delay: 60

On Developer Edition, target a specific branch to fetch branch-specific issues.

- uses: vmvarela/sonarqube-sarif@v1
  with:
    sonar-host-url: ${{ secrets.SONAR_HOST_URL }}
    sonar-token: ${{ secrets.SONAR_TOKEN }}
    branch: ${{ github.ref_name }}

If the PR comment becomes noise, keep the Check Run and disable the comment.

- uses: vmvarela/sonarqube-sarif@v1
  with:
    sonar-host-url: ${{ secrets.SONAR_HOST_URL }}
    sonar-token: ${{ secrets.SONAR_TOKEN }}
    pr-comment: false

For air-gapped setups or environments where the SonarQube host is not reachable from the runner at startup, skip the pre-flight checks.

- uses: vmvarela/sonarqube-sarif@v1
  with:
    sonar-host-url: ${{ secrets.SONAR_HOST_URL }}
    sonar-token: ${{ secrets.SONAR_TOKEN }}
    skip-preflight: true

Outputs

The action always emits the SARIF path plus counts you can reuse in later workflow steps.

Output Meaning
sarif-file Path to the generated SARIF file
issues-count Total issues after filtering
rules-count Unique rules represented in the result
components-count Files/components referenced by remaining issues
blocker-count / critical-count / major-count / minor-count / info-count Severity counts
bugs-count / vulnerabilities-count / code-smells-count / hotspots-count Type counts
api-request-count / api-error-count / api-retry-count HTTP request metrics
pages-fetched Pagination pages retrieved from SonarQube
rule-fetch-success-rate Percentage of rule details successfully fetched
sarif-file-size-bytes Size of the generated SARIF file in bytes
processing-time-ms Total action duration in milliseconds
export-status ok after the SARIF is written; otherwise the pinned-mode rejection reason, when one applies

This is a typical follow-up step:

- name: Show SonarQube counts
  run: |
    echo "Issues: ${{ steps.sarif.outputs.issues-count }}"
    echo "Vulnerabilities: ${{ steps.sarif.outputs.vulnerabilities-count }}"

Permissions

The action uses GITHUB_TOKEN by default. Give it only what it needs.

permissions:
  security-events: write
  checks: write
  pull-requests: write

On the SonarQube side, Browse is required. Execute Analysis is needed for polling via wait-for-processing: true and for pin-to-analysis: true.

Limitations

  • PR filtering depends on changed-file lookup. If GitHub file lookup fails, the action falls back to the full issue set.
  • Check annotations are capped at 50. That is a GitHub Check Run limit, not a project limit. Issues are sorted by severity before the cap is applied, so the most critical findings always survive.
  • The action does not evaluate SonarQube Quality Gates. fail-on-severity is a separate, issue-based gate.
  • Community Edition has no branch or PR analysis. On CE, SonarQube analyzes the project as a whole; this action filters the result to changed files as a best-effort approximation.
  • Security Hotspots are opt-in and capped. include-hotspots: true queries /api/hotspots/search (SonarQube >= 9.8) and exports at most 10,000 hotspots — warned and truncated in normal mode, incomplete-fetch with pin-to-analysis. The endpoint is deprecated in SonarQube 2026.4, where hotspots become security issues.

If you need baseline-aware PR decoration on Community Edition, SonarQube Developer Edition is the better tool.

Related docs

License

MIT

About

GitHub Action that converts SonarQube issues to SARIF for GitHub Code Scanning.

Topics

Resources

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages