Skip to content

Commit 4eb7329

Browse files
bart-vmwareTimHess
andauthored
Update to .NET 10, adapt code style to Steeltoe conventions (#22)
* Convert to slnx * Remove dependency on Steeltoe 3.x * Update to .NET 10, run tests during Docker build * Use file-scoped namespaces * Additional code cleanup * Apply style settings from Steeltoe * Enable nullable reference types * Use top-level statements, replace Swashbuckle with ASP.NET OpenAPI * Docker tweaks * Do not auto-redirect to https * Delete CODEOWNERS * Only enable health actuator for non-development * Disable install/uninstall endpoints by default * Fixed: always use forward slashes in paths inside zip * Fixed: do not wrap into multiple exceptions * Restore original log level * Fix broken error handling * Strip paths from output * Remove UseAuthorization * Move setting DOTNET_ENVIRONMENT in Docker, remove unused settings * Add code style verification * Remove Nerdbank.GitVersioning * Set up vulnerability scans * Apply suggestions from code review Co-authored-by: Tim Hess <tim.hess@broadcom.com> --------- Co-authored-by: Tim Hess <tim.hess@broadcom.com>
1 parent 333c281 commit 4eb7329

51 files changed

Lines changed: 3883 additions & 1425 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.config/dotnet-tools.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"version": 1,
3+
"isRoot": true,
4+
"tools": {
5+
"jetbrains.resharper.globaltools": {
6+
"version": "2026.1.3",
7+
"commands": [
8+
"jb"
9+
],
10+
"rollForward": false
11+
},
12+
"regitlint": {
13+
"version": "6.3.13",
14+
"commands": [
15+
"regitlint"
16+
],
17+
"rollForward": false
18+
}
19+
}
20+
}

.dockerignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
Dockerfile
22
docker-compose.yaml
3-
azure-pipelines.yaml
43
*.sln.DotSettings.user
54
deploy/
65
*/*/bin/

.editorconfig

Lines changed: 151 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,164 @@
1+
# EditorConfig is awesome: http://EditorConfig.org
2+
3+
# top-most EditorConfig file
14
root = true
25

36
[*]
47
indent_style = space
8+
indent_size = 4
9+
tab-width = 4
10+
charset = utf-8
511
trim_trailing_whitespace = true
612
insert_final_newline = true
7-
max_line_length = 120
8-
charset = utf-8
913

10-
[*.{csproj,props,targets,DotSettings}]
14+
[*.sh]
15+
end_of_line = lf
16+
17+
[*.{build,config,csproj,js,json,proj,props,targets,xml,ruleset,xsd,yml,yaml}]
1118
indent_size = 2
19+
tab-width = 2
20+
max_line_length = 160
1221

13-
[*.cs]
14-
indent_size = 4
22+
[*.{cs,cshtml,ascx,aspx}]
1523

16-
[*.yaml]
17-
indent_size = 2
24+
#### C#/.NET Code Style ####
1825

19-
[*.ps1]
20-
indent_size = 4
26+
# Default severity for IDE* analyzers with category 'Style'
27+
# Note: specific rules below use severity silent, because Resharper code cleanup auto-fixes them.
28+
dotnet_analyzer_diagnostic.category-Style.severity = warning
2129

22-
[*.json]
23-
indent_size = 2
30+
# 'using' directive preferences
31+
dotnet_sort_system_directives_first = true
32+
csharp_using_directive_placement = outside_namespace:silent
33+
# IDE0005: Remove unnecessary import
34+
dotnet_diagnostic.IDE0005.severity = silent
35+
36+
# Namespace declarations
37+
csharp_style_namespace_declarations = file_scoped:silent
38+
# IDE0160: Use block-scoped namespace
39+
dotnet_diagnostic.IDE0160.severity = silent
40+
# IDE0161: Use file-scoped namespace
41+
dotnet_diagnostic.IDE0161.severity = silent
42+
43+
# this. preferences
44+
dotnet_style_qualification_for_field = false:silent
45+
dotnet_style_qualification_for_property = false:silent
46+
dotnet_style_qualification_for_method = false:silent
47+
dotnet_style_qualification_for_event = false:silent
48+
# IDE0003: Remove this or Me qualification
49+
dotnet_diagnostic.IDE0003.severity = silent
50+
# IDE0009: Add this or Me qualification
51+
dotnet_diagnostic.IDE0009.severity = silent
52+
53+
# Language keywords vs BCL types preferences
54+
dotnet_style_predefined_type_for_locals_parameters_members = true:silent
55+
dotnet_style_predefined_type_for_member_access = true:silent
56+
# IDE0049: Use language keywords instead of framework type names for type references
57+
dotnet_diagnostic.IDE0049.severity = silent
58+
59+
# Modifier preferences
60+
dotnet_style_require_accessibility_modifiers = for_non_interface_members:silent
61+
# IDE0040: Add accessibility modifiers
62+
dotnet_diagnostic.IDE0040.severity = silent
63+
csharp_preferred_modifier_order = public, private, protected, internal, new, static, abstract, virtual, sealed, readonly, override, extern, unsafe, volatile, async:silent
64+
# IDE0036: Order modifiers
65+
dotnet_diagnostic.IDE0036.severity = silent
66+
67+
# Expression-level preferences
68+
dotnet_style_operator_placement_when_wrapping = end_of_line
69+
dotnet_style_prefer_auto_properties = true:silent
70+
# IDE0032: Use auto property
71+
dotnet_diagnostic.IDE0032.severity = silent
72+
dotnet_style_prefer_conditional_expression_over_assignment = true:silent
73+
# IDE0045: Use conditional expression for assignment
74+
dotnet_diagnostic.IDE0045.severity = silent
75+
dotnet_style_prefer_conditional_expression_over_return = true:silent
76+
# IDE0046: Use conditional expression for return
77+
dotnet_diagnostic.IDE0046.severity = silent
78+
csharp_style_unused_value_expression_statement_preference = discard_variable:silent
79+
# IDE0058: Remove unused expression value
80+
dotnet_diagnostic.IDE0058.severity = silent
81+
82+
# Collection expression preferences (note: turned off in shared-package.props)
83+
dotnet_style_prefer_collection_expression = when_types_exactly_match
84+
dotnet_diagnostic.IDE0306.severity = silent # Workaround for https://github.com/dotnet/roslyn/issues/77177
85+
86+
# Parameter preferences
87+
dotnet_code_quality_unused_parameters = non_public
88+
89+
# Local functions vs lambdas
90+
csharp_style_prefer_local_over_anonymous_function = false:silent
91+
# IDE0039: Use local function instead of lambda
92+
dotnet_diagnostic.IDE0039.severity = silent
93+
94+
# Expression-bodied members
95+
csharp_style_expression_bodied_accessors = true:silent
96+
# IDE0027: Use expression body for accessors
97+
dotnet_diagnostic.IDE0027.severity = silent
98+
csharp_style_expression_bodied_constructors = false:silent
99+
# IDE0021: Use expression body for constructors
100+
dotnet_diagnostic.IDE0021.severity = silent
101+
csharp_style_expression_bodied_indexers = true:silent
102+
# IDE0026: Use expression body for indexers
103+
dotnet_diagnostic.IDE0026.severity = silent
104+
csharp_style_expression_bodied_lambdas = true:silent
105+
# IDE0053: Use expression body for lambdas
106+
dotnet_diagnostic.IDE0053.severity = silent
107+
csharp_style_expression_bodied_local_functions = false:silent
108+
# IDE0061: Use expression body for local functions
109+
dotnet_diagnostic.IDE0061.severity = silent
110+
csharp_style_expression_bodied_methods = false:silent
111+
# IDE0022: Use expression body for methods
112+
dotnet_diagnostic.IDE0022.severity = silent
113+
csharp_style_expression_bodied_operators = false:silent
114+
# IDE0023: Use expression body for conversion operators
115+
dotnet_diagnostic.IDE0023.severity = silent
116+
# IDE0024: Use expression body for operators
117+
dotnet_diagnostic.IDE0024.severity = silent
118+
csharp_style_expression_bodied_properties = true:silent
119+
# IDE0025: Use expression body for properties
120+
dotnet_diagnostic.IDE0025.severity = silent
121+
122+
# Code-block preferences
123+
csharp_prefer_braces = true:silent
124+
# IDE0011: Add braces
125+
dotnet_diagnostic.IDE0011.severity = silent
126+
127+
# Indentation preferences
128+
csharp_indent_case_contents_when_block = false
129+
130+
# Wrapping preferences
131+
csharp_preserve_single_line_statements = false
132+
133+
# 'var' usage preferences
134+
csharp_style_var_for_built_in_types = false:silent
135+
csharp_style_var_when_type_is_apparent = true:silent
136+
csharp_style_var_elsewhere = false:silent
137+
# IDE0007: Use var instead of explicit type
138+
dotnet_diagnostic.IDE0007.severity = silent
139+
# IDE0008: Use explicit type instead of var
140+
dotnet_diagnostic.IDE0008.severity = silent
141+
142+
# Parentheses preferences
143+
dotnet_style_parentheses_in_arithmetic_binary_operators = never_if_unnecessary:silent
144+
dotnet_style_parentheses_in_other_binary_operators = always_for_clarity:silent
145+
dotnet_style_parentheses_in_relational_binary_operators = never_if_unnecessary:silent
146+
# IDE0047: Remove unnecessary parentheses
147+
dotnet_diagnostic.IDE0047.severity = silent
148+
# IDE0048: Add parentheses for clarity
149+
dotnet_diagnostic.IDE0048.severity = silent
150+
151+
# IDE0010: Add missing cases to switch statement
152+
dotnet_diagnostic.IDE0010.severity = silent
153+
# IDE0072: Add missing cases to switch expression
154+
dotnet_diagnostic.IDE0072.severity = silent
155+
156+
# IDE0029: Null check can be simplified
157+
dotnet_diagnostic.IDE0029.severity = silent
158+
# IDE0030: Null check can be simplified
159+
dotnet_diagnostic.IDE0030.severity = silent
160+
# IDE0270: Null check can be simplified
161+
dotnet_diagnostic.IDE0270.severity = silent
24162

25-
[Dockerfile,*.sh]
26-
end_of_line = lf
163+
# JSON002: Probable JSON string detected
164+
dotnet_diagnostic.JSON002.severity = silent

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Enable running shell scripts from Docker on Windows
2+
*.sh eol=lf

.gitconfig

Lines changed: 0 additions & 2 deletions
This file was deleted.

.github/CODEOWNERS

Lines changed: 0 additions & 1 deletion
This file was deleted.

.github/workflows/build-and-stage.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,10 @@ jobs:
2424
name: Build and push image
2525
runs-on: ubuntu-latest
2626
steps:
27-
- uses: actions/checkout@v6
28-
with:
29-
fetch-depth: 0 # avoid shallow clone so nbgv can do its work.
27+
- name: Git checkout
28+
uses: actions/checkout@v6
29+
with:
30+
persist-credentials: false
3031

3132
- name: Detect template source from PR body
3233
env:
@@ -90,7 +91,7 @@ jobs:
9091
uses: mshick/add-pr-comment@v3
9192
with:
9293
message: |
93-
## Preview link: https://${{ vars.AZURE_WEBAPP_NAME }}-${{ env.SLOT_NAME }}.azurewebsites.net
94+
## Preview link: https://${{ vars.AZURE_WEBAPP_NAME }}-${{ env.SLOT_NAME }}.azurewebsites.net/api/new
9495
9596
- Your changes have been deployed to the preview site. The preview site will update as you add more commits to this branch.
9697
- The preview link is shareable, but will be deleted when the pull request is merged or closed.
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
name: Scan vulnerable dependencies
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches:
7+
- main
8+
pull_request:
9+
10+
concurrency:
11+
group: ${{ github.workflow }}-${{ github.ref }}
12+
cancel-in-progress: true
13+
14+
permissions:
15+
contents: read
16+
17+
env:
18+
DOTNET_CLI_TELEMETRY_OPTOUT: 1
19+
DOTNET_NOLOGO: true
20+
SOLUTION_FILE: 'Steeltoe.NetCoreToolService.slnx'
21+
22+
jobs:
23+
scan:
24+
name: Scan
25+
timeout-minutes: 15
26+
runs-on: ubuntu-latest
27+
28+
steps:
29+
- name: Setup .NET
30+
uses: actions/setup-dotnet@v5
31+
with:
32+
dotnet-version: |
33+
10.0.*
34+
35+
- name: Git checkout
36+
uses: actions/checkout@v6
37+
with:
38+
persist-credentials: false
39+
40+
- name: Report vulnerable dependencies
41+
shell: pwsh
42+
run: |
43+
$ErrorActionPreference = 'Stop'
44+
$PSNativeCommandUseErrorActionPreference = $true
45+
46+
$output = dotnet list ${{ env.SOLUTION_FILE }} package --vulnerable --include-transitive --format json --output-version 1 2>&1
47+
$text = ($output | Out-String).TrimEnd()
48+
$json = $text | ConvertFrom-Json
49+
$hasVulnerabilities = $false
50+
51+
foreach ($project in $json.projects) {
52+
if (-not $project.frameworks) {
53+
continue
54+
}
55+
56+
$isTestProject = $project.path -like '*/test/*'
57+
58+
foreach ($framework in $project.frameworks) {
59+
foreach ($package in $framework.topLevelPackages) {
60+
$hasVulnerabilities = $true
61+
62+
foreach ($vulnerability in $package.vulnerabilities) {
63+
Write-Host "$($project.path) ($($framework.framework)): top-level $($package.id) $($package.resolvedVersion) – $($vulnerability.severity): $($vulnerability.advisoryurl)"
64+
}
65+
}
66+
67+
if (-not $isTestProject) {
68+
foreach ($package in $framework.transitivePackages) {
69+
$hasVulnerabilities = $true
70+
71+
foreach ($vulnerability in $package.vulnerabilities) {
72+
Write-Host "$($project.path) ($($framework.framework)): transitive $($package.id) $($package.resolvedVersion) – $($vulnerability.severity): $($vulnerability.advisoryurl)"
73+
}
74+
}
75+
}
76+
}
77+
}
78+
79+
if ($hasVulnerabilities) {
80+
exit 1
81+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
name: Cleanup Code
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches:
7+
- main
8+
pull_request:
9+
10+
concurrency:
11+
group: ${{ github.workflow }}-${{ github.ref }}
12+
cancel-in-progress: true
13+
14+
permissions:
15+
contents: read
16+
17+
env:
18+
DOTNET_CLI_TELEMETRY_OPTOUT: 1
19+
DOTNET_NOLOGO: true
20+
SOLUTION_FILE: 'Steeltoe.NetCoreToolService.slnx'
21+
22+
jobs:
23+
verify:
24+
name: Verify Code Style
25+
runs-on: ubuntu-latest
26+
27+
steps:
28+
- name: Setup .NET
29+
uses: actions/setup-dotnet@v5
30+
with:
31+
dotnet-version: |
32+
10.0.*
33+
34+
- name: Git checkout
35+
uses: actions/checkout@v6
36+
with:
37+
persist-credentials: false
38+
fetch-depth: 2
39+
40+
- name: Restore tools
41+
run: dotnet tool restore --verbosity minimal
42+
43+
- name: Restore packages
44+
run: dotnet restore ${{ env.SOLUTION_FILE }} /p:Configuration=Release /p:NuGetAudit=false --verbosity minimal
45+
46+
- name: Build
47+
run: dotnet build ${{ env.SOLUTION_FILE }} --no-restore --configuration Release /p:RunAnalyzers=false
48+
49+
- name: CleanupCode (on PR diff)
50+
if: ${{ github.event_name == 'pull_request' }}
51+
shell: pwsh
52+
run: |
53+
# Not using the environment variables for SHAs, because they may be outdated. This may happen on force-push after the build is queued, but before it starts.
54+
# The below works because HEAD is detached (at the merge commit), so HEAD~1 is at the base branch. When a PR contains no commits, this job will not run.
55+
$headCommitHash = git rev-parse HEAD
56+
$baseCommitHash = git rev-parse HEAD~1
57+
58+
Write-Output "Running code cleanup on commit range $baseCommitHash..$headCommitHash in pull request."
59+
dotnet jb cleanupcode --version
60+
dotnet regitlint -s $env:SOLUTION_FILE --print-command --skip-tool-check --max-runs=5 --jb --dotnetcoresdk=$(dotnet --version) --jb-profile="Steeltoe Full Cleanup" --jb --no-updates --jb --properties:Configuration=Release --jb --properties:RunAnalyzers=false --jb --properties:NuGetAudit=false --jb --verbosity=WARN -f commits -a $headCommitHash -b $baseCommitHash --fail-on-diff --print-diff
61+
62+
- name: CleanupCode (on branch)
63+
if: ${{ github.event_name == 'push' || github.event_name == 'release' || github.event_name == 'workflow_dispatch' }}
64+
shell: pwsh
65+
run: |
66+
Write-Output 'Running code cleanup on all files.'
67+
dotnet jb cleanupcode --version
68+
dotnet regitlint -s $env:SOLUTION_FILE --print-command --skip-tool-check --jb --dotnetcoresdk=$(dotnet --version) --jb-profile="Steeltoe Full Cleanup" --jb --no-updates --jb --properties:Configuration=Release --jb --properties:RunAnalyzers=false --jb --properties:NuGetAudit=false --jb --verbosity=WARN --fail-on-diff --print-diff

0 commit comments

Comments
 (0)