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(ci): enable code coverage on Sonarcloud #1518

Merged
merged 6 commits into from
Sep 11, 2023
Merged

chore(ci): enable code coverage on Sonarcloud #1518

merged 6 commits into from
Sep 11, 2023

Conversation

mmorel-35
Copy link
Contributor

@mmorel-35 mmorel-35 commented Aug 23, 2023

Hi @mdelapenya,
It seems like sonar requires a SONAR_TOKEN secret, I tried to compare with testcontainers-donet and testcontainers-node that reports code coverage on their sonarcloud reports but I couldn’t find anything comparable as they are not using the sonarcloud action to upload their test results.
I tried to provide my own SONAR_TOKEN but it seems it not possible to use it in a fork repository.
Any idea ? Or you prefer to keep things as it is now ?

@netlify
Copy link

netlify bot commented Aug 23, 2023

Deploy Preview for testcontainers-go ready!

Name Link
🔨 Latest commit bcb9795
🔍 Latest deploy log https://app.netlify.com/sites/testcontainers-go/deploys/64ff35c3003cf200089e751b
😎 Deploy Preview https://deploy-preview-1518--testcontainers-go.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@@ -101,6 +101,15 @@ jobs:
run: |
go install gotest.tools/gotestsum@latest
make test-unit

- name: Analyze with SonarCloud
if: ${{ always() && inputs.run-tests && inputs.project-directory == '.' }}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once this is working for the parent go module we can do the same for each submodule.

Comment on lines +5 to +7
sonar.projectKey=testcontainers_testcontainers-go

sonar.projectName=testcontainers-go
Copy link
Contributor Author

@mmorel-35 mmorel-35 Aug 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I imagine that for modulegen, it could be :

sonar.projectKey=testcontainers_testcontainers-go_modulegen
sonar.projectName=testcontainers-go/modulegen

For examples/bigtable it could be :

sonar.projectKey=testcontainers_testcontainers-go_examples_bigtable
sonar.projectName=testcontainers-go/examples/bigtable

@mdelapenya
Copy link
Collaborator

Let me check internally with other maintainers how it's done in their language projects. Will ping you back here once I have it clear how to proceed with Sonarqube, as it'd be a great improvement seeing the code coverage alongside the "defects" it finds (although I dislike a bit how the Go rules are processed).

@mdelapenya
Copy link
Collaborator

I tried to provide my own SONAR_TOKEN but it seems it not possible to use it in a fork repository.
Any idea ?

I'm going to create the secret in the project to make this work.

Copy link
Collaborator

@mdelapenya mdelapenya left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a comment about the used flags. I also added the SONAR_TOKEN secret to the repo, probably won't work until this is PR merged because of forks 🤷

commons-test.mk Outdated Show resolved Hide resolved
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
@mmorel-35 mmorel-35 marked this pull request as ready for review September 11, 2023 12:53
@mmorel-35 mmorel-35 requested a review from a team as a code owner September 11, 2023 12:53
@mdelapenya mdelapenya self-assigned this Sep 11, 2023
@mdelapenya mdelapenya added the chore Changes that do not impact the existing functionality label Sep 11, 2023
@mdelapenya mdelapenya changed the title Sonarcloud chore: enable code coverage on Sonarcloud Sep 11, 2023
@mdelapenya mdelapenya changed the title chore: enable code coverage on Sonarcloud chore(ci): enable code coverage on Sonarcloud Sep 11, 2023
@mmorel-35
Copy link
Contributor Author

There seems to be an option to share secrets with pull request from forks. Have you read this ?

@mdelapenya
Copy link
Collaborator

There seems to be an option to share secrets with pull request from forks. Have you read this ?

I'm not sure if that will work for PRs from forks not from the organisation: https://community.sonarsource.com/t/sonar-token-permissions-in-pull-request-github-actions/90614/9

I'll double check with other maintainers now

@mdelapenya
Copy link
Collaborator

mdelapenya commented Sep 11, 2023

@mmorel-35 it seems that .NET uses it but only for merges to develop or main branches: https://github.com/testcontainers/testcontainers-dotnet/blob/develop/.github/workflows/cicd.yml#L74

I think we should go with the same approach for the moment

@sonarcloud
Copy link

sonarcloud bot commented Sep 11, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@mmorel-35
Copy link
Contributor Author

Hi @mdelapenya ,
It’s now only executed when the owner of the repo is testcontainers and the branch is main.

Copy link
Collaborator

@mdelapenya mdelapenya left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks again for your work here!

@mdelapenya
Copy link
Collaborator

Merging it now

@mdelapenya mdelapenya merged commit 721aed7 into testcontainers:main Sep 11, 2023
90 of 92 checks passed
@mmorel-35 mmorel-35 deleted the sonarcloud branch September 11, 2023 16:03
@mmorel-35
Copy link
Contributor Author

mmorel-35 commented Sep 11, 2023

Hi @mdelapenya ,
The error message says there cannot be an automatic configuration and the sonar action at the same time.
After reading this , it seems better to desactivate automatic analysis and use the github-action.
To my understanding, the desactivation is done on the sonarcloud administration panel.

@mdelapenya
Copy link
Collaborator

I've just disabled the automatic analysis from the service. It's unfortunate that they do not provide a graceful alternative, like not failing that hard 🤷‍♂️

mdelapenya added a commit that referenced this pull request Sep 12, 2023
…containerd-1.7.5

* main:
  chore: always generate the examples including a explicit image (#1611)
  chore: support linting all modules locally (#1609)
  ci(sonarcloud): run only when not root-less (#1608)
  remove extra equal in sonar.organization (#1607)
  chore(ci): enable code coverage on Sonarcloud (#1518)
  docs: use Go testable examples in modules (#1603)
mdelapenya added a commit to mdelapenya/testcontainers-go that referenced this pull request Sep 12, 2023
* main:
  chore: always generate the examples including a explicit image (testcontainers#1611)
  chore: support linting all modules locally (testcontainers#1609)
  ci(sonarcloud): run only when not root-less (testcontainers#1608)
  remove extra equal in sonar.organization (testcontainers#1607)
  chore(ci): enable code coverage on Sonarcloud (testcontainers#1518)
  docs: use Go testable examples in modules (testcontainers#1603)
  ci(lint): enable errorlint linter (testcontainers#1604)
  ci(lint): enable gocritic linter (testcontainers#1605)
  chore(deps): bump github.com/hashicorp/vault-client-go in /modules/vault (testcontainers#1566)
  ci(security): setup codeql scan  (testcontainers#1606)
  chore(deps): bump github.com/cyphar/filepath-securejoin (testcontainers#1601)
  chore: generate Go examples for new modules (testcontainers#1600)
  chore: generate Go examples for new modules (testcontainers#1600)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chore Changes that do not impact the existing functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants