Skip to content

This sample app demonstrate how to set up SonarQube in local, run with GitHub Actions for a Node.js project.

Notifications You must be signed in to change notification settings

rupachowrasia/nodejs-sonarqube-setup-with-github-action

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

14 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Setup SonarQube for a Node.js project with Github Action

This sample app demonstrate how to set up SonarQube with GitHub Actions for a Node.js project.

  • We will be installing SonarQube on local machine.
  • Install SonarScanner globally in local machine.
  • We will be using Self-Hosted GitHub Runner, which lets GitHub Actions use localhost to access your local SonarQube server. Go to your GitHub repo: Settings β†’ Actions β†’ Runners β†’ New self-hosted runner

🚨 Important: GitHub Actions Cannot Access Your Localhost

  • If you’re using a self-hosted SonarQube on your machine and try to run analysis from GitHub Actions, localhost will not work, because GitHub Actions runs on GitHub-hosted VMs, not your machine.
  • βœ… Solution Options:
    • Option 1: Use SonarCloud (Recommended for GitHub)
    • Option 2: Host SonarQube on a Public Server or Cloud (e.g., GCP, AWS) - You’ll need to deploy SonarQube on a reachable IP or domain and update: sonar.host.url=http://your-public-ip:9000
    • Option 3: Use a Self-Hosted GitHub Runner (Advanced) - Install GitHub Actions runner on your machine (where SonarQube is running), so localhost works as expected.

πŸ›  Basic Setup - step by step

  • You should have a SonarQube server (self-hosted, either cloud or local)
  • Setup/Install SonarQube and login with Admin/Admin (If running from local it should run on http://localhost:9000/)
  • After login create SonarQube Token: β†’ My Account β†’ Security β†’ Generate Token
  • Create a new project
  • Add the token in GitHub repo: βž” GitHub β†’ Settings β†’ Secrets and variables β†’ Actions β†’ New Repository Secret:
  • Create a file called sonar-project.properties and keep it in root of project:
      sonar.projectKey=<YOUR_PROJECT_KEY>
      sonar.host.url=<https://your-sonarqube-server.com>
      sonar.sources=.
      sonar.language=js
  • Add GitHub Action Workflow (.github/workflows/sonarqube.yml): code is provided in the Repo.

⚑ Custom Quality Gates

  • In SonarQube UI β†’ Go to your project β†’ Administration β†’ Quality Gates β†’ create your own rules, like:
    • Coverage > 80%
    • 0 Bugs
    • 0 Critical Security Hotspots
  • Your PRs will only pass if they meet this standard!

πŸ“¦ Installation

# Clone the repo
git clone https://github.com/rupachowrasia/nodejs-sonarqube-setup-with-github-action.git

# Move into the project directory
cd nodejs-sonarqube-setup-with-github-action

# Install dependencies
npm install

# Run the app
npm run start

About

This sample app demonstrate how to set up SonarQube in local, run with GitHub Actions for a Node.js project.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published