Skip to content

Update sonarqube.yml #14

Update sonarqube.yml

Update sonarqube.yml #14

Workflow file for this run

# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
# This workflow helps you trigger a SonarQube analysis of your code and populates
# GitHub Code Scanning alerts with the vulnerabilities found.
# (this feature is available starting from SonarQube 9.7, Developer Edition and above)
# 1. Make sure you add a valid GitHub configuration to your SonarQube (Administration > DevOps platforms > GitHub)
# 2. Import your project on SonarQube
# * Add your repository as a new project by clicking "Create project" from your homepage.
#
# 3. Select GitHub Actions as your CI and follow the tutorial
# * a. Generate a new token and add it to your GitHub repository's secrets using the name SONAR_TOKEN
# (On SonarQube, click on your avatar on top-right > My account > Security or ask your administrator)
#
# * b. Copy/paste your SonarQube host URL to your GitHub repository's secrets using the name SONAR_HOST_URL
#
# * c. Copy/paste the project Key into the args parameter below
# (You'll find this information in SonarQube by following the tutorial or by clicking on Project Information at the top-right of your project's homepage)
# Feel free to take a look at our documentation (https://docs.sonarqube.org/latest/analysis/github-integration/)
# or reach out to our community forum if you need some help (https://community.sonarsource.com/c/sq/10)
name: SonarQube analysis
on:
push:
branches: [ "develop" ]
pull_request:
branches: [ "develop" ]
types: [opened, synchronize, reopened]
workflow_dispatch:
permissions:
pull-requests: read # allows SonarQube to decorate PRs with analysis results
jobs:
Analysis:
runs-on: ubuntu-latest
strategy:
matrix:
node_version: ['20.x']
steps:
- name: Checkout code
- uses: actions/checkout@v2
with:
# Disabling shallow clone is recommended for improving relevancy of reporting.
fetch-depth: 0
- name: npm install and test
run: |
npm install
npm run test
- name: Analyze with SonarQube
# You can pin the exact commit or the version.
# uses: SonarSource/[email protected]
uses: SonarSource/[email protected]
env:
GITHUB_TOKEN: 5f00e34e-2186-4fad-9668-8ef15af3b6b1 # Needed to get PR information
SONAR_TOKEN: squ_d48999c121b577436aa15e362bafba7590ba473a # Generate a token on SonarQube, add it to the secrets of this repo with the name SONAR_TOKEN (Settings > Secrets > Actions > add new repository secret)
SONAR_HOST_URL: https://sonar.tools.sap # add the URL of your instance to the secrets of this repo with the name SONAR_HOST_URL (Settings > Secrets > Actions > add new repository secret)
with:
# Additional arguments for the sonarcloud scanner
args:
-Dsonar.projectKey=cap-js-sdm
-Dsonar.sources=lib
-Dsonar.exclusions=**/node_modules/**
-Dsonar.js.file.suffixes=.js,.jsx
-Dsonar.qualitygate.wait=true
-Dsonar.javascript.lcov.reportPaths=coverage/lcov.info
-Dsonar.exclusions=/dist/,/node_modules/,**/*.spec.js,**/*.test.js
-Dsonar.verbose=false # This should generally be set to `false` in a production environment to not clutter logs. Use `true` for debugging.
# Check the Quality Gate status.
- name: SonarQube Quality Gate check
id: sonarqube-quality-gate-check
uses: sonarsource/[email protected]
# Force to fail step after specific time.
timeout-minutes: 5
env:
SONAR_TOKEN: squ_d48999c121b577436aa15e362bafba7590ba473a
SONAR_HOST_URL: https://sonar.tools.sap #OPTIONAL
# Optionally you can use the output from the Quality Gate in another step.
# The possible outputs of the `quality-gate-status` variable are `PASSED`, `WARN` or `FAILED`.
- name: "Example show SonarQube Quality Gate Status value"
run: echo "The Quality Gate status is ${{ steps.sonarqube-quality-gate-check.outputs.quality-gate-status }}"