Skip to content

Feature/refactor

Feature/refactor #43

Workflow file for this run

name: Check code quality on pull request
on:
pull_request:
workflow_dispatch:
env:
SONAR_HOST_URL: https://sonarcloud.io
SONAR_PROJECT_KEY: sonarqube-quality-gate-action
jobs:
sonar-scan:
name: Check code quality on pull request branch
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-node@v4
with:
cache: npm
- name: Install dependencies and run test
run: |
npm ci
npm test
- name: SonarCloud Scan
uses: SonarSource/sonarcloud-github-action@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
with:
args: >
-Dsonar.organization=phwt
-Dsonar.projectKey=sonarqube-quality-gate-action
-Dsonar.javascript.lcov.reportPaths=./coverage/lcov.info
-Dsonar.branch.name=${{ github.event.pull_request.head.ref }}
-Dsonar.cpd.exclusions=**/__tests__/*.ts
- name: Wait for the quality gate result
run: sleep 5
- name: Create a comment with the result
uses: ./
id: quality-gate-check
with:
sonar-host-url: ${{ env.SONAR_HOST_URL }}
sonar-project-key: ${{ env.SONAR_PROJECT_KEY }}
sonar-token: ${{ secrets.SONAR_TOKEN }}
github-token: ${{ secrets.GITHUB_TOKEN }}
branch: ${{ github.event.pull_request.head.ref }}
fail-on-quality-gate-error: true
- run: |
echo "${{ steps.quality-gate-check.outputs.project-status }}"
echo "${{ steps.quality-gate-check.outputs.quality-gate-result }}"
sonar-scan-main:
name: Retrieve quality gate result of the main branch
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Retrieve quality gate result
uses: ./
id: quality-gate-check
with:
sonar-host-url: ${{ env.SONAR_HOST_URL }}
sonar-project-key: ${{ env.SONAR_PROJECT_KEY }}
sonar-token: ${{ secrets.SONAR_TOKEN }}
disable-pr-comment: true
- run: |
echo "${{ steps.quality-gate-check.outputs.project-status }}"
echo "${{ steps.quality-gate-check.outputs.quality-gate-result }}"