Skip to content

Commit

Permalink
ci: update PR workflow to verify action run with pull-request input
Browse files Browse the repository at this point in the history
  • Loading branch information
phwt committed Oct 7, 2024
1 parent eb65863 commit 94a64c5
Showing 1 changed file with 50 additions and 1 deletion.
51 changes: 50 additions & 1 deletion .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ env:
SONAR_PROJECT_KEY: sonarqube-quality-gate-action

jobs:
sonar-scan:
sonar-scan-branch:
name: Check code quality on pull request branch
runs-on: ubuntu-latest
steps:
Expand Down Expand Up @@ -57,6 +57,55 @@ jobs:
echo "${{ steps.quality-gate-check.outputs.project-status }}"
echo "${{ steps.quality-gate-check.outputs.quality-gate-result }}"
sonar-scan-pr:
name: Check code quality on the pull request
if: github.event_name == 'pull_request'
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.pullrequest.key=${{ github.event.number }}
-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 }}
pull-request: ${{ github.event.number }}
disable-pr-comment: 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
Expand Down

0 comments on commit 94a64c5

Please sign in to comment.