Skip to content

Add optional SonarCloud analysis to generated project template - #97

Merged
dennisdoomen merged 3 commits into
mainfrom
dennisdoomen-add-sonarcloud-support
Oct 28, 2026
Merged

dennisdoomen merged 3 commits into
mainfrom
dennisdoomen-add-sonarcloud-support

Conversation

@dennisdoomen

Copy link
Copy Markdown
Owner

Closes #30

Adds opt-in SonarCloud analysis to the templates/Source/... project template that this repo generates (GitHub Actions variants only — Azure DevOps variants are untouched since SonarCloud on ADO needs a different marketplace-extension-based setup and wasn't requested).

What changed

  • templates/Source/Build/Build.cs: new SonarToken ([Secret]), SonarHostUrl parameters, plus SonarOrganization/SonarProjectKey/UseSonarCloud computed from the GitHub Actions context (no new dotnet new symbols needed). Added SonarBegin/SonarEnd Nuke targets wired into Compile/Pack, both gated with OnlyWhenDynamic(() => UseSonarCloud) so they're skipped entirely when SonarToken isn't set. Coverage is fed into Sonar via ReportGenerator's built-in SonarQube report type (sonar.coverageReportPaths), so no extra Coverlet format juggling was needed.
  • templates/Source/.github/workflows/build.yml: adds an actions/setup-java@v5 step (JRE required by dotnet-sonarscanner), gated on secrets.SONAR_TOKEN != '', and passes SonarToken: ${{ secrets.SONAR_TOKEN }} to the build step.
  • templates/Source/README.md: SonarCloud badge (in the existing badge row) and a bullet explaining how to opt in (create a SonarCloud project, add a SONAR_TOKEN secret).
  • Root README.md: mentions the new optional SonarCloud support in the feature list.

Design

Non-breaking by default — a generated project that never sets up SonarCloud still gets a fully green build, mirroring the existing Coveralls no-op pattern.

Validation

  • Ran this repo's own Nuke build (Compile/Pack targets that Scriban-render all 6 template variants) — succeeded with no templating errors.
  • Manually inspected rendered Normal and NormalAzdo variants: SonarCloud code/YAML appears only in the GitHub Actions (non-azdo) variant; the Azdo variant has zero Sonar references.
  • Compiled the rendered Normal variant's Build.cs directly with dotnet build — 0 errors, 0 warnings.

Wires opt-in SonarCloud support into the templates/Source project template
(GitHub Actions variants only). When a SONAR_TOKEN secret is configured,
the Nuke build runs SonarScannerBegin/End around the existing
build/test/coverage steps and the workflow sets up Java and passes the
token through. Consumers who don't configure SONAR_TOKEN are unaffected
(targets are skipped via OnlyWhenDynamic).

- templates/Source/Build/Build.cs: add SonarToken/SonarOrganization/
  SonarProjectKey/SonarHostUrl/UseSonarCloud, SonarBegin/SonarEnd targets,
  wire into Compile/Pack, feed ReportGenerator's SonarQube coverage format
  into the scanner.
- templates/Source/.github/workflows/build.yml: setup-java + SONAR_TOKEN
  env var.
- templates/Source/README.md: SonarCloud badge + opt-in setup note.
- README.md: mention optional SonarCloud support.

Closes #30

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@dennisdoomen dennisdoomen added the enhancement New feature or request label Sep 26, 2026
@dennisdoomen

Copy link
Copy Markdown
Owner Author

@copilot resolve the merge conflicts in this pull request

Copilot AI and others added 2 commits September 26, 2026 09:31
…rcloud-support

# Conflicts:
#	templates/Source/.github/workflows/build.yml

Co-authored-by: dennisdoomen <572734+dennisdoomen@users.noreply.github.com>
Co-authored-by: dennisdoomen <572734+dennisdoomen@users.noreply.github.com>

Copilot AI commented Sep 26, 2026

Copy link
Copy Markdown
Contributor

@copilot resolve the merge conflicts in this pull request

Resolved in 58144d2; I also applied the follow-up consistency fixes from validation in ea1921a.

@dennisdoomen
dennisdoomen merged commit 2f454d2 into main Oct 28, 2026
1 check passed
@dennisdoomen
dennisdoomen deleted the dennisdoomen-add-sonarcloud-support branch October 28, 2026 13:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for SonarCloud

2 participants