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

Updated sonarqube github action #529

Merged
merged 2 commits into from
Jan 2, 2024
Merged
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
55 changes: 55 additions & 0 deletions .github/workflows/coverage_run_and_upload.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Generate code coverage and upload to artifact
on:
push:
branches:
- main
pull_request:
types: [opened, synchronize, reopened]
jobs:
build:
name: Code Coverage
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