-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3196a05
commit b39ba54
Showing
1 changed file
with
29 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,67 +1,38 @@ | ||
name: Check testcases and quality gate status | ||
name: Analyze pull request | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- "*" | ||
- '*' | ||
|
||
jobs: | ||
sonarqube-analysis: | ||
build: | ||
|
||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout code | ||
- name: Setup sonarqube | ||
uses: warchant/setup-sonar-scanner@v1 | ||
|
||
- name: 'Checkout repository on branch: ${{ github.REF }}' | ||
uses: actions/checkout@v2 | ||
|
||
- name: Set up Node.js | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: "14" | ||
|
||
- name: Set branch name | ||
id: set_branch | ||
ref: ${{ github.HEAD_REF }} | ||
|
||
- name: Retrieve entire repository history | ||
run: | | ||
if [[ $GITHUB_EVENT_NAME == 'pull_request' ]]; then | ||
BRANCH_NM=${GITHUB_HEAD_REF} | ||
else | ||
BRANCH_NM=$(echo ${GITHUB_REF#refs/heads/}) | ||
fi | ||
echo "BRANCH_NAME=((${BRANCH_NE}))" >> $GITHUB_ENV | ||
- name: Scanning the project with sonarQube scanner | ||
run: | | ||
if [[ $GITHUB_EVENT_NAME == 'pull_request' ]]; then | ||
BRANCH_NAME=${GITHUB_HEAD_REF} | ||
else | ||
BRANCH_NAME=$(echo ${GITHUB_REF#refs/heads/}) | ||
fi | ||
echo "BRANCH_NAME=${BRANCH_NAME}" >> $GITHUB_ENV | ||
npm install -g sonarqube-scanner | ||
sonar-scanner \ | ||
-Dsonar.host.url='http://sonarqube.kcspl.in:9000/' \ | ||
-Dsonar.projectKey='kcs-arpitdixit_branchname' \ | ||
-Dsonar.login=cab872eb9f133e53532de29a9fb7bec0cd9b61e2 \ | ||
-Dsonar.branch.name=$BRANCH_NAME | ||
- name: identify SonarQube Quality Gate status | ||
id: quality_gate_status | ||
run: | | ||
echo "Identifying quality gate status..." | ||
if [[ $GITHUB_EVENT_NAME == 'pull_request' ]]; then | ||
BRANCH_NAME=${GITHUB_HEAD_REF} | ||
else | ||
BRANCH_NAME=$(echo ${GITHUB_REF#refs/heads/}) | ||
fi | ||
echo "BRANCH_NAME=${BRANCH_NAME}" >> $GITHUB_ENV | ||
STATUS=$(curl -s "http://sonarqube.kcspl.in:9000/api/qualitygates/project_status?projectKey=kcs-arpitdixit_branchname&branch=${BRANCH_NAME}" -u "89f09c21d9b7f2f8e67b98200b5772794b4c2872" | jq -r '.projectStatus.status') | ||
echo "Quality Gate Status for branch $BRANCH_NAME: $STATUS" | ||
echo "QUALITY_GATE_STATUS=$STATUS" >> $GITHUB_ENV | ||
|
||
- name: Check Quality Gate status | ||
run: | | ||
if [ "$QUALITY_GATE_STATUS" != "OK" ]; then | ||
echo "SonarQube Quality Gate Failed for branch $BRANCH_NAME!!" | ||
exit 1 | ||
else | ||
echo "SonarQube Quality Gate passed for branch $BRANCH_NAME!!" | ||
fi | ||
git fetch --prune --unshallow | ||
- name: Run an analysis of the PR | ||
env: | ||
# to get access to secrets.SONAR_TOKEN, provide GITHUB_TOKEN | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
run: sonar-scanner | ||
-Dsonar.host.url='http://sonarqube.kcspl.in:9000/' | ||
-Dsonar.login='89f09c21d9b7f2f8e67b98200b5772794b4c2872' | ||
-Dsonar.projectKey='kcs-arpitdixit_branchname' | ||
-Dsonar.pullrequest.key=${{ github.event.number }} | ||
-Dsonar.pullrequest.branch=${{ github.HEAD_REF }} | ||
-Dsonar.pullrequest.base=${{ github.BASE_REF }} | ||
-Dsonar.pullrequest.github.repository=${{ github.repository }} | ||
-Dsonar.scm.provider=git | ||
-Dsonar.java.binaries=/tmp |