Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixup API baselines after merge #28253

Merged
merged 13 commits into from
Feb 8, 2021
Merged

Fixup API baselines after merge #28253

merged 13 commits into from
Feb 8, 2021

Conversation

JunTaoLuo
Copy link
Contributor

@JunTaoLuo JunTaoLuo commented Nov 30, 2020

TODO:

  • Restore Shipped API baseline files
  • Update Unshipped API baseline files to match updated APIs
  • Add documentation
  • Add codecheck step to make sure no Shipped APIs are touched

@Pilchie Pilchie added the area-infrastructure Includes: MSBuild projects/targets, build scripts, CI, Installers and shared framework label Dec 1, 2020
@Tratcher Tratcher removed their request for review December 8, 2020 01:08
@dougbu
Copy link
Member

dougbu commented Jan 14, 2021

@JunTaoLuo did this get fixed elsewhere❔ Please fix the conflicts or close😃

Base automatically changed from master to main January 22, 2021 01:33
@dougbu dougbu requested review from javiercn, pranavkm and a team as code owners January 22, 2021 01:33
@dougbu
Copy link
Member

dougbu commented Feb 5, 2021

Good start apart from the conflicts 😁

Restore Shipped files to match release/5.0

Update Unshipped to reflect changed APIs
Add codecheck test for modified baseline files

Add documentation
@JunTaoLuo JunTaoLuo requested a review from a team as a code owner February 8, 2021 06:05

## Updating baselines after major releases

TODO
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dougbu would you like to update this section since you did it for 5.0 and have more expreience 😄

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In 5.0, I only had to copy files around because all PublicAPI.Shipped.txt files were empty. Fortunately a couple of scripts are available e.g. in the Roslyn repo. dotnet/roslyn-analyzers#3226 covers centralizing that work.

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:

1. Copy eng\PublicAPI.empty.txt to the project directory and rename it to PublicAPI.Shipped.txt
1. Copy eng\PublicAPI.empty.txt to the project directory and rename it to PublicAPI.Unshipped.txt
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these modified automatically during the build? Is there a way to automatically populate them? If not how should devs update them? Would be worth calling out in the doc

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Visual Studio is the only reliable way to update the files at the moment. Editing them manually is strongly discouraged because the syntax is finicky.

@Pilchie is working with the Roslyn team to enable dotnet format to handle this from the command line.

In the meantime, instructions for adding new implementation projects should mention

  1. cp .\eng\PublicAPI.empty.txt {new folder}\PublicAPI.Shipped.txt
  2. cp .\eng\PublicAPI.empty.txt {new folder}\PublicAPI.Unshipped.txt
  3. Update AspNetCore.sln and relevant *.slnf file to include the new project
  4. {directory containing relevant *.slnf}\startvs.cmd
  5. F6 # or whatever your favourite build gesture is
  6. Click on a RS0016 (or whatever) error
  7. Right click in editor on underscored symbol or go straight to the “quick fix” icon to its left . Control-. also works.
  8. Choose “Add Blah to public API” / “Fix all occurrences in … Solution”
  9. Click Apply
  10. F6 # yes, again to see if the fixer missed anything or if other RS00xx errors show up (not uncommon)
  11. Suppress or fix other problems as needed but please suppress (if suppressing) using attributes and not globally or with #pragmas because attributes make the justification obvious e.g. for common errors that can't be fixed
    [SuppressMessage("ApiDesign", "RS0026:Do not add multiple public overloads with optional parameters", Justification = "Required to maintain compatibility")]
    or
    [SuppressMessage("ApiDesign", "RS0027:Public API with optional parameter(s) should have the most parameters amongst its public overloads.", Justification = "Required to maintain compatibility")]

More information available in


# Retrieve the set of changed files compared to main
$commitSha = git rev-parse HEAD
$changedFilesFromMain = git --no-pager diff origin/main...$commitSha --ignore-space-change --name-only
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't need to make the change now, but if there's a way to not hard-code the branch name that'd be preferable

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure how we can remove the hard coding to the default branch, is there a git command to do that? In any case, I figured the default branch name shouldn't be modified often and I think in those cases, we would scrub the script for usages of the name anyway.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There be dragons @JunTaoLuo In particular,

  1. We need to enable a more drastic version of this in release/5.0, covering the PublicAPI.Unshipped.txt files too
    • We need to compare against release/5.0 there
  2. Need to compare against our preview branches for 6.0 after each is split from main
  3. This check will do nothing in rolling builds and should be suppressed unless $(Build.Reason) (in YAML) or $env:BUILD_REASON contain PullRequest

To get current branch in PR builds, can use

  • git config --show-current displays the current branch name
  • same information should be available in $(Build.SourceBranchName) in YAML or $env:BUILD_SOURCEBRANCHNAME
  • use above w/o Name / NAME to get the full branch path but, with the name, should display the PR id

Need something like the GitHub REST API to get more information e.g. to display the base aka target branch

Invoke-WebRequest -Headers @{ Accept = "application/vnd.github.v3+json"} https://api.github.com/repos/dotnet/aspnetcore/pulls/{PR id} | `
 ConvertFrom-Json |ForEach-Object `
 base |ForEach-Object `
 ref

For internal PRs, the commands are probably like

Invoke-WebRequest  -Headers @{ Accept = "application/vnd.github.v3+json"} https://dev.azure.com/{blah}/{blah}/_git/dotnet-aspnetcore/_apis/git/pullrequests/{PR id}?api-version=5.0 |ForEach-Object `
  targetRefName

But, I don't see documentation on how to authenticate nor control the preferred response type. (May respond w/ JSON in successful cases but I'm only getting 404s despite testing w/ an existing PR.)

@ilyas1974 anyone in your world with the AzDO REST API knowledge we need❔ Note we'd like to run this in CI, where we should have the right tokens available.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JunTaoLuo
Copy link
Contributor Author

The codecheck failure is expected since this PR needs to fix and restore APIBaseline.Shipped.txt files. In these cases, the admins need to override the failure and merge.

I'll follow up with improvements to the documentation separately.

@JunTaoLuo JunTaoLuo merged commit ab9c650 into main Feb 8, 2021
@JunTaoLuo JunTaoLuo deleted the johluo/api-baseline-fix branch February 8, 2021 19:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-infrastructure Includes: MSBuild projects/targets, build scripts, CI, Installers and shared framework
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants