on:
  push:
    branches:
      - master
  pull_request:
    types: [opened, synchronize, reopened]
name: SonarCloud Analysis
jobs:
  sonarcloud:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
        with:
          # Disabling shallow clone is recommended for improving relevancy of reporting
          fetch-depth: 0
      - name: Set up Ruby ${{ matrix.ruby }}
        uses: ruby/setup-ruby@v1
        with:
          ruby-version: "3.1"
      - name: "Install dependencies"
        run: bundle install
      - name: Run tests for coverage
        run: bundle exec rspec
      - name: SonarCloud Scan
        uses: sonarsource/sonarcloud-github-action@master
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
          COVERAGE: json

on:
  push:
    branches:
      - master
  pull_request:
    types: [opened, synchronize, reopened]
name: SonarCloud Analysis
jobs:
  sonarcloud:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
        with:
          # Disabling shallow clone is recommended for improving relevancy of reporting
          fetch-depth: 0
      - name: Set up Ruby ${{ matrix.ruby }}
        uses: ruby/setup-ruby@v1
        with:
          ruby-version: "3.1"
      - name: "Install dependencies"
        run: bundle install
      - name: Run tests for coverage
        run: bundle exec rspec
        env:
          COVERAGE: json
      - name: SonarCloud Scan
        uses: sonarsource/sonarcloud-github-action@master
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

Add env in right place in GitHub Action
Add env in right place in GitHub Action
