Skip to content

fix: resolve SonarCloud issues in build, new-cli, and CI workflows#4989

Merged
arturcic merged 10 commits into
GitTools:mainfrom
arturcic:fix/sonar-fixes
Jun 29, 2026
Merged

fix: resolve SonarCloud issues in build, new-cli, and CI workflows#4989
arturcic merged 10 commits into
GitTools:mainfrom
arturcic:fix/sonar-fixes

Conversation

@arturcic

Copy link
Copy Markdown
Member

Resolves a batch of SonarCloud findings across the build, new-cli, and CI (.github) areas. Code fixes here; false-positives / won't-fix dispositions were applied on SonarCloud directly.

Code fixes

.github (CI security)

  • S7630 (×10, BLOCKER) – prevent script injection in the docker-publish / docker-manifests composite actions by passing inputs.* (dotnet_version, docker_distro, arch) via env: and referencing $env:VAR in the pwsh run: steps instead of interpolating ${{ inputs.* }} into the shell.
  • S8233 (×3) – scope GITHUB_TOKEN to least privilege: workflow-level dropped to contents: read; write scopes granted only on the jobs that need them (unit_testid-token; docker_*packages; publishid-token+packages), matching each reusable workflow's own declarations. release already declared its own.
  • S6573 (×1) – quote the **/AddFormats/ glob in format.yml.

build

  • S1118 ×4static utility classes (Arguments/Paths/Tools); protected ctor for the subclassed EnvVars.
  • S2325LogBuildInformation made static.
  • S112 ×5InvalidOperationException instead of bare Exception (UnitTest, NuGet publish flow).
  • S6570 – quote $VERSION in the Dockerfile.
  • S1125 / S2589 / S3887 ×2 / S2386 – misc maintainability (redundant boolean, redundant null-conditional, IReadOnlyDictionary for public collections).
  • S3776 – reduced GitVersionRunner.GetArguments cognitive complexity via extracted helpers.
  • S8642 / S8637build.ps1: lowercase param; renamed reserved $WhatIf$DryRun (kept WhatIf/Noop aliases, so the CLI is unchanged).

new-cli

  • S927 ×2 – param names matched to base/interface (propertyFactory, symbol).
  • S2629 ×9 – interpolated log messages → structured message templates.
  • S6678 – PascalCase log placeholders.
  • S1125== trueis true.
  • S3878 – pass single alias directly instead of an array literal.

Verification

  • dotnet build of src/new-cli/build solutions: 0 errors / 0 warnings.
  • dotnet format --verify-no-changes clean.
  • All changed GitHub Actions YAML validated as parseable.

⚠️ S8233 (reusable-workflow permission scoping) can only be fully verified by an actual publish/release CI run — if any publish step hits a permissions error, add the missing scope to that specific job.

🤖 Generated with Claude Code

arturcic and others added 10 commits June 28, 2026 23:10
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
- S1118: make Arguments/Paths/Tools static utility classes; add protected
  ctor to EnvVars (it is subclassed, so it cannot be static)
- S2325: make BuildLifetimeBase.LogBuildInformation static
- S112: throw NotSupportedException instead of bare Exception (UnitTest)
- S6570: quote $VERSION in Dockerfile 'dotnet tool install'

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
- S8642: lowercase 'param' keyword
- S8637: rename reserved parameter $WhatIf -> $DryRun, keeping WhatIf as an
  alias so the '-WhatIf' CLI flag (and -Noop/-DryRun) still work unchanged

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
- S1125: simplify 'ForcePublish is false' to '!ForcePublish' (PublishDocs)
- S2589: drop redundant null-conditional on entryAssembly (Default; non-null
  past the tasks guard) using null-forgiving access
- S3887/S2386: expose Tools.Versions as IReadOnlyDictionary
- S3887: expose BuildContext.NativeRuntimes as IReadOnlyDictionary

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Extract argument-building groups into focused helpers (output, auth,
assembly-info, repository, verbosity) and use guard clauses to flatten
nesting. Stateless helpers are static. Behavior is unchanged.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
The NuGet OIDC publish flow threw bare System.Exception on token/API-key
failures; use InvalidOperationException for the failure paths.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
- S927: rename params to match base/interface (propFactory->propertyFactory
  in LoggingEnricher; type->symbol in TypeVisitor.VisitNamedType)
- S6678: PascalCase log placeholders {logFile}/{workDir} -> {LogFile}/{WorkDir}
- S1125: '.Any() == true' -> '.Any() is true' (CommandBaseGenerator)
- S3878: pass single alias directly (params) instead of array literal

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…(S2629)

Convert interpolated $"..." log messages to structured message templates
with PascalCase named placeholders across the config/normalize/output
commands (9 occurrences).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
- S7630 (BLOCKER): avoid script injection by passing inputs (dotnet_version,
  docker_distro, arch) via env: and referencing $env:VAR in pwsh run steps,
  instead of interpolating ${{ inputs.* }} directly into the shell
- S6573: quote the '**/AddFormats/' glob in the format workflow

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Reduce workflow-level permissions to 'contents: read' and grant write
scopes only on the jobs that need them, matching what each reusable
workflow already declares:
- unit_test: id-token: write (coverage OIDC)
- docker_linux_images / docker_linux_manifests: packages: write
- publish: id-token + packages: write
- release already declares its own job-level permissions

Read-only jobs (prepare, build, artifacts tests) no longer receive
package/id-token/attestation write, shrinking the supply-chain blast radius.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@arturcic arturcic merged commit 0a4a0f8 into GitTools:main Jun 29, 2026
120 checks passed
@arturcic arturcic deleted the fix/sonar-fixes branch June 29, 2026 08:25
@mergify

mergify Bot commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Thank you @arturcic for your contribution!

@sonarqubecloud

Copy link
Copy Markdown

@arturcic arturcic added this to the 6.x milestone Jun 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant