Skip to content

Commit dd126d4

Browse files
John Luodougbu
John Luo
andauthored
Following up on API baseline check and documentation (dotnet#30221)
* Update codecheck logic for verifying api baselines * Update baseline documentation Co-authored-by: Doug Bunting <6431421+dougbu@users.noreply.github.com>
1 parent 8df6490 commit dd126d4

File tree

2 files changed

+38
-10
lines changed

2 files changed

+38
-10
lines changed

docs/APIBaselines.md

+24-5
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,25 @@
11
# API Baselines
22

3-
This document contains information regarding API baseline files and how to work with them.
3+
This document contains information regarding API baseline files and how to work with them. For additional details on how these files works, consult:
4+
- https://github.com/dotnet/roslyn-analyzers/blob/master/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md
5+
- https://github.com/dotnet/roslyn-analyzers/blob/master/src/PublicApiAnalyzers/Microsoft.CodeAnalysis.PublicApiAnalyzers.md
46

57
## Add baseline files for new projects
68

79
When creating a new implementation (i.e. src) project, it's necessary to manually add API baseline files since API baseline are enabled by default. If the project is a non-shipping or test only project, add `<AddPublicApiAnalyzers>false</AddPublicApiAnalyzers>` to the project to disable these checks. To add baseline files to the project:
810

9-
1. Copy eng\PublicAPI.empty.txt to the project directory and rename it to PublicAPI.Shipped.txt
10-
1. Copy eng\PublicAPI.empty.txt to the project directory and rename it to PublicAPI.Unshipped.txt
11+
1. `cp .\eng\PublicAPI.empty.txt {new folder}\PublicAPI.Shipped.txt`
12+
1. `cp .\eng\PublicAPI.empty.txt {new folder}\PublicAPI.Unshipped.txt`
13+
14+
See [Steps for adding and updating APIs](#steps-for-adding-and-updating-apis) for steps on how to add APIs to the Unshipped.txt files
1115

1216
## PublicAPI.Shipped.txt
1317

1418
This file contains APIs that were released in the last major version. This file should only be modified after a major release by the build team and should never be modified otherwise.
1519

1620
## PublicAPI.Unshipped.txt
1721

18-
This file contains new APIs since the last major version.
22+
This file contains new APIs since the last major version. Steps for working with changes in APIs and updating this file are found in [Steps for adding and updating APIs](#steps-for-adding-and-updating-apis).
1923

2024
### New APIs
2125

@@ -45,6 +49,21 @@ Two new entry needs to be added to the PublicAPI.Unshipped.txt file for an updat
4549
Microsoft.AspNetCore.DataProtection.Infrastructure.IApplicationDiscriminator.Discriminator.get -> string?
4650
```
4751

52+
### Steps for adding and updating APIs
53+
54+
1. Update AspNetCore.sln and relevant `*.slnf` file to include the new project if needed
55+
1. `{directory containing relevant *.slnf}\startvs.cmd`
56+
1. F6 *or whatever your favourite build gesture is*
57+
1. Click on a RS0016 (or whatever) error
58+
1. Right click in editor on underscored symbol or go straight to the “quick fix” icon to its left. Control-. also works.
59+
1. Choose “Add Blah to public API” / “Fix all occurrences in … Solution”
60+
1. Click Apply
61+
1. F6 *again to see if the fixer missed anything or if other RS00xx errors show up (not uncommon)*
62+
1. Suppress or fix other problems as needed but please suppress (if suppressing) using attributes and not globally or with `#pragma`s because attributes make the justification obvious e.g. for common errors that can't be fixed
63+
`[SuppressMessage("ApiDesign", "RS0026:Do not add multiple public overloads with optional parameters", Justification = "Required to maintain compatibility")]`
64+
or
65+
`[SuppressMessage("ApiDesign", "RS0027:Public API with optional parameter(s) should have the most parameters amongst its public overloads.", Justification = "Required to maintain compatibility")]`
66+
4867
## Updating baselines after major releases
4968

50-
TODO
69+
This will be performed by the build team using scripts at https://github.com/dotnet/roslyn/tree/master/scripts/PublicApi (or an Arcade successor). The process moves the content of PublicAPI.Unshipped.txt into PublicAPI.Shipped.txt

eng/scripts/CodeCheck.ps1

+14-5
Original file line numberDiff line numberDiff line change
@@ -191,18 +191,27 @@ try {
191191
}
192192
}
193193

194-
Write-Host "Checking for changes to API baseline files"
194+
$targetBranch = $env:SYSTEM_PULLREQUEST_TARGETBRANCH
195+
if ($targetBranch.StartsWith('refs/heads/')) {
196+
$targetBranch = $targetBranch.Replace('refs/heads/','')
197+
}
195198

196199
# Retrieve the set of changed files compared to main
197-
$commitSha = git rev-parse HEAD
198-
$changedFilesFromMain = git --no-pager diff origin/main...$commitSha --ignore-space-change --name-only --diff-filter=ar
200+
Write-Host "Checking for changes to API baseline files $targetBranch"
201+
202+
$changedFilesFromTarget = git --no-pager diff origin/$targetBranch --ignore-space-change --name-only --diff-filter=ar
199203
$changedAPIBaselines = [System.Collections.Generic.List[string]]::new()
200204

201-
if ($changedFilesFromMain) {
202-
foreach ($file in $changedFilesFromMain) {
205+
if ($changedFilesFromTarget) {
206+
foreach ($file in $changedFilesFromTarget) {
207+
# Check for changes in Shipped in all branches
203208
if ($file -like '*PublicAPI.Shipped.txt') {
204209
$changedAPIBaselines.Add($file)
205210
}
211+
# Check for changes in Unshipped in servicing branches
212+
if ($targetBranch -like 'release*' -and $file -like '*PublicAPI.Unshipped.txt') {
213+
$changedAPIBaselines.Add($file)
214+
}
206215
}
207216
}
208217

0 commit comments

Comments
 (0)