Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added sonar coverage #259

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions .github/workflows/scraper.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,54 @@ jobs:
with:
name: release-notes.md
path: scraper/scripts/release.md
test:
runs-on: [ self-hosted ]
name: Test
steps:
- name: checkout
id: checkout
uses: actions/checkout@v2
- name: running test
id: running_test
uses: docker://golang:alpine
env:
GIT_TOKEN: ${{ secrets.GIT_TOKEN }}
GIT_USERNAME: rzp
with:
entrypoint: /bin/sh
args: scripts/run_checks.sh test ci
- name: set_sonar_project
id: set_sonar_project
run: |
BRANCH="$(echo ${GITHUB_REF##*/})";
SONAR_PROJECT="IFSCDevCoverage"
if [ "$BRANCH" == "sonarCoverage" ]; then
SONAR_PROJECT="IfscUT";
fi
echo ::set-output name=sonar_project::$SONAR_PROJECT
- name: Push to Sonar
id: push_to_sonar
uses: sonarsource/[email protected]
env:
SONAR_TOKEN: ${{ secrets.SONARQUBE_TOKEN }}
SONARCLOUD_URL: ${{ secrets.SONARQUBE_HOST }}
with:
args: >
-Dsonar.host.url=${{ secrets.SONARQUBE_HOST }}
-Dsonar.projectKey=${{ steps.set_sonar_project.outputs.sonar_project }}
-Dsonar.projectName=${{ steps.set_sonar_project.outputs.sonar_project }}
-Dsonar.projectVersion=${{ github.sha }}
-Dsonar.login=${{ secrets.SONARQUBE_TOKEN }}
-Dsonar.projectBaseDir=/github/workspace/
-Dsonar.go.coverage.reportPaths=/github/workspace/sonarqube.cov
-Dsonar.exclusions=migrations/*,**/*_test.go,**/*mock.go,**/*coverage*,**/constants/*,**/*constants.go,coverage/*,**/logger/*
- name: Coverage Check
id: coverage_check
uses: docker://razorpay/onggi:nginx
if: github.ref != 'refs/heads/master' || !contains(github.ref,'hotfix')
with:
entrypoint: /bin/sh
args: scripts/code_coverage.sh #if issue for older coverage comes, needs to add delay or do this in other job
env:
SONAR_HOST: ${{ secrets.SONARQUBE_HOST }}
SONAR_TOKEN: ${{ secrets.SONARQUBE_TOKEN }}
19 changes: 19 additions & 0 deletions scraper/scripts/code-coverage.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# sleep for 10 seconds
sleep 10

project_key="IfscUT"
threshold=0

#Code flow
CURL_URL=$SONAR_HOST'/api/measures/component_tree?metricKeys=coverage&component='$project_key
curl --location --request GET $CURL_URL -u $SONAR_TOKEN:"" > sonar.json
apk update \
&& apk add jq \
&& rm -rf /var/cache/apk/*
jq -r '.baseComponent.measures[0].value' sonar.json
code_coverage=$( jq -r '.baseComponent.measures[0].value' sonar.json | cut -d "." -f 1)
echo $code_coverage
echo "SONAR Threshold is $threshold"
cat sonar.json
if [ -z "$code_coverage" ] || [ $code_coverage = "null" ]; then echo "Value not found"; exit 1; fi
if [ $code_coverage -lt $threshold ]; then echo "failed - threshold unit code coverage check"; exit 1; else echo "success"; exit 0; fi
14 changes: 14 additions & 0 deletions scraper/scripts/run_checks.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/sh

test_env=$2

if [[ "${test_env}" = "ci" ]]; then
echo "Setting up code"
go env -w GOPRIVATE=github.com/razorpay
apk add --no-cache git gcc xmlsec-dev libxml2 libltdl pkgconfig libc-dev openssl-dev
export CGO_CFLAGS_ALLOW=".*"
git config --global url."https://${GIT_TOKEN}:[email protected]".insteadOf "https://github.com"
go get -u golang.org/x/tools/cmd/goimports
go get -u golang.org/x/lint/golint
cp config/default.toml config/dev-test.toml
fi