GOAL: Setup SonarCloud to run as a part of your GitHub Actions!
- Fork this repository that contains an example Inventory App starter code from Bootcamp.
- Navigate to SonarCloud dashboard and press the ✚ sign to analyze a new project.
- Select the project that you forked from GitHub.
- Select "GitHub Actions" as your analysis method
The next steps may disappear on the initial setup as a report finishes. To access these if they disappear go to the following on the project page Admistration → Analysis Method → GitHub Actions Follow the Tutorial
- In GitHub, copy and add the provided
SONAR_TOKEN
and value as a repository secret.
- Select "Other (for JS, TS, Go, Python, PHP, …)
- Copy the provided code into your build.yml file. The code should look similar to the one shown below.
name: Jest -> SonarCloud
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
jobs:
sonarcloud:
name: SonarCloud
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: SonarCloud Scan
uses: SonarSource/sonarcloud-github-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
# These commands exist in the original file.
- name: Install Dependencies
run: npm i
- name: Run tests
run: npm run test
# Add deployment commands here
- Create a sonar-project.properties file in the root directory of the project. Copy the provided code.
- Disable automatic analysis.
- Save and push your changes and GitHub Actions will now run your analysis on SonarCloud.