AGENT SKILL

SDK 代码提交前检查

pre-commit-checks

azure-sdk-for-net 的提交前验证检查。在提交或推送对 SDK 包的更改之前使用。执行 dotnet format、导出公共 API 列表、更新 snippets,并按需重新生成代码。

License 许可
MIT
最近更新
2026-11-14
Stars
★ 6.1k
Forks
5.2k

01 前言 Front Matter

name
pre-commit-checks
description
Pre-commit validation checks for azure-sdk-for-net. Use this before committing or pushing changes to SDK packages. Runs dotnet format, exports public API listings, updates snippets, and regenerates code as needed.

03 SKILL.md 正文

Pre-Commit Validation Checks

Run these checks after making changes to SDK packages under sdk/ and before staging, committing, or pushing. These steps may produce additional file changes that must be included in the commit.

General rule: Steps 3–5 are conditional to save time, but if you are unsure whether a step is needed, always run it. It is better to run an unnecessary script than to miss a required regeneration.

1. Determine scope from changed files

  • Derive the changed file list from git status --porcelain (or by combining git diff --name-only HEAD with git ls-files -o --exclude-standard) so that untracked (new) files are included.
  • From the changed file list, extract all unique ServiceDirectories — the first path segment after sdk/ (e.g., sdk/storage/... → storage, sdk/ai/... → ai).
  • For each ServiceDirectory, identify all affected packages = distinct sdk/{ServiceDirectory}/{PackageName}/ paths.
  • For each affected package, identify:
    • All csproj files that had changes beneath them (src, tests, samples, perf, stress, or any other project type).
    • The src csproj specifically = sdk/{service}/{package}/src/{Package}.csproj — this is used for GenerateCode.
  • The remaining steps must be run for each affected project/ServiceDirectory. If changes span multiple ServiceDirectories or packages, run for each one.

2. Run dotnet format (for every changed csproj)

For every csproj that had files change beneath it — src, tests, samples, perf, stress, or any other project type — run:

dotnet format <path-to-changed.csproj>

Identify affected csproj files by looking at the full changed file list: include any project where either (a) there is a changed .cs file with that .csproj as its nearest parent, or (b) the .csproj itself changed, or files such as .props, .targets, or .md changed under that project. This fixes style/formatting issues and may modify .cs files.

3. Conditionally run dotnet build /t:GenerateCode (per src csproj)

Exclusion: Skip this step entirely for the provisioning service directory. Provisioning libraries use their own generator and are not generated via TypeSpec/AutoRest.

Trigger condition — for each affected package's src csproj: Run this if ANY of the following files are in the changed file list:

  • Any file matching sdk/{service}/{package}/src/Generated/**
  • sdk/{service}/{package}/tsp-location.yaml
  • sdk/{service}/{package}/src/autorest.md
  • Any .cs file under sdk/{service}/{package}/src/ where a CodeGen* attribute was added, removed, or modified (e.g., CodeGenType, CodeGenModel, CodeGenClient, CodeGenMember, CodeGenSuppress, CodeGenSerialization, CodeGenVisibility). These attributes in custom (non-generated) code influence the generated output.

Important: Do not manually edit files under src/Generated/. Changes to generated code should only come from running the GenerateCode target.

Command:

dotnet build sdk/{service}/{package}/src/{Package}.csproj /t:GenerateCode

This regenerates code from TypeSpec/AutoRest specs. It may modify files under src/Generated/.

4. Conditionally run Export-API.ps1 (per ServiceDirectory)

Trigger condition — per ServiceDirectory: Run this if ANY of the following are true for ANY affected package within this ServiceDirectory:

  • Step 3 above ran for any package in this ServiceDirectory (generated code may affect public API).
  • Changed .cs files under sdk/{service}/{package}/src/ for any package in this ServiceDirectory contain public API surface changes. To determine this, inspect the diffs for:
    • New, removed, or renamed public or protected types (class, interface, struct, enum, record).
    • New, removed, or changed signatures of public or protected members (methods, properties, constructors, events, fields).
    • Visibility changes (e.g., internal → public).
    • Changes to base classes or implemented interfaces on public types.
    • New .cs files under src/ that contain public types.

Skip Export-API if changes are limited to:

  • Method body implementations (no signature changes).
  • internal or private members only.
  • XML doc comments or code comments.
  • .csproj configuration changes.

Command:

eng\scripts\Export-API.ps1 {ServiceDirectory}

This regenerates API listing files under sdk/{service}/{package}/api/*.cs. Uses dotnet build /t:ExportApi internally.

Note: Export-API operates at the ServiceDirectory level (not per-csproj), so run it once per affected ServiceDirectory.

5. Conditionally run Update-Snippets.ps1 (per ServiceDirectory)

Trigger condition — for each affected ServiceDirectory: Run this if ANY of the following are true:

  • Changed *.md files under sdk/{service}/ contain snippet references (```C# Snippet: markers).
  • Changed .cs files contain snippet regions (#region Snippet:).

Command:

eng\scripts\Update-Snippets.ps1 {ServiceDirectory}

Note: Update-Snippets operates at the ServiceDirectory level (not per-csproj), so run it once per affected ServiceDirectory.

This runs snippet-generator to sync code snippets into markdown files. May modify *.md and *.cs files.

6. Verify and include all changes

  • After running all applicable steps for all affected projects and ServiceDirectories, check for new/modified files with git status.
  • All changes produced by these steps must be included in the commit.
  • Do NOT commit if any of the above steps failed.

Execution order

Run the following steps in this order, respecting their scope (per package vs per ServiceDirectory):

  1. dotnet format first — run on all changed csproj files (src, tests, etc.) for each affected package.
  2. GenerateCode second — per src csproj, regenerates from specs (may override format changes in Generated/) for each affected package.
  3. Export-API third — run once per affected ServiceDirectory, after all GenerateCode runs for packages in that ServiceDirectory are complete; captures the final public API surface after generation.
  4. Update-Snippets fourth — run once per affected ServiceDirectory, after Export-API; captures any snippet changes from all prior steps.

When multiple packages/ServiceDirectories are affected, run steps 1–2 for each affected package, then steps 3–4 once per affected ServiceDirectory. Step 6 (verify) runs once at the end.

04 同仓库更多 Skills

Azure
Azure/azure-sdk-for-net

WebPubSub Chat API 基线维护

update-chat-api

使用场景:在公共 API 发生变更后,更新、导出、刷新或验证 Azure.Messaging.WebPubSub.Chat 的公共 API 基线。

软件开发工程师代码实现
★ 6.1k
Azure
Azure/azure-sdk-for-net

Azure 搜索文档 SDK 端到端工作流

search-documents

Azure.Search.Documents SDK 的端到端(E2E)工作流技能(TypeSpec + 大量定制)。处理完整发布周期和部分更新:SHA 更新;代码生成;构建;定制修复;ServiceVersion 同步;测试;API 导出;变更日志;版本;示例;格式化;发布元数据。使用场景:为 Azure.Search.Documents 创建新包版本;重新生成 Azure.Search.Documents;修复 Azure.Search.Documents 错误;发布 Azure.Search.Documents;更新 Azure.Search.Documents 规范。不适用于 Azure.ResourceManager.Search 或 Azure.Provisioning.Search。

软件开发工程师Microsoft 应用生命周期管理
★ 6.1k
Azure
Azure/azure-sdk-for-net

Search.Documents 版本差异检测

search-documents-version-diff

将当前 Azure.Search.Documents 公共 API 接口与之前发布的版本进行对比,检测因 TypeSpec 变更后 SDK 自定义层未向上传播而导致的预览版之间的回归。当用户要求比较 Azure.Search.Documents 各 beta 版本、确认 Azure.Search.Documents 预览功能未丢失、审计 Azure.Search.Documents 各版本间的回归、对 Azure.Search.Documents 发布分支进行健全性检查,或排查 Azure.Search.Documents 预览功能缺失时使用——即使用户没有提到“diff”一词。专门捕获丢失的包装器(QueryAnswer/QueryCaption/QueryRewrites 类型)、丢失的 SearchOptions 聚合重定向器、`@@access("internal")` 翻转、被直接删除而非通过条件门控的 `#if AZURE_SEARCH_PREVIEW` 代码块、丢失的 `ServiceVersion` 枚举值,以及便捷方法降级为协议方法等问题。

软件开发工程师测试与质量保障
★ 6.1k
Azure
Azure/azure-sdk-for-net

Search.Documents TypeSpec 一致性验证

search-documents-typespec-validation

面向 Azure.Search.Documents SDK 的 TypeSpec 验证技能。针对任意固定 commit 的 TypeSpec 定义,对全部操作、全部模型、全部枚举和全部属性执行完整验证。适用于任何 API 版本。生成完整的差距报告:缺失功能、多余功能、命名不匹配以及建议的修复位置。适用场景:“根据 TypeSpec 验证 Azure.Search.Documents SDK”、“检测 Azure.Search.Documents TypeSpec 功能差距”、“Azure.Search.Documents SDK 缺少哪些功能”、“将 Azure.Search.Documents SDK 与规范对比”、“对 Azure.Search.Documents 进行完整的规范覆盖审计”。请勿用于版本间差异对比或回归检测——此类情况请使用 search-documents-version-diff。

软件开发工程师测试与质量保障
★ 6.1k
Azure
Azure/azure-sdk-for-net

掷骰子技能文件测试

test-skill_file

使用随机数生成器掷骰子。

普通用户抽奖活动与随机抽取
★ 6.1k
Azure
Azure/azure-sdk-for-net

随机数掷骰子

roll-dice

使用随机数生成器掷骰子。当用户要求掷单个骰子(d6、d20 等)、掷骰子或生成随机掷骰结果时使用。

普通用户抽奖活动与随机抽取
★ 6.1k