Skip to content

Commit db8582d

Browse files
ci: fix broken OpenAPI generation (#1392)
* ci: fix broken OpenAPI generation * ci: add PR for OpenAPI files * docs: clarify comments * Update scripts/git-push-cleanmetadata.ps1 * ci: clarify use of version when creating PR * ci: remove display name from template use * ci update logging * ci: correct the copyfile overwrite parameter * ci: add approval step for OpenAPI before running Kiota generation * ci: update env var name * ci: typings gen does not use open_api * ci: name branch using endpointversion, add clarity for host output * ci: update for supporting builds * ci: add PR title for OpenAPI PRs * ci: add beta openapi approval step
1 parent cf29a38 commit db8582d

File tree

7 files changed

+196
-54
lines changed

7 files changed

+196
-54
lines changed

.azure-pipelines/generation-pipeline.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,10 +298,45 @@ extends:
298298
outputPath: $(cleanOpenAPIFileBetaOutputPath)
299299
cleanMetadataFolder: $(cleanOpenAPIFolderBeta)
300300

301+
# Approval stage for v1 OpenAPI generation. All subsequent stages depending on OpenAPI generation
302+
# will be blocked until approval is granted. Any new stages depending on OpenAPI generation
303+
# should also depend on this approval stage.
304+
- stage: open_api_v1_approval
305+
dependsOn:
306+
- stage_v1_openapi
307+
condition: eq(dependencies.stage_v1_openapi.result, 'Succeeded')
308+
jobs:
309+
- deployment: OpenApiApproval
310+
displayName: 'OpenAPI v1.0 Generation Review'
311+
environment: 'openapi-generation-review'
312+
strategy:
313+
runOnce:
314+
deploy:
315+
steps:
316+
- script: echo "OpenAPI generation approved."
317+
318+
# Approval stage for beta OpenAPI generation. All subsequent stages depending on OpenAPI generation
319+
# will be blocked until approval is granted. Any new stages depending on OpenAPI generation
320+
# should also depend on this approval stage.
321+
- stage: open_api_beta_approval
322+
dependsOn:
323+
- stage_beta_openapi
324+
condition: eq(dependencies.stage_beta_openapi.result, 'Succeeded')
325+
jobs:
326+
- deployment: OpenApiApproval
327+
displayName: 'OpenAPI Beta Generation Review'
328+
environment: 'openapi-generation-review'
329+
strategy:
330+
runOnce:
331+
deploy:
332+
steps:
333+
- script: echo "OpenAPI generation approved."
334+
301335
- stage: stage_csharp_v1_kiota
302336
dependsOn:
303337
- stage_build_and_publish_kiota
304338
- stage_v1_openapi
339+
- open_api_v1_approval
305340
condition: |
306341
and
307342
(
@@ -343,6 +378,7 @@ extends:
343378
dependsOn:
344379
- stage_build_and_publish_kiota
345380
- stage_beta_openapi
381+
- open_api_beta_approval
346382
condition: |
347383
and
348384
(
@@ -384,6 +420,7 @@ extends:
384420
dependsOn:
385421
- stage_build_and_publish_kiota
386422
- stage_v1_openapi
423+
- open_api_v1_approval
387424
condition: |
388425
and
389426
(
@@ -423,6 +460,7 @@ extends:
423460
dependsOn:
424461
- stage_build_and_publish_kiota
425462
- stage_beta_openapi
463+
- open_api_beta_approval
426464
condition: |
427465
and
428466
(
@@ -462,6 +500,7 @@ extends:
462500
dependsOn:
463501
- stage_build_and_publish_kiota
464502
- stage_v1_openapi
503+
- open_api_v1_approval
465504
condition: |
466505
and
467506
(
@@ -503,6 +542,7 @@ extends:
503542
dependsOn:
504543
- stage_build_and_publish_kiota
505544
- stage_beta_openapi
545+
- open_api_beta_approval
506546
condition: |
507547
and
508548
(
@@ -544,6 +584,7 @@ extends:
544584
dependsOn:
545585
- stage_build_and_publish_kiota
546586
- stage_beta_openapi
587+
- open_api_beta_approval
547588
condition: |
548589
and
549590
(
@@ -585,6 +626,7 @@ extends:
585626
dependsOn:
586627
- stage_build_and_publish_kiota
587628
- stage_v1_openapi
629+
- open_api_v1_approval
588630
condition: |
589631
and
590632
(
@@ -700,6 +742,7 @@ extends:
700742
dependsOn:
701743
- stage_build_and_publish_kiota
702744
- stage_v1_openapi
745+
- open_api_v1_approval
703746
condition: |
704747
and
705748
(
@@ -742,6 +785,7 @@ extends:
742785
dependsOn:
743786
- stage_build_and_publish_kiota
744787
- stage_beta_openapi
788+
- open_api_beta_approval
745789
condition: |
746790
and
747791
(
@@ -784,6 +828,7 @@ extends:
784828
dependsOn:
785829
- stage_build_and_publish_kiota
786830
- stage_v1_openapi
831+
- open_api_v1_approval
787832
condition: |
788833
and
789834
(
@@ -824,6 +869,7 @@ extends:
824869
dependsOn:
825870
- stage_build_and_publish_kiota
826871
- stage_beta_openapi
872+
- open_api_beta_approval
827873
condition: |
828874
and
829875
(

.azure-pipelines/generation-templates/capture-metadata.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,9 @@ steps:
166166

167167
# Checkin clean metadata into metadata repo or make it an artifact.
168168
- pwsh: '$(scriptsDirectory)/git-push-cleanmetadata.ps1'
169-
170-
displayName: push clean ${{ parameters.endpoint }} metadata to msgraph-metadata repo
169+
displayName: push clean ${{ parameters.endpoint }} CSDL metadata to msgraph-metadata repo
171170
env:
171+
CreateOpenAPIPR: False
172172
EndpointVersion: ${{ parameters.endpoint }}
173173
PublishChanges: $(publishChanges)
174174
workingDirectory: '$(Build.SourcesDirectory)/msgraph-metadata'

.azure-pipelines/generation-templates/capture-openapi.yml

Lines changed: 57 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# capture-openapi.yml
12
# Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information.
23
# The following template creates multiple artifacts from a matrix, this is the intended behavior to follow the same workflow before the governance migration
34

@@ -21,6 +22,7 @@ jobs:
2122
persistCredentials: true
2223

2324
- template: /.azure-pipelines/generation-templates/checkout-metadata.yml@self
25+
2426
- pwsh: |
2527
$dirPath = "./conversion-settings"
2628
$endpoint = "${{ parameters.endpoint }}"
@@ -37,8 +39,10 @@ jobs:
3739
Write-Host "##vso[task.setvariable variable=targets;isOutput=true]$json"
3840
name: setTargets
3941
workingDirectory: $(Build.SourcesDirectory)/msgraph-metadata
42+
4043
- script: echo $(setTargets.targets)
4144
displayName: "Print settings"
45+
4246
- job: convert_openapi
4347
dependsOn: get_conversion_settings
4448
displayName: Convert
@@ -58,13 +62,12 @@ jobs:
5862
persistCredentials: true
5963

6064
- template: /.azure-pipelines/generation-templates/checkout-metadata.yml@self
61-
6265
# required for the hidi to run
6366
- template: /.azure-pipelines/generation-templates/use-dotnet-sdk.yml@self
6467
parameters:
6568
version: '8.x'
6669

67-
# required for the hidi installation validation
70+
# required for the hidi installation validation
6871
- template: /.azure-pipelines/generation-templates/use-dotnet-sdk.yml@self
6972
parameters:
7073
version: '9.x'
@@ -78,8 +81,13 @@ jobs:
7881
displayName: ensure the generation happens from master latest
7982
workingDirectory: $(Build.SourcesDirectory)/msgraph-metadata
8083
81-
- pwsh: '$(scriptsDirectory)/generate-open-api.ps1 -endpointVersion ${{ parameters.endpoint }} -settings "$(conversionSettingsDirectory)/$(File)" -platformName "$(Name)"'
82-
displayName: 'update ${{ parameters.endpoint }} open API description'
84+
- pwsh: |
85+
Write-Host "`ngit status before generation:"
86+
git status
87+
$(scriptsDirectory)/generate-open-api.ps1 -endpointVersion ${{ parameters.endpoint }} -settings "$(conversionSettingsDirectory)/$(File)" -platformName "$(Name)"
88+
Write-Host "`ngit status after generation:"
89+
git status
90+
displayName: 'generate ${{ parameters.endpoint }} open API description'
8391
workingDirectory: $(Build.SourcesDirectory)/msgraph-metadata
8492
8593
# publish metadata as an artifact
@@ -88,16 +96,16 @@ jobs:
8896
sourceFolder: ${{ parameters.outputPath }}
8997
contents: '**/$(Name).yaml'
9098
targetFolder: '$(Build.ArtifactStagingDirectory)/$(Name)'
91-
displayName: Copy generated metadata
99+
displayName: Copy generated OpenAPI yaml file to ArtifactStagingDirectory
100+
92101
- pwsh: |
93102
./scripts/run-openapi-validation.ps1 -repoDirectory (Get-Location).Path -version "${{ parameters.endpoint }}" -platformName "$(Name)"
94-
displayName: ensure that OpenAPI docs can be parsed
103+
displayName: Validate that OpenAPI docs can be parsed
95104
workingDirectory: $(Build.SourcesDirectory)/msgraph-metadata
96105
97-
98106
- job: publish_openapi
99107
dependsOn: convert_openapi
100-
displayName: Publish
108+
displayName: Publish OpenAPI files
101109
## If there's new settings added please add them here too
102110
templateContext:
103111
inputs:
@@ -123,35 +131,61 @@ jobs:
123131
displayName: checkout generator
124132
fetchDepth: 1
125133
persistCredentials: true
126-
# Copy files from the maxtrix artifacts to a single folder
134+
135+
# Note that msgraph-metadata repo has detached HEAD
136+
- template: /.azure-pipelines/generation-templates/checkout-metadata.yml@self
137+
138+
- template: /.azure-pipelines/generation-templates/set-user-config.yml@self
139+
140+
# Copy OpenAPI files from the matrix artifacts to the ArtifactStagingDirectory
141+
# This is used for library generation later
127142
- task: CopyFiles@2
128143
inputs:
129144
sourceFolder: '$(Build.SourcesDirectory)/artifacts'
130145
contents: '**/*.yaml'
131146
targetFolder: '$(Build.ArtifactStagingDirectory)'
132-
displayName: Copy artifact metadata
133-
# Copy files from the target path where artifacts should be downloaded
147+
displayName: Copy OpenAPI input artifacts to artifact staging directory
148+
149+
# Copy OpenAPI files from ArtifactStagingDirectory to local msgraph-metadata repo
134150
- task: CopyFiles@2
135151
inputs:
136152
sourceFolder: '$(Build.ArtifactStagingDirectory)'
137153
contents: '**/*.yaml'
138154
targetFolder: '$(Build.SourcesDirectory)/msgraph-metadata/openapi/${{ parameters.endpoint }}'
139-
displayName: Copy downloaded metadata
155+
overwrite: true
156+
displayName: Copy OpenAPI files to local msgraph-metadata repo
140157

141-
# publish metadata as an artifact
142-
- task: CopyFiles@2
143-
inputs:
144-
sourceFolder: ${{ parameters.outputPath }}
145-
contents: '**/*.yaml'
146-
targetFolder: '$(Build.ArtifactStagingDirectory)'
147-
displayName: Copy downloaded metadata
148-
- template: /.azure-pipelines/generation-templates/checkout-metadata.yml@self
149-
- template: /.azure-pipelines/generation-templates/set-user-config.yml@self
158+
# Push changes to msgraph-metadata repo
150159
- pwsh: '$(scriptsDirectory)/git-push-cleanmetadata.ps1'
151-
152-
displayName: push clean ${{ parameters.endpoint }} OpenAPI description to msgraph-metadata repo
160+
displayName: Publish ${{ parameters.endpoint }} OpenAPI description to msgraph-metadata repo
153161
env:
162+
CreateOpenAPIPR: True
154163
EndpointVersion: ${{ parameters.endpoint }}
155164
PublishChanges: $(publishChanges)
156165
workingDirectory: '$(Build.SourcesDirectory)/msgraph-metadata'
157166
enabled: true
167+
168+
169+
# Create PR - note that this PR is not used for gating. It's just for discovery purposes.
170+
# Library generation PRs will still be created based on the OpenAPI files.
171+
172+
- task: AzureKeyVault@2
173+
displayName: "Azure Key Vault: Get Secrets"
174+
inputs:
175+
azureSubscription: "Federated AKV Managed Identity Connection"
176+
KeyVaultName: akv-prod-eastus
177+
SecretsFilter: "microsoft-graph-devx-bot-appid,microsoft-graph-devx-bot-privatekey"
178+
179+
- pwsh: '$(scriptsDirectory)/create-pull-request.ps1'
180+
displayName: 'Create Pull Request for the generated OpenAPI files for msgraph-metadata'
181+
env:
182+
BaseBranch: master
183+
GeneratePullRequest: true
184+
GhAppId: $(microsoft-graph-devx-bot-appid)
185+
GhAppKey: $(microsoft-graph-devx-bot-privatekey)
186+
OverrideSkipCI: false
187+
RepoName: 'microsoftgraph/msgraph-metadata'
188+
ScriptsDirectory: $(scriptsDirectory)
189+
# Version is intentionally left empty for OpenAPI PRs as versioning is not applicable in this context.
190+
Version: ''
191+
workingDirectory: '$(Build.SourcesDirectory)/msgraph-metadata'

.azure-pipelines/generation-templates/use-dotnet-sdk.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ parameters:
55

66
steps:
77
- task: UseDotNet@2
8-
displayName: 'Use .NET SDK'
8+
displayName: 'Use .NET SDK ${{ parameters.version }}'
99
inputs:
1010
packageType: sdk
1111
version: ${{ parameters.version }}

scripts/create-pull-request.ps1

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,27 @@
11
if (($env:OverrideSkipCI -eq $False) -and ($env:BUILD_REASON -eq 'Manual')) # Skip CI if manually running this pipeline.
22
{
3-
Write-Host "Skipping pull request creation due Skip CI." -ForegroundColor Green
3+
Write-Host "Skipping pull request creation due Skip CI."
44
return;
55
}
66

77
if (($env:GeneratePullRequest -eq $False)) { # Skip CI if manually running this pipeline.
8-
Write-Host "Skipping pull request creation due this repository being disabled" -ForegroundColor Green
8+
Write-Host "Skipping pull request creation due this repository being disabled"
99
return;
1010
}
1111

12-
# Special case for beta typings as it uses a non-conforming preview versioning.
12+
# Special case for beta typings as it uses a non-conforming preview versioning. Helps with triggering Release Please.
1313
if ($env:RepoName.Contains("msgraph-beta-typescript-typings"))
1414
{
15-
$title = "feat: generated $version models and request builders"
15+
$title = "feat: generated $env:Version models and request builders"
16+
}
17+
elseif ($env:RepoName.Contains("msgraph-metadata")) # we are only generating OpenAPI PRs for the metadata repo
18+
{
19+
$title = "Generated $env:Version OpenAPI descriptions"
1620
}
1721
else {
18-
$title = "Generated $version models and request builders"
22+
$title = "Generated $env:Version models and request builders"
1923
}
2024

21-
$version = $env:Version
2225
$body = ":bangbang:**_Important_**:bangbang: <br> Check for unexpected deletions or changes in this PR and ensure relevant CI checks are passing. <br><br> **Note:** This pull request was automatically created by Azure pipelines."
2326
$baseBranchParameter = ""
2427

@@ -30,10 +33,10 @@ if (![string]::IsNullOrEmpty($env:BaseBranch))
3033
# The installed application is required to have the following permissions: read/write on pull requests/
3134
$tokenGenerationScript = "$env:ScriptsDirectory\Generate-Github-Token.ps1"
3235
$env:GITHUB_TOKEN = & $tokenGenerationScript -AppClientId $env:GhAppId -AppPrivateKeyContents $env:GhAppKey -Repository $env:RepoName
33-
Write-Host "Fetched Github Token for PR generation and set as environment variable." -ForegroundColor Green
36+
Write-Host "Fetched Github Token for PR generation and set as environment variable."
3437

3538
# No need to specify reviewers as code owners should be added automatically.
3639
Invoke-Expression "gh auth login" # login to GitHub
3740
Invoke-Expression "gh pr create -t ""$title"" -b ""$body"" $baseBranchParameter | Write-Host"
3841

39-
Write-Host "Pull Request Created successfully." -ForegroundColor Green
42+
Write-Host "Pull Request Created successfully."

0 commit comments

Comments
 (0)