Make Sonar analysis step optional to support fork CI #56
Labels
No labels
bug
dependencies
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
openrn/react-native-logging-tools#56
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Checklist
has not been requested before
exist
Feature Description
Make the Sonar analysis step in the CI pipeline optional by reading sensitive
configuration from environment variables and skipping the step entirely when
those variables are absent.
Problem Statement
The CI pipeline currently fails for forks because:
sonar-project.propertieshardcodes several values tied to the upstreamrepository:
sonar.host.url(a private SonarQube instance unreachable fromforks),
sonar.projectKey, andsonar.projectName.SONAR_TOKENsecret is only available in the upstream repository.As a result, any contributor who forks the project and opens a PR from their
fork will have the
sonarCI job fail, even though their code changes areperfectly valid.
Proposed Solution
Move the following properties out of
sonar-project.propertiesand into CIenvironment variables (passed via repository secrets):
sonar.host.urlSONAR_HOST_URLsonar.projectKeySONAR_PROJECT_KEYsonar.projectNameSONAR_PROJECT_NAMEAdd a skip condition (
if: ${{ secrets.SONAR_TOKEN != '' }}) to thesonarjobin all four workflow files. The step should be skipped (not failed) when
the variable is absent, so fork CI passes cleanly.
Expected behavior
SONAR_TOKENpresentUse Case
A contributor forks the repository, makes a change, and opens a PR from their
fork. Today the
sonarjob blocks their CI with an authentication/connectionerror. After this change, the job is skipped and the PR shows a green pipeline.
Alternatives Considered
to configure their own org/project, so the skip logic would still be needed.
experience for contributors with no explanation.
Implementation Ideas
All four workflows need the same changes to their
sonarjob: add theifcondition and inject the new env vars. Each workflow has a slightly different
sonar-scannerinvocation:.forgejo/workflows/pr.yaml.forgejo/workflows/master.yamland.forgejo/workflows/dev.yaml.forgejo/workflows/tag.yamlSame env vars as above; the
sonar-scannerinvocation is also branch-based(
-Dsonar.branch.name=$GITHUB_REF_NAME). Note: intag.yamlthepublishjobdepends on
sonar(needs: sonar) — this dependency must be kept or adjustedso that publish is not blocked when sonar is skipped.
sonar-project.properties— remove hardcoded values:Additional Context
Affected files:
.forgejo/workflows/pr.yaml.forgejo/workflows/master.yaml.forgejo/workflows/dev.yaml.forgejo/workflows/tag.yamlsonar-project.propertiesCONTRIBUTING.md(document the required secrets and how to enable Sonar on a fork)Documentation to add in
CONTRIBUTING.md:A new section explaining how to enable Sonar analysis on a forked repository:
SONAR_TOKEN— authentication token for the SonarQube instanceSONAR_HOST_URL— URL of the SonarQube instance (e.g.https://sonarcloud.io)SONAR_PROJECT_KEY— project key as defined in SonarQubeSONAR_PROJECT_NAME— project name as defined in SonarQubeSONAR_TOKENis present.