Skip to content

Commit

Permalink
Add pull-request Input Support for Retrieving Result from the Pull …
Browse files Browse the repository at this point in the history
…Request (#30)

* build: update patch versions

* build: update minor versions

* feat: add support for `pullRequest` input

* docs: add `pullRequest` input to README

* feat/refactor: define actions input and use `kebab-case` for input name

* ci: update PR workflow to verify action run with `pull-request` input

* ci/fix: add `sonar.pullrequest.branch` parameter

* build: bump version to `1.5.0`

* ci/refactor: update step name and remove unused input

* ci: try to specify both `branch` and `pull-request` input

* feat: add mutually exclusive error on `branch` and `pull-request` input

* ci/refactor: remove test to fail step

* refactor: update inputs description
  • Loading branch information
phwt authored Oct 7, 2024
1 parent e6daa1b commit fdbf780
Show file tree
Hide file tree
Showing 9 changed files with 216 additions and 97 deletions.
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.pullrequest.branch=${{ github.event.pull_request.head.ref }}
-Dsonar.cpd.exclusions=**/__tests__/*.ts
- name: Wait for the quality gate result
run: sleep 5

- 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 }}
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
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ Check quality gate result from latest analysis and report result in the pull req
| github-token | GitHub Token for commenting on the pull request - not required if `disable-pr-comment` is set to `true` | `false` | |
| disable-pr-comment | Disable commenting result on the pull request | `false` | false |
| fail-on-quality-gate-error | Set the action status to failed when quality gate status is `ERROR` | `false` | false |
| branch | Branch name to retrieve the quality gate result | `false` | |
| branch | Branch name to retrieve the quality gate result, mutually exclusive with `pull-request` input | `false` | |
| pull-request | Pull request id to retrieve the quality gate result, mutually exclusive with `branch` input | `false` | |

<!-- action-docs-inputs -->

Expand Down Expand Up @@ -54,7 +55,8 @@ jobs:
sonar-host-url: ${{ secrets.SONAR_HOST_URL }}
sonar-token: ${{ secrets.SONAR_TOKEN }}
github-token: ${{ secrets.GITHUB_TOKEN }}
branch: main # Optional input
branch: main # Optional input, mutually exclusive with `pull-request`
pull-request: 8 # Optional input, mutually exclusive with `branch`

- name: Output result
run: |
Expand Down Expand Up @@ -89,7 +91,8 @@ jobs:
sonar-host-url: ${{ secrets.SONAR_HOST_URL }}
sonar-token: ${{ secrets.SONAR_TOKEN }}
github-token: ${{ secrets.GITHUB_TOKEN }}
branch: main # Optional input
branch: main # Optional input, mutually exclusive with `pull-request`
pull-request: 8 # Optional input, mutually exclusive with `branch`

- name: Output result
run: |
Expand Down
5 changes: 4 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ inputs:
required: false
default: "false"
branch:
description: "Branch name to retrieve the quality gate result"
description: "Branch name to retrieve the quality gate result, mutually exclusive with `pull-request` input"
required: false
pull-request:
description: "Pull request id to retrieve the quality gate result, mutually exclusive with `branch` input"
required: false
outputs:
project-status:
Expand Down
Loading

0 comments on commit fdbf780

Please sign in to comment.