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

Run apiview checks in pr to detect public api changes #3283

Merged
merged 81 commits into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
81 commits
Select commit Hold shift + click to select a range
9d76c0a
initial checkin for apiview change
m-nash May 6, 2024
dcad68b
Merge branch 'main' of https://github.com/Microsoft/typespec into api…
m-nash May 6, 2024
1ed6df8
fix formatting
m-nash May 6, 2024
c69535c
update artifacts param
m-nash May 6, 2024
ec1b7cb
fix typo in param
m-nash May 6, 2024
6a6b371
add devops project param
m-nash May 6, 2024
32cd8d3
move lang specific functions
m-nash May 6, 2024
69a9705
pass through language name
m-nash May 6, 2024
366ee0e
missed one pass through
m-nash May 6, 2024
718ebc1
pass through was in wrong spot
m-nash May 6, 2024
c6283e5
pack the dotnet dlls
m-nash May 6, 2024
82e7c0b
isolate langauge artifacts
m-nash May 6, 2024
045c5e9
fix filter in pwsh
m-nash May 6, 2024
44d2e19
update file locations
m-nash May 6, 2024
226bbc1
fix link
m-nash May 6, 2024
4a07e97
update paths
m-nash May 7, 2024
eb5ce57
add wildcard to filter
m-nash May 7, 2024
e16012f
add packageinfo files to artifacts
m-nash May 7, 2024
010691c
few more fixes
m-nash May 7, 2024
57d768d
fix path
m-nash May 7, 2024
389b755
add git helper for getting changed files for api view
m-nash May 7, 2024
cca571a
remove the prepend slash
m-nash May 7, 2024
c7953f7
move detect api changes to its own job that runs after the build job …
m-nash May 7, 2024
25a693c
syntax error
m-nash May 7, 2024
7218991
adjust folder
m-nash May 7, 2024
34af324
add download step
m-nash May 7, 2024
b6a07b5
adjust paths again
m-nash May 7, 2024
3fb213b
try diff root
m-nash May 7, 2024
c469364
Merge branch 'main' of https://github.com/Microsoft/typespec into api…
m-nash May 7, 2024
d508018
more tries
m-nash May 7, 2024
ae63442
update variable used
m-nash May 7, 2024
62790d7
refactory more
m-nash May 7, 2024
7d610fd
typo
m-nash May 7, 2024
805653a
syntax error
m-nash May 7, 2024
c29a1e3
more tweaks
m-nash May 7, 2024
8e801c8
make artifctname optional
m-nash May 7, 2024
7584043
update test reference to build artifact
m-nash May 7, 2024
7ee5167
pass through artifact name
m-nash May 7, 2024
b5c7936
fix typo
m-nash May 7, 2024
ef3d584
update artifact name to be more explicit
m-nash May 8, 2024
64d28d8
add create api review for publish
m-nash May 8, 2024
5894c0b
add short name
m-nash May 8, 2024
f6ad732
use 1es feed for nuget
m-nash May 8, 2024
1d926f5
fix format
m-nash May 8, 2024
eab84aa
don't run detect if we are publishing
m-nash May 8, 2024
ef3d487
update cspell
m-nash May 8, 2024
0eb170a
update version numbers for csharp packages
m-nash May 8, 2024
4cd6685
refactor version handling
m-nash May 8, 2024
47c7346
add some write host
m-nash May 8, 2024
906e24d
update write host
m-nash May 8, 2024
4fb2910
update build script
m-nash May 8, 2024
c4baee6
remove noise and set pre release to true for publish
m-nash May 8, 2024
0bf3749
test var scope
m-nash May 8, 2024
ca514b0
fix format
m-nash May 8, 2024
1bc4d6c
update nupkg publish
m-nash May 8, 2024
1aa1488
fix param ref
m-nash May 8, 2024
a971c56
add if
m-nash May 8, 2024
238218f
try condition instead
m-nash May 8, 2024
7cf0b89
another try
m-nash May 8, 2024
c9f3720
expicitly set if we have nuget packages
m-nash May 8, 2024
59e1d65
add missing helpers
m-nash May 8, 2024
da21d8a
pass through lang short name
m-nash May 8, 2024
73a3785
specify correct build artifact path
m-nash May 8, 2024
d19dbaf
update paths
m-nash May 9, 2024
925367d
add semver helper
m-nash May 9, 2024
3560fc8
import semver
m-nash May 9, 2024
d75978b
print package info
m-nash May 9, 2024
3cf08a1
set emitter version
m-nash May 9, 2024
2bfa759
temporarily remove the main branch check to test e2e
m-nash May 9, 2024
94d641b
fix reference to language name
m-nash May 9, 2024
1b63395
update to extract api for emitter
m-nash May 9, 2024
28115e4
Merge branch 'main' of https://github.com/Microsoft/typespec into api…
m-nash May 9, 2024
48209a0
fix spelling
m-nash May 9, 2024
e30c166
copy api.json files to build artifacts
m-nash May 9, 2024
1f7ea7f
update file names
m-nash May 9, 2024
ed75bcb
set language to js if its the emitter package
m-nash May 9, 2024
8c25c2f
pass both api.json and _js.json in
m-nash May 9, 2024
0ffd679
typo
m-nash May 9, 2024
6e07ca7
update filter lookup
m-nash May 9, 2024
c8ca9c5
remove temp code
m-nash May 9, 2024
a600e77
testing removing some dev dependencies
m-nash May 10, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions cspell.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ words:
- TCGC
- VITE
- uncollapsed
- nupkg
- Vsts
- tsdoc
ignorePaths:
- "**/node_modules/**"
- "**/dist/**"
Expand Down
38 changes: 38 additions & 0 deletions eng/common/scripts/git-helpers.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# cSpell:ignore Committish
# cSpell:ignore PULLREQUEST
# cSpell:ignore TARGETBRANCH
# cSpell:ignore SOURCECOMMITID
function Get-ChangedFiles {
param (
[string]$SourceCommittish= "${env:SYSTEM_PULLREQUEST_SOURCECOMMITID}",
[string]$TargetCommittish = ("origin/${env:SYSTEM_PULLREQUEST_TARGETBRANCH}" -replace "refs/heads/"),
[string]$DiffPath,
[string]$DiffFilterType = "d"
)
# If ${env:SYSTEM_PULLREQUEST_TARGETBRANCH} is empty, then return empty.
if (!$TargetCommittish -or ($TargetCommittish -eq "origin/")) {
Write-Host "There is no target branch passed in. "
return ""
}

# Add config to disable the quote and encoding on file name.
# Ref: https://github.com/msysgit/msysgit/wiki/Git-for-Windows-Unicode-Support#disable-quoted-file-names
# Ref: https://github.com/msysgit/msysgit/wiki/Git-for-Windows-Unicode-Support#disable-commit-message-transcoding
# Git PR diff: https://docs.github.com/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/about-comparing-branches-in-pull-requests#three-dot-and-two-dot-git-diff-comparisons
$command = "git -c core.quotepath=off -c i18n.logoutputencoding=utf-8 diff `"$TargetCommittish...$SourceCommittish`" --name-only --diff-filter=$DiffFilterType"
if ($DiffPath) {
$command = $command + " -- `'$DiffPath`'"
}
Write-Host $command
$changedFiles = Invoke-Expression -Command $command
if(!$changedFiles) {
Write-Host "No changed files in git diff between $TargetCommittish and $SourceCommittish"
}
else {
Write-Host "Here are the diff files:"
foreach ($file in $changedFiles) {
Write-Host " $file"
}
}
return $changedFiles
}
11 changes: 10 additions & 1 deletion eng/emitters/pipelines/templates/jobs/build-job.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ parameters:
type: boolean
default: false

# Language short name
- name: LanguageShortName
type: string

- name: BuildArtifactName
type: string
default: ""

jobs:
- job: Build_${{ parameters.Os }}_${{ split(parameters.NodeVersion, '.')[0] }}
${{ if eq(parameters.Os, 'linux') }}:
Expand All @@ -62,11 +70,12 @@ jobs:
Publish: ${{ parameters.Publish }}
AdditionalInitializeSteps: ${{ parameters.AdditionalInitializeSteps }}
Packages: ${{ parameters.Packages }}
LanguageShortName: ${{ parameters.LanguageShortName }}
PackagePath: ${{ parameters.PackagePath }}
NodeVersion: ${{ parameters.NodeVersion }}
${{ if parameters.EmitArtifacts }}:
templateContext:
outputs:
- output: pipelineArtifact
path: $(Build.ArtifactStagingDirectory)
artifact: build_artifacts
artifact: ${{ parameters.BuildArtifactName }}
40 changes: 40 additions & 0 deletions eng/emitters/pipelines/templates/jobs/detect-api-changes.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
parameters:
Artifacts: []
BuildArtifactName: ""
LanguageShortName: "Unknown"
DependsOn: ""

jobs:
- job: DetectApiChanges
dependsOn: ${{ parameters.DependsOn }}
pool:
name: $(LINUXPOOL)
image: $(LINUXVMIMAGE)
os: linux
steps:
- download: current
artifact: ${{ parameters.BuildArtifactName }}
displayName: Download build artifacts
- pwsh: |
$apiChangeDetectRequestUrl = "https://apiview.dev/PullRequest/DetectApiChanges"
echo "##vso[task.setvariable variable=ApiChangeDetectRequestUrl]$apiChangeDetectRequestUrl"
displayName: "Set API change detect request URL"
condition: eq(variables['ApiChangeDetectRequestUrl'], '')

- task: Powershell@2
inputs:
filePath: $(Build.SourcesDirectory)/eng/emitters/scripts/Detect-Api-Changes.ps1
arguments: >
-ArtifactList ('${{ convertToJson(parameters.Artifacts) }}' | ConvertFrom-Json | Select-Object Name)
-ArtifactPath $(Agent.BuildDirectory)/${{ parameters.BuildArtifactName }}
-CommitSha '$(Build.SourceVersion)'
-BuildId $(Build.BuildId)
-PullRequestNumber $(System.PullRequest.PullRequestNumber)
-RepoFullName $(Build.Repository.Name)
-APIViewUri $(ApiChangeDetectRequestUrl)
-BuildArtifactName ${{ parameters.BuildArtifactName }}
-DevopsProject $(System.TeamProject)
-LanguageShortName ${{ parameters.LanguageShortName }}
pwsh: true
displayName: Detect API changes
condition: and(succeededOrFailed(), eq(variables['Build.Reason'],'PullRequest'))
10 changes: 10 additions & 0 deletions eng/emitters/pipelines/templates/jobs/test-job.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ parameters:
type: boolean
default: false

# Language short name
- name: LanguageShortName
type: string

- name: BuildArtifactName
type: string
default: ""

jobs:
- job: Test_${{ parameters.Os }}_${{ split(parameters.NodeVersion, '.')[0] }}
${{ if eq(parameters.Os, 'linux') }}:
Expand All @@ -52,7 +60,9 @@ jobs:
parameters:
AdditionalInitializeSteps: ${{ parameters.AdditionalInitializeSteps }}
PackagePath: ${{ parameters.PackagePath }}
LanguageShortName: ${{ parameters.LanguageShortName }}
NodeVersion: $(nodeVersion)
BuildArtifactName: ${{ parameters.BuildArtifactName }}
${{ if ne(length(parameters.TestMatrix), 0) }}:
TestArgs: $(TestArguments)
${{ else }}:
Expand Down
170 changes: 110 additions & 60 deletions eng/emitters/pipelines/templates/stages/emitter-stages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ parameters:
type: object
default: []

- name: LanguageShortName
type: string

- name: HasNugetPackages
type: boolean
default: false

stages:
# Build stage
# Responsible for building the autorest generator and typespec emitter packages
Expand All @@ -84,6 +91,8 @@ stages:
AdditionalInitializeSteps: ${{ parameters.AdditionalInitializeSteps }}
Packages: ${{ parameters.Packages }}
PackagePath: ${{ parameters.PackagePath }}
LanguageShortName: ${{ parameters.LanguageShortName }}
BuildArtifactName: build_artifacts_${{ parameters.LanguageShortName }}
NodeVersion: 20.x
Os: linux
EmitArtifacts: true # Emit artifacts only for the first job
Expand All @@ -95,6 +104,7 @@ stages:
AdditionalInitializeSteps: ${{ parameters.AdditionalInitializeSteps }}
Packages: ${{ parameters.Packages }}
PackagePath: ${{ parameters.PackagePath }}
LanguageShortName: ${{ parameters.LanguageShortName }}
NodeVersion: 18.x
Os: linux
- template: /eng/emitters/pipelines/templates/jobs/build-job.yml
Expand All @@ -105,6 +115,7 @@ stages:
AdditionalInitializeSteps: ${{ parameters.AdditionalInitializeSteps }}
Packages: ${{ parameters.Packages }}
PackagePath: ${{ parameters.PackagePath }}
LanguageShortName: ${{ parameters.LanguageShortName }}
NodeVersion: 20.x
Os: windows
- template: /eng/emitters/pipelines/templates/jobs/build-job.yml
Expand All @@ -115,66 +126,18 @@ stages:
AdditionalInitializeSteps: ${{ parameters.AdditionalInitializeSteps }}
Packages: ${{ parameters.Packages }}
PackagePath: ${{ parameters.PackagePath }}
LanguageShortName: ${{ parameters.LanguageShortName }}
NodeVersion: 18.x
Os: windows

# Publish stage
# Responsible for publishing the packages in `build_artifacts/packages` and producing `emitter-package-lock.json`
# Produces the artifact `publish_artifacts` which contains the following:
# emitter-package-lock.json: Created by calling `npm install` using `build_artifacts/emitter-package.json` and will
# be placed in the `/eng` folder of the sdk repository.
- ${{ if ne(parameters.Publish, 'none') }}:
- stage: ${{ parameters.StagePrefix }}_Publish
displayName: ${{ parameters.StagePrefix }} - Publish
condition: and(succeeded(), ${{ parameters.Condition }})
dependsOn:
- ${{ parameters.DependsOn }}
- ${{ parameters.StagePrefix }}_Build
- ${{ if and(parameters.PublishDependsOnTest, ne(length(parameters.TestMatrix), 0)) }}:
- ${{ parameters.StagePrefix }}_Test
variables:
toolsRepositoryPath: $(Build.SourcesDirectory)
buildArtifactsPath: $(Pipeline.Workspace)/build_artifacts
pool:
name: $(LINUXPOOL)
image: $(LINUXVMIMAGE)
os: linux
jobs:
- job: Publish
steps:
- checkout: self

- download: current
artifact: build_artifacts
displayName: Download build artifacts

# Create authenticated .npmrc file for publishing
- ${{ if eq(parameters.Publish, 'internal') }}:
- template: /eng/emitters/pipelines/templates/steps/create-authenticated-npmrc.yml
parameters:
npmrcPath: $(buildArtifactsPath)/packages/.npmrc
registryUrl: https://pkgs.dev.azure.com/azure-sdk/public/_packaging/azure-sdk-for-js-test-autorest/npm/registry/
- ${{ else }}:
- pwsh: |
"//registry.npmjs.org/:_authToken=$(azure-sdk-npm-token)" | Out-File '.npmrc'
displayName: Authenticate .npmrc for npmjs.org
workingDirectory: $(buildArtifactsPath)/packages

# per package, publishing using appropriate tool
- ${{ each package in parameters.Packages }}:
- ${{ if eq(package.type, 'npm') }}:
- pwsh: |
$file = Resolve-Path "${{ package.file }}"
Write-Host "npm publish $file --verbose --access public --prefix $(buildArtifactsPath)/packages"
npm publish $file --verbose --access public --prefix $(buildArtifactsPath)/packages
displayName: Publish ${{ package.name }}
workingDirectory: $(buildArtifactsPath)/packages

templateContext:
outputs:
- output: pipelineArtifact
path: $(Build.ArtifactStagingDirectory)
artifact: publish_artifacts
- ${{ if eq(parameters.Publish, 'none') }}:
- template: /eng/emitters/pipelines/templates/jobs/detect-api-changes.yml
parameters:
LanguageShortName: ${{ parameters.LanguageShortName }}
DependsOn: Build_linux_20
BuildArtifactName: build_artifacts_${{ parameters.LanguageShortName }}
Artifacts:
- ${{ each package in parameters.Packages }}:
- name: ${{ package.name }}

# Test stage
# Responsible for running unit and functional tests using a matrix passed in as the parameter `TestMatrix`.
Expand All @@ -189,14 +152,16 @@ stages:
- ${{ parameters.StagePrefix }}_Build
variables:
selfRepositoryPath: $(Build.SourcesDirectory)
buildArtifactsPath: $(Pipeline.Workspace)/build_artifacts
buildArtifactsPath: $(Pipeline.Workspace)/build_artifacts_${{ parameters.LanguageShortName }}
jobs:
- ${{ if parameters.UnitTestArgs }}:
- template: /eng/emitters/pipelines/templates/jobs/test-job.yml
parameters:
AdditionalInitializeSteps: ${{ parameters.AdditionalInitializeSteps }}
PackagePath: ${{ parameters.PackagePath }}
TestArgs: ${{ parameters.UnitTestArgs }}
LanguageShortName: ${{ parameters.LanguageShortName }}
BuildArtifactName: build_artifacts_${{ parameters.LanguageShortName }}
NodeVersion: 20.x
Os: linux
EmitArtifacts: true # Emit artifacts only for the first job
Expand All @@ -205,20 +170,26 @@ stages:
AdditionalInitializeSteps: ${{ parameters.AdditionalInitializeSteps }}
PackagePath: ${{ parameters.PackagePath }}
TestArgs: ${{ parameters.UnitTestArgs }}
LanguageShortName: ${{ parameters.LanguageShortName }}
BuildArtifactName: build_artifacts_${{ parameters.LanguageShortName }}
NodeVersion: 18.x
Os: linux
- template: /eng/emitters/pipelines/templates/jobs/test-job.yml
parameters:
AdditionalInitializeSteps: ${{ parameters.AdditionalInitializeSteps }}
PackagePath: ${{ parameters.PackagePath }}
TestArgs: ${{ parameters.UnitTestArgs }}
LanguageShortName: ${{ parameters.LanguageShortName }}
BuildArtifactName: build_artifacts_${{ parameters.LanguageShortName }}
NodeVersion: 20.x
Os: windows
- template: /eng/emitters/pipelines/templates/jobs/test-job.yml
parameters:
AdditionalInitializeSteps: ${{ parameters.AdditionalInitializeSteps }}
PackagePath: ${{ parameters.PackagePath }}
TestArgs: ${{ parameters.UnitTestArgs }}
LanguageShortName: ${{ parameters.LanguageShortName }}
BuildArtifactName: build_artifacts_${{ parameters.LanguageShortName }}
NodeVersion: 18.x
Os: windows

Expand All @@ -234,11 +205,90 @@ stages:
- ${{ parameters.StagePrefix }}_Build
variables:
selfRepositoryPath: $(Build.SourcesDirectory)
buildArtifactsPath: $(Pipeline.Workspace)/build_artifacts
buildArtifactsPath: $(Pipeline.Workspace)/build_artifacts_${{ parameters.LanguageShortName }}
jobs:
- template: /eng/emitters/pipelines/templates/jobs/test-job.yml
parameters:
AdditionalInitializeSteps: ${{ parameters.AdditionalInitializeSteps }}
PackagePath: ${{ parameters.PackagePath }}
LanguageShortName: ${{ parameters.LanguageShortName }}
BuildArtifactName: build_artifacts_${{ parameters.LanguageShortName }}
Os: windows
TestMatrix: ${{ parameters.TestMatrix }}

# Publish stage
# Responsible for publishing the packages in `build_artifacts/packages` and producing `emitter-package-lock.json`
# Produces the artifact `publish_artifacts` which contains the following:
# emitter-package-lock.json: Created by calling `npm install` using `build_artifacts/emitter-package.json` and will
# be placed in the `/eng` folder of the sdk repository.
- ${{ if ne(parameters.Publish, 'none') }}:
- stage: ${{ parameters.StagePrefix }}_Publish
displayName: ${{ parameters.StagePrefix }} - Publish
condition: and(succeeded(), ${{ parameters.Condition }})
dependsOn:
- ${{ parameters.DependsOn }}
- ${{ parameters.StagePrefix }}_Build
- ${{ if and(parameters.PublishDependsOnTest, ne(length(parameters.TestMatrix), 0)) }}:
- ${{ parameters.StagePrefix }}_Test
- ${{ parameters.StagePrefix }}_Regen_Test
variables:
toolsRepositoryPath: $(Build.SourcesDirectory)
buildArtifactsPath: $(Pipeline.Workspace)/build_artifacts_${{ parameters.LanguageShortName }}
pool:
name: $(LINUXPOOL)
image: $(LINUXVMIMAGE)
os: linux
jobs:
- job: Publish
steps:
- checkout: self

- download: current
artifact: build_artifacts_${{ parameters.LanguageShortName }}
displayName: Download build artifacts

# Create authenticated .npmrc file for publishing
- ${{ if eq(parameters.Publish, 'internal') }}:
- template: /eng/emitters/pipelines/templates/steps/create-authenticated-npmrc.yml
parameters:
npmrcPath: $(buildArtifactsPath)/packages/.npmrc
registryUrl: https://pkgs.dev.azure.com/azure-sdk/public/_packaging/azure-sdk-for-js-test-autorest/npm/registry/
- ${{ else }}:
- pwsh: |
"//registry.npmjs.org/:_authToken=$(azure-sdk-npm-token)" | Out-File '.npmrc'
displayName: Authenticate .npmrc for npmjs.org
workingDirectory: $(buildArtifactsPath)/packages

# per package, publishing using appropriate tool
- ${{ each package in parameters.Packages }}:
- ${{ if eq(package.type, 'npm') }}:
- pwsh: |
$file = Resolve-Path "${{ package.file }}"
Write-Host "npm publish $file --verbose --access public --prefix $(buildArtifactsPath)/packages"
npm publish $file --verbose --access public --prefix $(buildArtifactsPath)/packages
displayName: Publish ${{ package.name }}
workingDirectory: $(buildArtifactsPath)/packages
- ${{ if parameters.HasNugetPackages }}:
- task: 1ES.PublishNuget@1
displayName: Publish Nuget packages
inputs:
packagesToPush: $(buildArtifactsPath)/packages/*.nupkg
packageParentPath: $(buildArtifactsPath)/packages
# todo update so we can publish publicly to nuget
publishVstsFeed: "29ec6040-b234-4e31-b139-33dc4287b756/fa8c16a3-dbe0-4de2-a297-03065ec1ba3f"
nuGetFeedType: internal

- template: /eng/emitters/pipelines/templates/steps/create-apireview.yml
parameters:
Artifacts:
- ${{ each package in parameters.Packages }}:
- name: ${{ package.name }}
ArtifactName: build_artifacts_${{ parameters.LanguageShortName }}
ArtifactPath: $(buildArtifactsPath)
LanguageShortName: ${{ parameters.LanguageShortName }}

templateContext:
outputs:
- output: pipelineArtifact
path: $(Build.ArtifactStagingDirectory)
artifact: publish_artifacts
Loading
Loading