diff --git a/.github/workflows/sonar.yaml b/.github/workflows/sonar.yaml new file mode 100644 index 00000000..d889a6e9 --- /dev/null +++ b/.github/workflows/sonar.yaml @@ -0,0 +1,53 @@ +name: sonarcloud-analysis +on: + pull_request: + branches: + - "master" + push: + branches: + - "master" + +permissions: + contents: read + pull-requests: read + +env: + GO_VERSION: '1.22' # Use the version you need + GOLANGCI_LINT_VERSION: v1.59 # Latest version as of my last update + +jobs: + sonarcloud: + name: SonarCloud + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis + + - uses: actions/setup-go@v5 + with: + go-version: ${{ env.GO_VERSION }} + + - name: Install test reporter + run: go install github.com/ctrf-io/go-ctrf-json-reporter/cmd/go-ctrf-json-reporter@latest + + - name: Run Go tests + run: go test -json -coverprofile=coverage.out ./... | go-ctrf-json-reporter -output ctrf-report.json + continue-on-error: true + + - name: Publish Test Summary Results + run: npx github-actions-ctrf ctrf-report.json + + # Re-run golangci separately without exiting on errors and generating a report for use in Sonar + - name: golangci-lint + uses: golangci/golangci-lint-action@v6 + with: + version: ${{ env.GOLANGCI_LINT_VERSION }} + args: --timeout=5m --issues-exit-code=0 --out-format=checkstyle:golangci-lint-report.xml + + - name: SonarCloud Scan + uses: SonarSource/sonarcloud-github-action@master + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} diff --git a/.gitignore b/.gitignore index 8e3f60d3..3edfa4b8 100644 --- a/.gitignore +++ b/.gitignore @@ -33,4 +33,8 @@ Thumbs.db .env.test .env.production +# SonarCloud temporary files +coverage.out +golangci-lint-report.xml + # Ignore any other files or directories specific to your project diff --git a/sonar-project.properties b/sonar-project.properties new file mode 100644 index 00000000..c161b699 --- /dev/null +++ b/sonar-project.properties @@ -0,0 +1,15 @@ +sonar.projectKey=bitcoin-sv_go-sdk +sonar.organization=bitcoin-sv +sonar.projectName=Go SDK +sonar.projectDescription=BSV BLOCKCHAIN | Software Development Kit for Go +sonar.projectVersion=1.0.0 +sonar.sources=. +sonar.sourceEncoding=UTF-8 +sonar.go.coverage.reportPaths=coverage.out +sonar.go.golangci-lint.reportPaths=golangci-lint-report.xml + +sonar.exclusions=**test**,**/docs/**,**vendor** +sonar.coverage.exclusions=docs/** +sonar.tests=. +sonar.test.inclusions=**/*_test.go +sonar.python.version=3.12