Skip to content

Commit 554eae8

Browse files
authored
Merge branch 'main' into copilot/enable-nullable-reference-types
2 parents b28afc5 + 398b91e commit 554eae8

27 files changed

Lines changed: 616 additions & 334 deletions
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
---
2+
applyTo: "**/*.cs"
3+
---
4+
5+
# C#/.NET Guidelines
6+
7+
## Coding style
8+
9+
For all new C# code:
10+
11+
- Use file-scoped namespaces.
12+
- Use collection expresions - write `[1, 2, 3]` and not `new List<int> { 1, 2, 3 }`.
13+
- Use `var` for local variable declarations.
14+
- Use switch expressions and pattern matching.
15+
- Use string interpolation (`$"Hello, {name}!"`) instead of `string.Format` or concatenation.
16+
- Use `"""triple-quoted strings"""` for multi-line string literals. These can be interpolated as well.
17+
- Use expression-bodied members for simple getters and setters.
18+
19+
## Code Design Rules
20+
21+
- Use immutable records instead of classes for DTOs.
22+
- Do not default to `public` accessibility for members and classes. Follow the least-exposure rule: `private` > `internal` > `protected` > `public`
23+
- Do not add unused methods/parameters for use cases that were not asked for.
24+
- Reuse existing methods or services as much as possible.
25+
- Use composition over inheritance.
26+
27+
## Error Handling & Edge Cases
28+
29+
- Guard early; use `string.IsNullOrWhiteSpace`, `ArgumentNullException.ThrowIfNull`, or `ArgumentNullException.ThrowIfNullOrWhiteSpace`.
30+
- Avoid using null for control flow.
31+
- In methods that return collections, return empty collections instead of null.
32+
- The null-forgiving operator (`!`) is **always** a code smell.
33+
- Do not add excessive or unnecessary try/catch blocks within the same assembly.
34+
35+
## Async Best Practices
36+
37+
- All async methods must have names ending with `Async`.
38+
- Always await async methods - do not "fire and forget".
39+
- Always accept and pass along a `CancellationToken` in async code.
40+
- Don’t add `async/await` if you can simply return a Task directly.
41+
42+
## Testing
43+
44+
- Use Shouldly when writing new assertions.
45+
- Use clear assertions that verify the outcome expressed by the test name.
46+
- Tests should be able to run in any order or in parallel.
47+
- Use or add helper methods for constructing mocks and complex test data objects.
48+
- Avoid disk I/O if possible; use in-memory alternatives or mocks.
49+
- Do not add "Arrange-Act-Assert" comments.
50+
51+
## Comments
52+
53+
- Add XML documentation comments for for new **public** or **internal** types and members.
54+
- Comments that simply restate the member or parameter name do not provide value.
55+
- Comments should provide additional context or explain non-obvious behavior, especially for parameters.
56+
- Comments inside methods should explain "why," not "what".
57+
- Avoid redundant comments that restate the code - not all code needs comments.

eng/docker-tools/templates/jobs/build-images.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ parameters:
44
matrix: {}
55
dockerClientOS: null
66
buildJobTimeout: 60
7-
commonInitStepsForMatrixAndBuild: []
87
customInitSteps: []
98
publishConfig: null
9+
versionsRepoRef: ""
1010
noCache: false
1111
internalProjectName: null
1212
publicProjectName: null
@@ -29,12 +29,13 @@ jobs:
2929
imageInfoHostDir: $(Build.ArtifactStagingDirectory)/imageInfo
3030
imageInfoContainerDir: $(artifactsPath)/imageInfo
3131
steps:
32-
- ${{ parameters.commonInitStepsForMatrixAndBuild }}
33-
- template: /eng/docker-tools/templates/jobs/${{ format('../steps/init-docker-{0}.yml', parameters.dockerClientOS) }}@self
32+
- template: /eng/docker-tools/templates/steps/init-common.yml@self
3433
parameters:
34+
dockerClientOS: ${{ parameters.dockerClientOS }}
3535
publishConfig: ${{ parameters.publishConfig }}
36+
versionsRepoRef: ${{ parameters.versionsRepoRef }}
3637
cleanupDocker: true
37-
- ${{ parameters.customInitSteps }}
38+
customInitSteps: ${{ parameters.customInitSteps }}
3839
- template: /eng/docker-tools/templates/steps/set-image-info-path-var.yml@self
3940
parameters:
4041
publicSourceBranch: $(publicSourceBranch)
@@ -115,6 +116,7 @@ jobs:
115116
- template: /eng/docker-tools/templates/jobs/${{ format('../steps/test-images-{0}-client.yml', parameters.dockerClientOS) }}@self
116117
parameters:
117118
condition: ne(variables.testScriptPath, '')
119+
skipCommonInit: true
118120
- ${{ if and(eq(variables['System.TeamProject'], parameters.internalProjectName), ne(variables['Build.Reason'], 'PullRequest'), eq(parameters.dockerClientOS, 'linux')) }}:
119121
- template: /eng/docker-tools/templates/steps/publish-artifact.yml@self
120122
parameters:

eng/docker-tools/templates/jobs/copy-base-images-staging.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ parameters:
1717
- name: continueOnError
1818
type: string
1919
default: false
20+
- name: versionsRepoRef
21+
type: string
22+
default: ""
2023

2124
jobs:
2225
- template: /eng/docker-tools/templates/jobs/copy-base-images.yml@self
@@ -27,3 +30,4 @@ jobs:
2730
customInitSteps: ${{ parameters.customInitSteps }}
2831
additionalOptions: ${{ parameters.additionalOptions }}
2932
acr: ${{ parameters.publishConfig.InternalMirrorRegistry }}
33+
versionsRepoRef: ${{ parameters.versionsRepoRef }}

eng/docker-tools/templates/jobs/copy-base-images.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,20 @@ parameters:
2323
- name: forceDryRun
2424
type: boolean
2525
default: false
26+
- name: versionsRepoRef
27+
type: string
28+
default: ""
2629

2730
jobs:
2831
- job: ${{ parameters.name }}
2932
pool: ${{ parameters.pool }}
3033
steps:
31-
- template: /eng/docker-tools/templates/steps/init-docker-linux.yml@self
34+
- template: /eng/docker-tools/templates/steps/init-common.yml@self
3235
parameters:
36+
dockerClientOS: linux
3337
publishConfig: ${{ parameters.publishConfig }}
34-
- ${{ parameters.customInitSteps }}
38+
customInitSteps: ${{ parameters.customInitSteps }}
39+
versionsRepoRef: ${{ parameters.versionsRepoRef }}
3540
- template: /eng/docker-tools/templates/steps/copy-base-images.yml@self
3641
parameters:
3742
acr: ${{ parameters.acr }}

eng/docker-tools/templates/jobs/generate-matrix.yml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,20 @@ parameters:
88
noCache: false
99
publishConfig: null
1010
customInitSteps: []
11-
commonInitStepsForMatrixAndBuild: []
11+
versionsRepoRef: ""
1212
sourceBuildPipelineRunId: ""
1313

1414
jobs:
1515
- job: ${{ parameters.name }}
1616
pool: ${{ parameters.pool }}
1717
steps:
18-
- ${{ parameters.commonInitStepsForMatrixAndBuild }}
18+
- template: /eng/docker-tools/templates/steps/init-common.yml@self
19+
parameters:
20+
dockerClientOS: linux
21+
publishConfig: ${{ parameters.publishConfig }}
22+
versionsRepoRef: ${{ parameters.versionsRepoRef }}
23+
customInitSteps: ${{ parameters.customInitSteps }}
1924
- template: /eng/docker-tools/templates/steps/retain-build.yml@self
20-
- template: /eng/docker-tools/templates/steps/init-docker-linux.yml@self
21-
- ${{ parameters.customInitSteps }}
2225
- template: /eng/docker-tools/templates/steps/validate-branch.yml@self
2326
parameters:
2427
publishConfig: ${{ parameters.publishConfig }}

eng/docker-tools/templates/jobs/post-build.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ parameters:
22
pool: {}
33
internalProjectName: null
44
publicProjectName: null
5+
customInitSteps: []
56

67
jobs:
78
- job: Build
@@ -13,7 +14,10 @@ jobs:
1314
imageInfosOutputSubDir: "/output"
1415
sbomOutputDir: "$(Build.ArtifactStagingDirectory)/sbom"
1516
steps:
16-
- template: /eng/docker-tools/templates/steps/init-docker-linux.yml@self
17+
- template: /eng/docker-tools/templates/steps/init-common.yml@self
18+
parameters:
19+
dockerClientOS: linux
20+
customInitSteps: ${{ parameters.customInitSteps }}
1721
- template: /eng/docker-tools/templates/steps/download-build-artifact.yml@self
1822
parameters:
1923
targetPath: $(Build.ArtifactStagingDirectory)

eng/docker-tools/templates/jobs/publish.yml

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ parameters:
33
internalProjectName: null
44
publishConfig: null
55
customInitSteps: []
6+
customPostInitSteps: []
67
customPublishVariables: []
78
sourceBuildPipelineDefinitionId: ""
89
sourceBuildPipelineRunId: ""
@@ -45,25 +46,21 @@ jobs:
4546
- ${{ parameters.customPublishVariables }}
4647

4748
steps:
48-
- template: /eng/docker-tools/templates/steps/init-matrix-build-publish.yml@self
49+
- template: /eng/docker-tools/templates/steps/init-common.yml@self
4950
parameters:
51+
dockerClientOS: linux
5052
publishConfig: ${{ parameters.publishConfig }}
5153
versionsRepoRef: ${{ parameters.versionsRepoRef }}
54+
customInitSteps: ${{ parameters.customInitSteps }}
5255

5356
- template: /eng/docker-tools/templates/steps/retain-build.yml@self
5457

55-
- template: /eng/docker-tools/templates/steps/init-docker-linux.yml@self
56-
parameters:
57-
publishConfig: ${{ parameters.publishConfig }}
58-
5958
- pwsh: |
6059
$azdoOrgName = Split-Path -Leaf $Env:SYSTEM_COLLECTIONURI
6160
echo "##vso[task.setvariable variable=azdoOrgName]$azdoOrgName"
62-
$versionsRepoRoot = "$(Pipeline.Workspace)/s/${{ parameters.versionsRepoPath }}"
63-
echo "##vso[task.setvariable variable=versionsRepoRoot]$versionsRepoRoot"
6461
displayName: Set Publish Variables
6562
66-
- ${{ parameters.customInitSteps }}
63+
- ${{ parameters.customPostInitSteps }}
6764

6865
- template: /eng/docker-tools/templates/steps/validate-branch.yml@self
6966
parameters:

0 commit comments

Comments
 (0)