How to show Quality Gate status after run Sonarscan by Github Action to PR checks tab or comment

Hi there.
I search many sites to resolve this problem but I can’t.
I am setting a Github workflow for

  • run unit test
  • run Sonarcloud scan.
    This is my file:
name: quality-control
run-name: ${{ github.actor }} just push/merge code
on: [push]
jobs:
  unit-test:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout Branch
        uses: actions/checkout@v3
      - name: Install NodeJs
        uses: actions/setup-node@v3
        with:
          node-version: '16.17.1'
          cache: 'npm'
      - name: Cache/Restore node modules
        id: cache-node-modules
        uses: actions/cache@v3
        env:
          cache-name: cache-node-modules
        with:
          path: node_modules
          key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
          restore-keys: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
      - name: Install dependency packages
        if: steps.cache-node-modules.outputs.cache-hit != 'true'
        run: npm ci
      - name: Run unit test
        run: npx jest --coverage
      - name: Upload coverage report artifact
        uses: actions/upload-artifact@v3
        with:
          name: code-coverage-report
          path: coverage/lcov.info
  sonar-scan:
    name: SonarQube Scan
    needs: unit-test
    runs-on: ubuntu-latest
    steps:
      - name: Checkout Branch
        uses: actions/checkout@v3
        with:
          node-version: '16.17.1'
      - name: Download coverage report artifact
        uses: actions/download-artifact@v3
        with:
          name: code-coverage-report
          path: ./coverage
      - name: SonarCloud Scan
        uses: SonarSource/sonarcloud-github-action@master
        env:
          GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN }}
          SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
          SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}

But after the action run success, I only see this on PR “Checks” tab

But as I know, we can see this result

Further, I know we can install Sonarcloud Github App to show result as a comment of PR.

But it is not free, isn’t it. We are using Github TeamPlan and SonarCloud Developer plan.

Can you give me an advice? Thanks so much.

Hey there.

You can get all of this for free!

And, it seems like you’re running on a push event rather than a pull_request event.

We recommend this in the in-UI tutorial for GitHub Actions:

name: Build
on:
  push:
    branches:
      - main
  pull_request:
    types: [opened, synchronize, reopened]

I update my workflow file as your recommendation.
But it doesn’t work, I still see nothing on Check tab.

This is my workflow file

name: quality-control
run-name: ${{ github.actor }} just push/merge code
on:
  push:
    branches:
      - master
  pull_request:
    types: [opened, synchronize, reopened]
jobs:
  unit-test:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout Branch
        uses: actions/checkout@v3
      - name: Install NodeJs
        uses: actions/setup-node@v3
        with:
          node-version: '16.17.1'
          cache: 'npm'
      - name: Cache/Restore node modules abc
        id: cache-node-modules
        uses: actions/cache@v3
        env:
          cache-name: cache-node-modules
        with:
          path: node_modules
          key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
          restore-keys: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
      - name: Install dependency packages
        if: steps.cache-node-modules.outputs.cache-hit != 'true'
        run: npm ci
      - name: Run unit test
        run: npx jest --coverage
      - name: Upload coverage report artifact
        uses: actions/upload-artifact@v3
        with:
          name: code-coverage-report
          path: coverage/lcov.info
  sonar-scan:
    name: SonarQube Scan
    needs: unit-test
    runs-on: ubuntu-latest
    steps:
      - name: Checkout Branch
        uses: actions/checkout@v3
        with:
          node-version: '16.17.1'
      - name: Download coverage report artifact
        uses: actions/download-artifact@v3
        with:
          name: code-coverage-report
          path: ./coverage
      - name: SonarCloud Scan
        uses: SonarSource/sonarcloud-github-action@master
        env:
          GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN }}
          SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
          SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}

Is your SonarCloud project bound?

It is bound to Bitbucket for now.
And our Github is just Team Plan not Enterprise plan, is it problem?

GitHub PR Decoration will only work if a project is bound to GitHub, in an organization that is bound to GitHub.

I am also having similar request. I am trying to do in a “push” event. So when developer pushes code their feature branch sonarcloud analysis runs. And have same issue here. in SonarCloud quality gate checks failed. So my questions how to get a “failure” response back from sonarcloud to calling action in github?

====
name: NodeJS

on:
push:
branches: [ “features” ]
pull_request:
branches: [ “main” ]

jobs:
build:
runs-on: ubuntu-latest

strategy:
  matrix:
    node-version: [16.x]

steps:
- uses: actions/checkout@v3

- name: Use Node.js ${{ matrix.node-version }}
  uses: actions/setup-node@v3
  with:
    node-version: ${{ matrix.node-version }}

- name: Build
  run: |
    npm install

sonar-analysis:
name: SonarCloud
runs-on: ubuntu-latest
needs: [ build ]
steps:
- uses: actions/checkout@v3

- name: SonarCloud Scan
  uses: SonarSource/sonarcloud-github-action@v1.7
  env:
    SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
    SONAR_PROJECT_KEY:  ${{ secrets.SONAR_PROJECT_KEY }}
    SONAR_PROJECT_NAME:  ${{ env.SONAR_PROJECT_NAME }}
    SONAR_PROJECT_VERSION:  ${{ env.SONAR_PROJECT_VERSION }}

==============

Also i want github action to be failed if SonarCloud analysis reports Failures