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

chore: sonarcloud pipeline #959

Merged
merged 1 commit into from
Dec 3, 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
60 changes: 60 additions & 0 deletions .github/workflows/coverage_run_and_upload_sonarcloud.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: Generate code coverage and upload to artifact for sonarcloud
on:
push:
branches:
- main
pull_request:
types: [opened, synchronize, reopened]
jobs:
generateCoverage:
name: Code Coverage
runs-on: ubuntu-latest
env:
COSMOS_CONNECTION_URL: ${{ secrets.COSMOS_CONNECTION_URL }}
COSMOS_KEY: ${{ secrets.COSMOS_KEY }}
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

DEPRECATED_PKGS=".*instaamqp$"

LIB_LIST=$(find ./instrumentation -name go.mod -exec dirname {} \; | grep -E -v "$DEPRECATED_PKGS")

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

INTEGRATIONS_TESTS=("instagocb" "instapgx" "instacosmos" "instapgx/v2")

for str in ${INTEGRATIONS_TESTS[@]}; do
dir=./instrumentation/$str
echo "Generating test coverage for $dir"
cd $dir
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 -
done

- name: Upload code coverage
uses: actions/upload-artifact@v3
with:
name: go-tracer-code-coverage-sonarcloud
path: coverage

40 changes: 40 additions & 0 deletions .github/workflows/sonarcloud.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Generate SonarCloud report
on:
workflow_run:
workflows: [Generate code coverage and upload to artifact for sonarcloud]
types: [completed]
jobs:
build:
name: Run sonarcloud analysis
runs-on: ubuntu-latest
if: github.event.workflow_run.conclusion == 'success'
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- 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-sonarcloud"
})[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-sonarcloud.zip`, Buffer.from(download.data));
- name: 'Unzip code coverage'
run: unzip go-tracer-code-coverage-sonarcloud.zip -d coverage
- name: SonarCloud Scan
uses: SonarSource/sonarcloud-github-action@master
env:
SONAR_TOKEN: ${{ secrets.SONAR_CLOUD_TOKEN }}
3 changes: 2 additions & 1 deletion sonar-project.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
sonar.projectKey=go-sensor
sonar.projectKey=instana_go-sensor
sonar.organization=instana
sonar.projectName=Go Tracer
sonar.links.scm=https://github.com/instana/go-sensor
sonar.links.ci=https://app.circleci.com/pipelines/github/instana/go-sensor
Expand Down