Skip to content

Commit

Permalink
change in sonarqube github action
Browse files Browse the repository at this point in the history
  • Loading branch information
nithinputhenveettil committed Dec 26, 2023
1 parent 6d96c43 commit de42f17
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 37 deletions.
51 changes: 51 additions & 0 deletions .github/workflows/coverage_run_and_upload.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Generate code coverage and upload to artifact
on:
workflow_dispatch:
jobs:
build:
name: Run analysis
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Run coverage commands
run: |
#!/bin/bash
TRACER_PATH=$(pwd)
echo $TRACER_PATH
mkdir coverage
echo "Starting Couchbase"
docker-compose -f docker-compose-integration.yaml up -d
echo "Starting Postgres"
sudo systemctl start postgresql.service
sudo -u postgres psql -c "ALTER USER postgres PASSWORD 'mysecretpassword'"
echo "After starting Postgres"
go test -v -coverpkg=./... -cover -covermode atomic -coverprofile $TRACER_PATH/coverage/coverage.out ./... -json > $TRACER_PATH/coverage/coverage.json
LIB_LIST=$(find ./instrumentation -name go.mod -exec dirname {} \;)
for lib in $LIB_LIST
do echo "Generating test coverage for $lib" && cd "$lib" && go mod tidy && go test -v -coverpkg=./... -cover -covermode atomic -coverprofile $TRACER_PATH/coverage/coverage_$(date +%s%N)_$RANDOM.out ./... -json > $TRACER_PATH/coverage/coverage_$(date +%s%N)_$RANDOM.json && cd -;
done
echo "Generating test coverage for ./instrumentation/instagocb"
cd ./instrumentation/instagocb
go mod tidy
go test -v -tags=integration -coverpkg=./... -cover -covermode atomic -coverprofile $TRACER_PATH/coverage/coverage_$(date +%s%N)_$RANDOM.out ./... -json > $TRACER_PATH/coverage/coverage_$(date +%s%N)_$RANDOM.json && cd -
echo "Generating test coverage for ./instrumentation/instapgx"
cd ./instrumentation/instapgx
go mod tidy
go test -v -tags=integration -coverpkg=./... -cover -covermode atomic -coverprofile $TRACER_PATH/coverage/coverage_$(date +%s%N)_$RANDOM.out ./... -json > $TRACER_PATH/coverage/coverage_$(date +%s%N)_$RANDOM.json && cd -
- name: Upload code coverage
uses: actions/upload-artifact@v3
with:
name: go-tracer-code-coverage
path: coverage

61 changes: 26 additions & 35 deletions .github/workflows/sonarqube.yml
Original file line number Diff line number Diff line change
@@ -1,48 +1,39 @@
name: Generate SonarQube report
on:
push:
branches:
- main
pull_request:
types: [opened, synchronize, reopened]
workflow_run:
workflows: [Generate code coverage and upload to artifact]
types: [completed]
jobs:
build:
name: Run analysis
runs-on: ubuntu-latest
if: github.event.workflow_run.conclusion == 'success'
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Run coverage commands
run: |
#!/bin/bash
echo "Starting Couchbase"
docker-compose -f docker-compose-integration.yaml up -d
echo "Starting Postgres"
sudo systemctl start postgresql.service
sudo -u postgres psql -c "ALTER USER postgres PASSWORD 'mysecretpassword'"
echo "After starting Postgres"
go test -v -coverpkg=./... -cover -covermode atomic -coverprofile coverage.out ./... -json > coverage.json
LIB_LIST=$(find ./instrumentation -name go.mod -exec dirname {} \;)
for lib in $LIB_LIST
do echo "Generating test coverage for $lib" && cd "$lib" && go mod tidy && go test -v -coverpkg=./... -cover -covermode atomic -coverprofile coverage.out ./... -json > coverage.json && cd -;
done
echo "Generating test coverage for ./instrumentation/instagocb"
cd ./instrumentation/instagocb
go mod tidy
go test -v -tags=integration -coverpkg=./... -cover -covermode atomic -coverprofile coverage.out ./... -json > coverage.json && cd -
echo "Generating test coverage for ./instrumentation/instapgx"
cd ./instrumentation/instapgx
go mod tidy
go test -v -tags=integration -coverpkg=./... -cover -covermode atomic -coverprofile coverage.out ./... -json > coverage.json && cd -
- name: 'Download code coverage'
uses: actions/github-script@v6
with:
script: |
let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: context.payload.workflow_run.id,
});
let matchArtifact = allArtifacts.data.artifacts.filter((artifact) => {
return artifact.name == "go-tracer-code-coverage"
})[0];
let download = await github.rest.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: matchArtifact.id,
archive_format: 'zip',
});
let fs = require('fs');
fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/go-tracer-code-coverage.zip`, Buffer.from(download.data));
- name: 'Unzip code coverage'
run: unzip go-tracer-code-coverage.zip -d coverage
- name: Sonarqube Scan
uses: sonarsource/sonarqube-scan-action@master

Expand Down
4 changes: 2 additions & 2 deletions sonar-project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ sonar.sources=.
sonar.tests=.
sonar.exclusions=eum.js,internal/bin/sql/sqlgen.go,example/*.go,example/**/*.go,**/example/*.go,**/**/example/*.go
sonar.test.inclusions=**/*_test.go,**/**/*_test.go,instrumentation/**/*_test.go
sonar.go.coverage.reportPaths=coverage.out,instrumentation/**/coverage.out
sonar.go.tests.reportPaths=coverage.json,instrumentation/**/coverage.json
sonar.go.coverage.reportPaths=coverage/coverage*.out
sonar.go.tests.reportPaths=coverage/coverage*.json

0 comments on commit de42f17

Please sign in to comment.