Move dotnet format check to build step (#166)

* Move dotnet format check to build step
* Add analyze job to build
This commit is contained in:
Patrick Hallisey authored and GitHub committed 2025-05-12 15:54:04 +00:00
1 parent 6e8f72e0f3
commit ed0c67d3c9
7 files changed
+70 -53

No files matched your search

+12 -11
View File
@@ -13,6 +13,8 @@ If you are contributing significant changes, or if the issue is already assigned
2. Install [GitHub Copilot](https://marketplace.visualstudio.com/items?itemName=GitHub.copilot) and [GitHub Copilot Chat](https://marketplace.visualstudio.com/items?itemName=GitHub.copilot-chat) extensions.
3. Install [Node.js](https://nodejs.org/en/download) 20 or later
* Ensure `node` and `npm` are in your path
4. Install [PowerShell](https://learn.microsoft.com/en-us/powershell/scripting/install/installing-powershell) 7.0 or later.
* Optional for coding but required for running build, test and resource deployment scripts
### Project Structure
@@ -95,19 +97,11 @@ After deploying test resources, you should have a `.testsettings.json` file with
./eng/scripts/Test-Code.ps1 -Live
```
## Installing Git Hooks
To ensure consistent code quality, the pre-commit hook is automatically installed before every build. This hook will ensure that your code adheres to the required standards.
### Automatic Setup
The pre-push hook is installed automatically when you build the project. You do not need to run any additional commands. The hook is located in the `eng/scripts/git-hooks/` directory and is copied to the `.git/hooks/` folder during the build process.
Powershell is required for hook installation. For installation instructions, see [Installing PowerShell](https://learn.microsoft.com/en-us/powershell/scripting/install/installing-powershell).
## Code Style
Run `dotnet format src/AzureMcp.sln` before submitting.
To ensure consistent code quality, code format checks will run during all PR and CI builds.
To catch format errors early, run `dotnet format src/AzureMcp.sln` before submitting.
- Follow C# coding conventions
- No comments in implementation code (code should be self-documenting)
@@ -117,6 +111,13 @@ Run `dotnet format src/AzureMcp.sln` before submitting.
- XML documentation for public APIs
- Follow Model Context Protocol (MCP) patterns
### Installing Git Hooks
You can install our pre-push hook to catch code format issues by automatically running `dotnet format` before each `git push`.
- `./eng/scripts/Install-GitHooks.ps1` - Installs the pre-push hook into your local repo
- `./eng/scripts/Remove-GitHooks.ps1` - Disables any git hooks in your local repo
## Model Context Protocol (MCP)
The Azure MCP Server implements the [Model Context Protocol specification](https://modelcontextprotocol.io). When adding new commands:
+5 -4
View File
@@ -18,7 +18,7 @@ resources:
type: git
name: internal/azure-sdk-build-tools
ref: refs/tags/azure-sdk-build-tools_20250307.1
extends:
template: /eng/pipelines/templates/1es-redirect.yml
parameters:
@@ -36,6 +36,7 @@ extends:
- template: /eng/pipelines/templates/jobs/initialize.yml
parameters:
ReleaseRun: ${{ parameters.ReleaseRun }}
- template: /eng/pipelines/templates/jobs/analyze.yml
- template: /eng/common/pipelines/templates/jobs/generate-job-matrix.yml
parameters:
SparseCheckout: false
@@ -76,7 +77,7 @@ extends:
CloudConfig:
Cloud: Public
ServiceConnection: azure-sdk-tests-public
# # All builds in the internal project get signing
- stage: SignAndPack
${{ if parameters.SkipSigning }}:
@@ -93,7 +94,7 @@ extends:
- template: /eng/pipelines/templates/jobs/sign-and-pack.yml
parameters:
SkipSigning: ${{ parameters.SkipSigning }}
- ${{ if eq(parameters.PublishPackages, 'true') }}:
- ${{ if eq(parameters.ReleaseRun, 'true') }}:
- stage: Release
@@ -127,4 +128,4 @@ extends:
- name: Version
value: $[ stageDependencies.Build.Initialize.outputs['Version.Version'] ]
jobs:
- template: /eng/pipelines/templates/jobs/integration.yml
- template: /eng/pipelines/templates/jobs/integration.yml
+8 -10
View File
@@ -10,7 +10,7 @@ jobs:
dependsOn: []
steps:
- checkout: self
- task: UseDotNet@2
displayName: "Use .NET SDK from global.json"
retryCountOnTaskFailure: 3
@@ -27,12 +27,10 @@ jobs:
parameters:
ContinueOnError: false
# Link detection into private repos is not supported.
# TODO: Uncomment when the repo is public
# - template: /eng/common/pipelines/templates/steps/verify-links.yml
# parameters:
# Condition: succeededOrFailed()
# Directory: ""
# CheckLinkGuidance: $true
# ${{ if eq(variables['Build.Reason'], 'PullRequest') }}:
# Urls: (eng/common/scripts/get-markdown-files-from-changed-files.ps1)
- template: /eng/common/pipelines/templates/steps/verify-links.yml
parameters:
Condition: succeededOrFailed()
Directory: ""
CheckLinkGuidance: $true
${{ if eq(variables['Build.Reason'], 'PullRequest') }}:
Urls: (eng/common/scripts/get-markdown-files-from-changed-files.ps1)
+11 -3
View File
@@ -2,12 +2,20 @@
#Requires -Version 7
. "$PSScriptRoot/../common/scripts/common.ps1"
$RepoRoot = $RepoRoot.Path.Replace('\', '/')
Push-Location $RepoRoot
try {
# source analysis steps here
$solutionFile = Get-ChildItem -Path . -Filter *.sln | Select-Object -First 1
dotnet format $solutionFile --verify-no-changes
if ($LASTEXITCODE) {
Write-Host "❌ dotnet format detected formatting issues."
Write-Host "Please run 'dotnet format `"$solutionFile`"' to fix the issues and then try committing again."
exit 1
} else {
Write-Host "✅ dotnet format did not detect any formatting issues."
}
}
finally {
Pop-Location
}
}
-13
View File
@@ -51,16 +51,3 @@ foreach ($file in $hookFiles) {
& chmod +x $targetFile
}
}
# TODO: Remove after 5/9/2025
# remove existing pre-commit hook if it matches the pre-push hook
$preCommitPath = Join-Path $gitHooksTargetDir "pre-commit"
$prePushPath = Join-Path $gitHooksTargetDir "pre-push"
if(Test-Path $preCommitPath) {
$prePushContent = Get-Content -Path $prePushPath -Raw
$preCommitContent = Get-Content -Path $preCommitPath -Raw
if($prePushContent -eq $preCommitContent) {
Write-Host "Removing stale pre-commit hook"
Remove-Item -Path $preCommitPath -Force -ErrorAction SilentlyContinue | Out-Null
}
}
+28
View File
@@ -0,0 +1,28 @@
#!/usr/bin/env pwsh
<#
.SYNOPSIS
Disable git hooks from in .git/hooks by renaming them
#>
[CmdletBinding()]
param()
$repoRoot = Resolve-Path (Join-Path $PSScriptRoot "../..")
$gitHooksTargetDir = Join-Path $repoRoot ".git/hooks"
if (-not (Test-Path $gitHooksTargetDir)) {
Write-Host "Git hooks directory not found. Skipping hook removal."
exit 0
}
# Copy hook files
Write-Host "Disabling git hooks in $gitHooksTargetDir..."
$hookFiles = Get-ChildItem -Path $gitHooksTargetDir -File
| Where-Object { $_.Extension -eq '' }
foreach ($file in $hookFiles) {
Write-Host " Renaming $($file.Name) to $($file.Name).old"
# Create a backup of the existing file
Move-Item -Path $file -Destination "$file.old" -Force
}
+6 -12
View File
@@ -49,8 +49,8 @@
<PackageReference Include="Azure.Messaging.ServiceBus" />
<PackageReference Include="Azure.Monitor.Query" />
<PackageReference Include="Azure.ResourceManager.AppConfiguration" />
<PackageReference Include="Azure.ResourceManager.Kusto" />
<PackageReference Include="Azure.ResourceManager.PostgreSql" />
<PackageReference Include="Azure.ResourceManager.Kusto" />
<PackageReference Include="Azure.ResourceManager.PostgreSql" />
<PackageReference Include="Azure.Security.KeyVault.Keys" />
<PackageReference Include="Azure.Storage.Blobs" />
<PackageReference Include="Azure.ResourceManager.CosmosDB" />
@@ -66,7 +66,7 @@
<PackageReference Include="Microsoft.Extensions.DependencyInjection" />
<PackageReference Include="Microsoft.Extensions.Hosting" />
<PackageReference Include="Newtonsoft.Json" />
<PackageReference Include="Npgsql" />
<PackageReference Include="Npgsql" />
<PackageReference Include="System.CommandLine" />
<PackageReference Include="System.Formats.Asn1" />
<PackageReference Include="System.Linq.AsyncEnumerable" />
@@ -81,17 +81,11 @@
<EmbeddedResource Include="Resources\azure-best-practices.txt" />
</ItemGroup>
<!-- TODO: Remove after 5/19/25 -->
<!-- Runs before every dotnet build -->
<Target Name="InstallGitHooks" BeforeTargets="BeforeBuild">
<Message Text="Installing Git hooks..." Importance="high" />
<!-- Run the Install-GitHooks.ps1 script using PowerShell Core -->
<Exec Command="pwsh -ExecutionPolicy Bypass -NoProfile -File &quot;$(MSBuildProjectDirectory)/../eng/scripts/Install-GitHooks.ps1&quot;" ContinueOnError="true" ConsoleToMsBuild="true" IgnoreExitCode="true">
<Output TaskParameter="ExitCode" PropertyName="ExitCode" />
</Exec>
<!-- Display informative message if pwsh fails -->
<Warning Text="Could not install Git hooks. PowerShell Core (pwsh) is required to install Git hooks:\nhttps://learn.microsoft.com/powershell/scripting/install/installing-powershell" Condition="'$(ExitCode)' != '0'" />
<Message Text="To install git hooks, run 'eng/scripts/Install-GitHooks.ps1'" Importance="high" />
<Message Text="To remove git hooks, run 'eng/scripts/Remove-GitHooks.ps1'" Importance="high" />
</Target>
<!-- Remove Cosmos native files from the build output directory -->