Skip to content

ci(sonar): run one scan against bcgov_common-notify, with coverage - #263

Open
NikhilMM89 wants to merge 2 commits into
mainfrom
fix/sonarqube-analysis
Open

NikhilMM89 wants to merge 2 commits into
mainfrom
fix/sonarqube-analysis

Conversation

@NikhilMM89

@NikhilMM89 NikhilMM89 commented Oct 7, 2026 •

Copy link
Copy Markdown
Collaborator

Why SonarQube isn't running

Two problems. The missing token was only one of them.

1. The scan has been silently skipped on every run.

bcgov/action-test-and-analyse guards its scan with if: inputs.sonar_token, and its own input description says "provide unpopulated token for pre-setup (will skip)". No token was set, so the scan never ran — while Analysis reported ✅ success.

Verified in run 37652147135: the scan action is downloaded, SONAR_TOKEN: is empty on every line, no scanner output is produced, and all four jobs pass.

The scan is still guarded on the token, so it now emits a warning annotation instead of passing in silence. A warning, not a failure — PRs stay green until the token is added.

2. The project keys were wrong, twice.

They started as the quickstart template's (quickstart-openshift_backend). I first changed them to bcgov_common-notify_backend / _frontend, assuming the monorepo setup we requested.

SonarCloud provisioned one project instead:

bcgov_common-notify              exists, analysed 2026-10-08
bcgov_common-notify_backend      404

So the two-key config would have failed with "project not found" the moment a token was added.

One scan, not two

Two scanners cannot push to a single project key and have results merge — whichever finishes last replaces the other's. So the scan now happens once over both apps, which is also the shape bcgov documents for a monorepo in one project (sonar.sources=ppr-api/src,ppr-ui/src in bcgov/sonarqube).

  • backend-tests and frontend-tests keep running lint, tests and coverage, and now publish their lcov.info as artifacts
  • a new sonar job collects both and scans once
  • the suites still run exactly once — coverage is handed over, not regenerated
  • the secret is a single SONAR_TOKEN, matching the standalone convention in the quickstart README

Behaviour change worth noting

triggers: is removed from both test jobs, so every PR now runs both suites.

With one Sonar project the scan needs coverage from both apps on every run. Otherwise a backend-only PR would report the frontend as uncovered and the project's coverage percentage would flap run to run. Each suite takes about a minute.

What's left

Add the token as a repo secret:

gh secret set SONAR_TOKEN

Generate it from https://sonarcloud.io/account/security. The warning annotation disappears on its own once it exists — no follow-up change.

Current state in SonarCloud

The project is live and already analysed, via Automatic Analysis:

bcgov_common-notify
lines of code     99,652
bugs                  22
vulnerabilities       44
code smells          722
duplicated lines     6.7%
coverage          ABSENT

Coverage is absent because automatic analysis can't run tests. This PR replaces that with CI-based analysis so the existing lcov pipeline is actually imported — both vitest configs already emit lcov to ./coverage, and CI produces it (the backend job runs 133 test files green with coverage enabled).


Thanks for the PR!

Deployments, as required, will be available below:

Please create PRs in draft mode. Mark as ready to enable:

After merge, new images are deployed in:

Two problems, neither of which the missing token alone explains.

action-test-and-analyse guards its scan with `if: inputs.sonar_token`, and its
own input description says "provide unpopulated token for pre-setup (will skip)".
SONAR_TOKEN_BACKEND and SONAR_TOKEN_FRONTEND are not set on this repo, so the
scan has been skipped on every run while the Analysis workflow reported success.
Verified in run 37652147135: the scan action is downloaded, SONAR_TOKEN is empty
on every line, no scanner output is produced, and all four jobs pass. A pipeline
that looks like it is analysing and is not is worse than one that is visibly
absent, so each job now emits a GitHub warning annotation when its token is
empty. A warning rather than a failure, so PRs stay green until the token lands.

The project keys were still the template's - quickstart-openshift_backend and
quickstart-openshift_frontend - so even with a valid token the scan would have
reported into a project this repo does not own, or failed on access. Changed to
bcgov_common-notify_backend / _frontend, matching the repo's current name
(it was renamed from nr-notify; the git remote still carries the old one) and
the bcgov_ prefix convention visible on existing org projects.

No SonarCloud project exists for this repo yet - searching the bcgov-sonarcloud
organisation for "common-notify" returns nothing - so the remaining work is a
bcgov/devops-requests issue asking for a monorepo project with backend and
frontend components, then adding the two tokens as repo secrets. The keys above
are what that request should ask for so config and reality match.

Checked while in here: both vitest configs emit the lcov reporter to the default
./coverage, which is what sonar.javascript.lcov.reportPaths expects, and CI
produces it - the backend job runs 133 test files green with coverage enabled.
So nothing else blocks the scan once the token exists.
…eated

The earlier commit assumed a monorepo and configured two project keys,
bcgov_common-notify_backend and _frontend. SonarCloud provisioned ONE project
instead - bcgov_common-notify - and bcgov_common-notify_backend returns 404.
Left as it was, the scan would have failed with "project not found" the moment
a token was added.

Two scanners cannot push to a single project key and have the results merge;
whichever finishes last replaces the other's. So the scan happens once, over
both apps, which is also the shape bcgov documents for a monorepo in one
project (sonar.sources=ppr-api/src,ppr-ui/src in bcgov/sonarqube).

The two test jobs keep running lint, tests and coverage, and now publish their
lcov as artifacts; a new sonar job collects both and scans once. The suites
still run exactly once - coverage is handed over, not regenerated.

Secret is now a single SONAR_TOKEN rather than the per-component pair, matching
the standalone convention in the quickstart README.

`triggers:` is removed from both test jobs, which is a real behaviour change:
every PR now runs both suites. With one Sonar project the scan needs coverage
from both apps on every run, otherwise a backend-only PR would report the
frontend as uncovered and the project's coverage would flap. The suites take
about a minute each.

The skip is still visible. The scan is guarded on the token, so without one the
job would pass having analysed nothing - how this went unnoticed to begin with.
It warns instead, and stays green until the token is added.

Already confirmed live: the project exists (bcgov_common-notify, analysed
2026-10-08, 99,652 ncloc, 44 vulnerabilities, 22 bugs, 722 smells) but reports
NO coverage, because automatic analysis cannot run tests. This replaces that
with CI-based analysis so coverage is imported.
@NikhilMM89 NikhilMM89 changed the title ci(sonar): point SonarQube at this repo, and stop the skip being silent ci(sonar): run one scan against bcgov_common-notify, with coverage Oct 8, 2026
@sonarqubecloud

sonarqubecloud Bot commented Oct 8, 2026

Copy link
Copy Markdown

This branch has not been deployed

No deployments
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.

1 participant