Skip to content

Commit 0a4a0f8

Browse files
authored
Merge pull request #4989 from arturcic/fix/sonar-fixes
fix: resolve SonarCloud issues in build, new-cli, and CI workflows
2 parents 52e3f59 + 1a8ec11 commit 0a4a0f8

31 files changed

Lines changed: 157 additions & 95 deletions

File tree

.codegraph/.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# CodeGraph data files — local to each machine, not for committing.
2+
# Ignore everything in .codegraph/ except this file itself, so transient
3+
# files (the database, daemon.pid, sockets, logs) never show up in git.
4+
*
5+
!.gitignore

.github/actions/docker-manifests/action.yml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,13 @@ runs:
3131

3232
- name: '[Docker Publish Manifests] DockerHub'
3333
shell: pwsh
34+
env:
35+
DOTNET_VERSION: ${{ inputs.dotnet_version }}
36+
DOCKER_DISTRO: ${{ inputs.docker_distro }}
3437
run: |
3538
dotnet run/docker.dll `
36-
--target=DockerManifest --arch=amd64 --arch=arm64 --dotnet_version=${{ inputs.dotnet_version }} `
37-
--docker_distro=${{ inputs.docker_distro }} --docker_registry dockerhub
39+
--target=DockerManifest --arch=amd64 --arch=arm64 --dotnet_version=$env:DOTNET_VERSION `
40+
--docker_distro=$env:DOCKER_DISTRO --docker_registry dockerhub
3841
3942
- name: Login to GitHub
4043
uses: docker/login-action@v4
@@ -45,7 +48,10 @@ runs:
4548

4649
- name: '[Docker Publish Manifests] GitHub'
4750
shell: pwsh
51+
env:
52+
DOTNET_VERSION: ${{ inputs.dotnet_version }}
53+
DOCKER_DISTRO: ${{ inputs.docker_distro }}
4854
run: |
4955
dotnet run/docker.dll `
50-
--target=DockerManifest --arch=amd64 --arch=arm64 --dotnet_version=${{ inputs.dotnet_version }} `
51-
--docker_distro=${{ inputs.docker_distro }} --docker_registry github
56+
--target=DockerManifest --arch=amd64 --arch=arm64 --dotnet_version=$env:DOTNET_VERSION `
57+
--docker_distro=$env:DOCKER_DISTRO --docker_registry github

.github/actions/docker-publish/action.yml

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,14 @@ runs:
3434

3535
- name: '[Docker Publish] DockerHub'
3636
shell: pwsh
37+
env:
38+
ARCH: ${{ inputs.arch }}
39+
DOTNET_VERSION: ${{ inputs.dotnet_version }}
40+
DOCKER_DISTRO: ${{ inputs.docker_distro }}
3741
run: |
3842
dotnet run/docker.dll `
39-
--target=DockerPublish --arch=${{ inputs.arch }} --dotnet_version=${{ inputs.dotnet_version }} `
40-
--docker_distro=${{ inputs.docker_distro }} --docker_registry dockerhub --verbosity=diagnostic
43+
--target=DockerPublish --arch=$env:ARCH --dotnet_version=$env:DOTNET_VERSION `
44+
--docker_distro=$env:DOCKER_DISTRO --docker_registry dockerhub --verbosity=diagnostic
4145
4246
- name: Login to GitHub
4347
uses: docker/login-action@v4
@@ -48,7 +52,11 @@ runs:
4852

4953
- name: '[Docker Publish] GitHub'
5054
shell: pwsh
55+
env:
56+
ARCH: ${{ inputs.arch }}
57+
DOTNET_VERSION: ${{ inputs.dotnet_version }}
58+
DOCKER_DISTRO: ${{ inputs.docker_distro }}
5159
run: |
5260
dotnet run/docker.dll `
53-
--target=DockerPublish --arch=${{ inputs.arch }} --dotnet_version=${{ inputs.dotnet_version }} `
54-
--docker_distro=${{ inputs.docker_distro }} --docker_registry github --verbosity=diagnostic
61+
--target=DockerPublish --arch=$env:ARCH --dotnet_version=$env:DOTNET_VERSION `
62+
--docker_distro=$env:DOCKER_DISTRO --docker_registry github --verbosity=diagnostic

.github/workflows/ci.yml

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,7 @@ env:
3737
ENABLED_DIAGNOSTICS: ${{ vars.ENABLED_DIAGNOSTICS }}
3838

3939
permissions:
40-
id-token: write
4140
contents: read
42-
packages: write
43-
attestations: write
4441

4542
jobs:
4643
prepare:
@@ -66,6 +63,9 @@ jobs:
6663
unit_test:
6764
name: Test
6865
needs: [ prepare, publish_flags ]
66+
permissions:
67+
contents: read
68+
id-token: write
6969
uses: ./.github/workflows/_unit_tests.yml
7070
with:
7171
dotnet_versions: ${{ needs.prepare.outputs.dotnet_versions }}
@@ -98,6 +98,9 @@ jobs:
9898
docker_linux_images:
9999
needs: [ prepare, build, publish_flags ]
100100
name: Docker Images (${{ matrix.arch }})
101+
permissions:
102+
contents: read
103+
packages: write
101104
strategy:
102105
fail-fast: false
103106
matrix:
@@ -119,6 +122,9 @@ jobs:
119122
docker_linux_manifests:
120123
needs: [ prepare, docker_linux_images, publish_flags ]
121124
name: Docker Manifests
125+
permissions:
126+
contents: read
127+
packages: write
122128
uses: ./.github/workflows/_docker_manifests.yml
123129
with:
124130
docker_distros: ${{ needs.prepare.outputs.docker_distros }}
@@ -129,6 +135,10 @@ jobs:
129135
publish:
130136
name: Publish
131137
needs: [ artifacts_windows_test, artifacts_linux_test, publish_flags ]
138+
permissions:
139+
contents: read
140+
id-token: write
141+
packages: write
132142
uses: ./.github/workflows/_publish.yml
133143
with:
134144
publish_packages: ${{ fromJson(needs.publish_flags.outputs.can_publish) }}

.github/workflows/format.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,4 @@ jobs:
5151
run: dotnet format ./build/ --verify-no-changes
5252

5353
- name: Run Format 'GitVersion' solution
54-
run: dotnet format ./src/ --exclude **/AddFormats/ --verify-no-changes
54+
run: dotnet format ./src/ --exclude "**/AddFormats/" --verify-no-changes

build.ps1

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,21 @@ The build stage to execute.
66
The build script target to run.
77
.PARAMETER Verbosity
88
Specifies the amount of information to be displayed.
9-
.PARAMETER WhatIf
9+
.PARAMETER DryRun
1010
Performs a dry run of the build script.
1111
No tasks will be executed.
1212
.PARAMETER ScriptArgs
1313
Remaining arguments are added here.
1414
#>
1515

1616
[CmdletBinding()]
17-
Param(
17+
param(
1818
[ValidateSet("artifacts", "build", "docker", "docs", "publish", "release")]
1919
[string]$Stage = "build",
2020
[string]$Target = "Default",
2121
[string]$Verbosity = "Normal",
22-
[Alias("DryRun","Noop")]
23-
[switch]$WhatIf,
22+
[Alias("WhatIf","Noop")]
23+
[switch]$DryRun,
2424
[switch]$Exclusive,
2525
[Parameter(Position=0,Mandatory=$false,ValueFromRemainingArguments=$true)]
2626
[string[]]$ScriptArgs
@@ -39,7 +39,7 @@ $env:DOTNET_NOLOGO=$true
3939
$Arguments = @{
4040
target=$Target;
4141
verbosity=$Verbosity;
42-
dryrun=$WhatIf;
42+
dryrun=$DryRun;
4343
exclusive=$Exclusive;
4444
nuget_useinprocessclient=$true;
4545
}.GetEnumerator() | ForEach-Object {

build/build/BuildContext.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ public class BuildContext(ICakeContext context) : BuildContextBase(context)
77
{
88
public string MsBuildConfiguration { get; set; } = Constants.DefaultConfiguration;
99

10-
public readonly Dictionary<PlatformFamily, string[]> NativeRuntimes = new()
10+
public readonly IReadOnlyDictionary<PlatformFamily, string[]> NativeRuntimes = new Dictionary<PlatformFamily, string[]>()
1111
{
1212
[PlatformFamily.Windows] = ["win-x64", "win-arm64"],
1313
[PlatformFamily.Linux] = ["linux-x64", "linux-musl-x64", "linux-arm64", "linux-musl-arm64"],

build/build/Tasks/Test/UnitTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public override void Run(BuildContext context)
2424
}
2525
if (!frameworks.Contains(dotnetVersion, StringComparer.OrdinalIgnoreCase))
2626
{
27-
throw new Exception($"Dotnet Target {dotnetVersion} is not supported at the moment");
27+
throw new NotSupportedException($"Dotnet Target {dotnetVersion} is not supported at the moment");
2828
}
2929
frameworks = [dotnetVersion];
3030
}

build/common/Addins/GitVersion/GitVersionRunner.cs

Lines changed: 78 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,36 @@ private ProcessArgumentBuilder GetArguments(GitVersionSettings settings)
6262
{
6363
var builder = new ProcessArgumentBuilder();
6464

65+
AppendOutputArguments(builder, settings);
66+
67+
if (!string.IsNullOrWhiteSpace(settings.ShowVariable))
68+
{
69+
builder.Append("-showvariable");
70+
builder.Append(settings.ShowVariable);
71+
}
72+
73+
AppendAuthenticationArguments(builder, settings);
74+
AppendAssemblyInfoArguments(builder, settings);
75+
AppendRepositoryArguments(builder, settings);
76+
77+
if (settings.LogFilePath != null)
78+
{
79+
builder.Append("-l");
80+
builder.AppendQuoted(settings.LogFilePath.FullPath);
81+
}
82+
83+
if (settings.NoFetch)
84+
{
85+
builder.Append("-nofetch");
86+
}
87+
88+
AppendVerbosityArguments(builder, settings);
89+
90+
return builder;
91+
}
92+
93+
private static void AppendOutputArguments(ProcessArgumentBuilder builder, GitVersionSettings settings)
94+
{
6595
if (settings.OutputTypes.Contains(GitVersionOutput.Json))
6696
{
6797
builder.Append("-output");
@@ -73,86 +103,87 @@ private ProcessArgumentBuilder GetArguments(GitVersionSettings settings)
73103
builder.Append("-output");
74104
builder.Append("buildserver");
75105
}
106+
}
76107

77-
if (!string.IsNullOrWhiteSpace(settings.ShowVariable))
108+
private static void AppendAuthenticationArguments(ProcessArgumentBuilder builder, GitVersionSettings settings)
109+
{
110+
if (string.IsNullOrWhiteSpace(settings.UserName))
78111
{
79-
builder.Append("-showvariable");
80-
builder.Append(settings.ShowVariable);
112+
return;
81113
}
82114

83-
if (!string.IsNullOrWhiteSpace(settings.UserName))
84-
{
85-
builder.Append("-u");
86-
builder.AppendQuoted(settings.UserName);
115+
builder.Append("-u");
116+
builder.AppendQuoted(settings.UserName);
87117

88-
builder.Append("-p");
89-
builder.AppendQuotedSecret(settings.Password);
90-
}
118+
builder.Append("-p");
119+
builder.AppendQuotedSecret(settings.Password);
120+
}
91121

92-
if (settings.UpdateAssemblyInfo)
122+
private static void AppendAssemblyInfoArguments(ProcessArgumentBuilder builder, GitVersionSettings settings)
123+
{
124+
if (!settings.UpdateAssemblyInfo)
93125
{
94-
builder.Append("-updateassemblyinfo");
126+
return;
127+
}
95128

96-
if (settings.UpdateAssemblyInfoFilePath != null)
97-
{
98-
builder.AppendQuoted(settings.UpdateAssemblyInfoFilePath.FullPath);
99-
}
129+
builder.Append("-updateassemblyinfo");
130+
131+
if (settings.UpdateAssemblyInfoFilePath != null)
132+
{
133+
builder.AppendQuoted(settings.UpdateAssemblyInfoFilePath.FullPath);
100134
}
135+
}
101136

137+
private void AppendRepositoryArguments(ProcessArgumentBuilder builder, GitVersionSettings settings)
138+
{
102139
if (settings.RepositoryPath != null)
103140
{
104141
builder.Append("-targetpath");
105142
builder.AppendQuoted(settings.RepositoryPath.FullPath);
143+
return;
106144
}
107-
else if (!string.IsNullOrWhiteSpace(settings.Url))
145+
146+
if (string.IsNullOrWhiteSpace(settings.Url))
108147
{
109-
builder.Append("-url");
110-
builder.AppendQuoted(settings.Url);
148+
return;
149+
}
111150

112-
if (!string.IsNullOrWhiteSpace(settings.Branch))
113-
{
114-
builder.Append("-b");
115-
builder.Append(settings.Branch);
116-
}
117-
else
118-
{
119-
this._log.Warning(
120-
"If you leave the branch name for GitVersion unset, it will fallback to the default branch for the repository.");
121-
}
151+
builder.Append("-url");
152+
builder.AppendQuoted(settings.Url);
122153

123-
if (!string.IsNullOrWhiteSpace(settings.Commit))
124-
{
125-
builder.Append("-c");
126-
builder.AppendQuoted(settings.Commit);
127-
}
128-
129-
if (settings.DynamicRepositoryPath != null)
130-
{
131-
builder.Append("-dynamicRepoLocation");
132-
builder.AppendQuoted(settings.DynamicRepositoryPath.FullPath);
133-
}
154+
if (!string.IsNullOrWhiteSpace(settings.Branch))
155+
{
156+
builder.Append("-b");
157+
builder.Append(settings.Branch);
158+
}
159+
else
160+
{
161+
this._log.Warning(
162+
"If you leave the branch name for GitVersion unset, it will fallback to the default branch for the repository.");
134163
}
135164

136-
if (settings.LogFilePath != null)
165+
if (!string.IsNullOrWhiteSpace(settings.Commit))
137166
{
138-
builder.Append("-l");
139-
builder.AppendQuoted(settings.LogFilePath.FullPath);
167+
builder.Append("-c");
168+
builder.AppendQuoted(settings.Commit);
140169
}
141170

142-
if (settings.NoFetch)
171+
if (settings.DynamicRepositoryPath != null)
143172
{
144-
builder.Append("-nofetch");
173+
builder.Append("-dynamicRepoLocation");
174+
builder.AppendQuoted(settings.DynamicRepositoryPath.FullPath);
145175
}
176+
}
146177

178+
private void AppendVerbosityArguments(ProcessArgumentBuilder builder, GitVersionSettings settings)
179+
{
147180
var verbosity = settings.Verbosity ?? this._log.Verbosity;
148181

149182
if (verbosity != Verbosity.Normal)
150183
{
151184
builder.Append("-verbosity");
152185
builder.Append(verbosity.ToString());
153186
}
154-
155-
return builder;
156187
}
157188

158189
/// <summary>

build/common/Lifetime/BuildLifetimeBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public override void Teardown(T context, ITeardownContext info)
7474
}
7575
context.EndGroup();
7676
}
77-
protected void LogBuildInformation(T context)
77+
protected static void LogBuildInformation(T context)
7878
{
7979
if (context.HasArgument(Arguments.Target))
8080
{

0 commit comments

Comments
 (0)