This is a minimal Node.js repo you can push to GitHub to demonstrate SonarQube Cloud analysis via GitHub Actions. It includes:
- A tiny code sample (
src/) and a Jest test (tests/) that produces coverage. sonar-project.propertiesconfigured for SonarQube Cloud.- A ready-to-run workflow in
.github/workflows/sonar.ymlusing the official SonarQube Scan GitHub Action.
- Create a project on SonarQube Cloud (aka SonarCloud) and note your organization key and project key.
- In this repo, edit
sonar-project.propertiesand replace the placeholders forsonar.organizationandsonar.projectKey. - Commit & push to GitHub.
- In your GitHub repository: Settings → Secrets and variables → Actions → New repository secret:
- Name:
SONAR_TOKEN - Value: your token from SonarQube Cloud.
- Name:
- Trigger the workflow by pushing a commit or opening a PR. After it runs, visit your project in SonarQube Cloud to see the results.
If you use a self‑hosted runner, ensure
unzipandcurlorwgetare installed.
nvm use 20 # or Node.js 20+
npm ci
npm test -- --coverage- The workflow runs tests, collects coverage (
coverage/lcov.info), then runs the Sonar scan. - Update the action version in
.github/workflows/sonar.ymlto the latest stable if needed.