Skip to content

Commit 3a4373a

Browse files
Merge pull request #1393 from microsoftgraph/dev
Fix broken OpenAPI generation
2 parents 29a4ab4 + d1221a0 commit 3a4373a

File tree

8 files changed

+205
-59
lines changed

8 files changed

+205
-59
lines changed

.azure-pipelines/generation-pipeline.yml

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,15 @@
33
trigger: none
44
pr: none
55
schedules:
6-
- cron: '0 10 * * TUE'
7-
displayName: Tuesday generation (PST 2am, EST 5am, EAT 3pm)
6+
7+
# Minute: 0 → At the start of the hour.
8+
# Hour: 10 → 10:00 AM UTC.
9+
# Day of Month: 1-7,15-21 → On the 1st–7th and 15th–21st.
10+
# Month: * → Every month.
11+
# Weekday: TUE → Only on Tuesdays.
12+
# This cron will run bi-weekly unless the month has 5 Tuesdays, in which case it will skip the 5th Tuesday (won't be bi-weekly that month).
13+
- cron: '0 10 1-7,15-21 * TUE'
14+
displayName: Bi-weekly Tuesday generation (1st and 3rd Tuesday, PST 2am, EST 5am, EAT 3pm)
815
branches:
916
include:
1017
- main
@@ -291,10 +298,45 @@ extends:
291298
outputPath: $(cleanOpenAPIFileBetaOutputPath)
292299
cleanMetadataFolder: $(cleanOpenAPIFolderBeta)
293300

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+
294335
- stage: stage_csharp_v1_kiota
295336
dependsOn:
296337
- stage_build_and_publish_kiota
297338
- stage_v1_openapi
339+
- open_api_v1_approval
298340
condition: |
299341
and
300342
(
@@ -336,6 +378,7 @@ extends:
336378
dependsOn:
337379
- stage_build_and_publish_kiota
338380
- stage_beta_openapi
381+
- open_api_beta_approval
339382
condition: |
340383
and
341384
(
@@ -377,6 +420,7 @@ extends:
377420
dependsOn:
378421
- stage_build_and_publish_kiota
379422
- stage_v1_openapi
423+
- open_api_v1_approval
380424
condition: |
381425
and
382426
(
@@ -416,6 +460,7 @@ extends:
416460
dependsOn:
417461
- stage_build_and_publish_kiota
418462
- stage_beta_openapi
463+
- open_api_beta_approval
419464
condition: |
420465
and
421466
(
@@ -455,6 +500,7 @@ extends:
455500
dependsOn:
456501
- stage_build_and_publish_kiota
457502
- stage_v1_openapi
503+
- open_api_v1_approval
458504
condition: |
459505
and
460506
(
@@ -496,6 +542,7 @@ extends:
496542
dependsOn:
497543
- stage_build_and_publish_kiota
498544
- stage_beta_openapi
545+
- open_api_beta_approval
499546
condition: |
500547
and
501548
(
@@ -537,6 +584,7 @@ extends:
537584
dependsOn:
538585
- stage_build_and_publish_kiota
539586
- stage_beta_openapi
587+
- open_api_beta_approval
540588
condition: |
541589
and
542590
(
@@ -578,6 +626,7 @@ extends:
578626
dependsOn:
579627
- stage_build_and_publish_kiota
580628
- stage_v1_openapi
629+
- open_api_v1_approval
581630
condition: |
582631
and
583632
(
@@ -693,6 +742,7 @@ extends:
693742
dependsOn:
694743
- stage_build_and_publish_kiota
695744
- stage_v1_openapi
745+
- open_api_v1_approval
696746
condition: |
697747
and
698748
(
@@ -735,6 +785,7 @@ extends:
735785
dependsOn:
736786
- stage_build_and_publish_kiota
737787
- stage_beta_openapi
788+
- open_api_beta_approval
738789
condition: |
739790
and
740791
(
@@ -777,6 +828,7 @@ extends:
777828
dependsOn:
778829
- stage_build_and_publish_kiota
779830
- stage_v1_openapi
831+
- open_api_v1_approval
780832
condition: |
781833
and
782834
(
@@ -817,6 +869,7 @@ extends:
817869
dependsOn:
818870
- stage_build_and_publish_kiota
819871
- stage_beta_openapi
872+
- open_api_beta_approval
820873
condition: |
821874
and
822875
(

.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: 54 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

@@ -58,13 +59,12 @@ jobs:
5859
persistCredentials: true
5960

6061
- template: /.azure-pipelines/generation-templates/checkout-metadata.yml@self
61-
6262
# required for the hidi to run
6363
- template: /.azure-pipelines/generation-templates/use-dotnet-sdk.yml@self
6464
parameters:
6565
version: '8.x'
6666

67-
# required for the hidi installation validation
67+
# required for the hidi installation validation
6868
- template: /.azure-pipelines/generation-templates/use-dotnet-sdk.yml@self
6969
parameters:
7070
version: '9.x'
@@ -78,8 +78,13 @@ jobs:
7878
displayName: ensure the generation happens from master latest
7979
workingDirectory: $(Build.SourcesDirectory)/msgraph-metadata
8080
81-
- pwsh: '$(scriptsDirectory)/generate-open-api.ps1 -endpointVersion ${{ parameters.endpoint }} -settings "$(conversionSettingsDirectory)/$(File)" -platformName "$(Name)"'
82-
displayName: 'update ${{ parameters.endpoint }} open API description'
81+
- pwsh: |
82+
Write-Host "`ngit status before generation:"
83+
git status
84+
$(scriptsDirectory)/generate-open-api.ps1 -endpointVersion ${{ parameters.endpoint }} -settings "$(conversionSettingsDirectory)/$(File)" -platformName "$(Name)"
85+
Write-Host "`ngit status after generation:"
86+
git status
87+
displayName: 'generate ${{ parameters.endpoint }} open API description'
8388
workingDirectory: $(Build.SourcesDirectory)/msgraph-metadata
8489
8590
# publish metadata as an artifact
@@ -88,16 +93,16 @@ jobs:
8893
sourceFolder: ${{ parameters.outputPath }}
8994
contents: '**/$(Name).yaml'
9095
targetFolder: '$(Build.ArtifactStagingDirectory)/$(Name)'
91-
displayName: Copy generated metadata
96+
displayName: Copy generated OpenAPI yaml file to ArtifactStagingDirectory
97+
9298
- pwsh: |
9399
./scripts/run-openapi-validation.ps1 -repoDirectory (Get-Location).Path -version "${{ parameters.endpoint }}" -platformName "$(Name)"
94-
displayName: ensure that OpenAPI docs can be parsed
100+
displayName: Validate that OpenAPI docs can be parsed
95101
workingDirectory: $(Build.SourcesDirectory)/msgraph-metadata
96102
97-
98103
- job: publish_openapi
99104
dependsOn: convert_openapi
100-
displayName: Publish
105+
displayName: Publish OpenAPI files
101106
## If there's new settings added please add them here too
102107
templateContext:
103108
inputs:
@@ -123,35 +128,61 @@ jobs:
123128
displayName: checkout generator
124129
fetchDepth: 1
125130
persistCredentials: true
126-
# Copy files from the maxtrix artifacts to a single folder
131+
132+
# Note that msgraph-metadata repo has detached HEAD
133+
- template: /.azure-pipelines/generation-templates/checkout-metadata.yml@self
134+
135+
- template: /.azure-pipelines/generation-templates/set-user-config.yml@self
136+
137+
# Copy OpenAPI files from the matrix artifacts to the ArtifactStagingDirectory
138+
# This is used for library generation later
127139
- task: CopyFiles@2
128140
inputs:
129141
sourceFolder: '$(Build.SourcesDirectory)/artifacts'
130142
contents: '**/*.yaml'
131143
targetFolder: '$(Build.ArtifactStagingDirectory)'
132-
displayName: Copy artifact metadata
133-
# Copy files from the target path where artifacts should be downloaded
144+
displayName: Copy OpenAPI input artifacts to artifact staging directory
145+
146+
# Copy OpenAPI files from ArtifactStagingDirectory to local msgraph-metadata repo
134147
- task: CopyFiles@2
135148
inputs:
136149
sourceFolder: '$(Build.ArtifactStagingDirectory)'
137150
contents: '**/*.yaml'
138151
targetFolder: '$(Build.SourcesDirectory)/msgraph-metadata/openapi/${{ parameters.endpoint }}'
139-
displayName: Copy downloaded metadata
152+
overwrite: true
153+
displayName: Copy OpenAPI files to local msgraph-metadata repo
140154

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
155+
# Push changes to msgraph-metadata repo
150156
- pwsh: '$(scriptsDirectory)/git-push-cleanmetadata.ps1'
151-
152-
displayName: push clean ${{ parameters.endpoint }} OpenAPI description to msgraph-metadata repo
157+
displayName: Publish ${{ parameters.endpoint }} OpenAPI description to msgraph-metadata repo
153158
env:
159+
CreateOpenAPIPR: True
154160
EndpointVersion: ${{ parameters.endpoint }}
155161
PublishChanges: $(publishChanges)
156162
workingDirectory: '$(Build.SourcesDirectory)/msgraph-metadata'
157163
enabled: true
164+
165+
166+
# Create PR - note that this PR is not used for gating. It's just for discovery purposes.
167+
# Library generation PRs will still be created based on the OpenAPI files.
168+
169+
- task: AzureKeyVault@2
170+
displayName: "Azure Key Vault: Get Secrets"
171+
inputs:
172+
azureSubscription: "Federated AKV Managed Identity Connection"
173+
KeyVaultName: akv-prod-eastus
174+
SecretsFilter: "microsoft-graph-devx-bot-appid,microsoft-graph-devx-bot-privatekey"
175+
176+
- pwsh: '$(scriptsDirectory)/create-pull-request.ps1'
177+
displayName: 'Create Pull Request for the generated OpenAPI files for msgraph-metadata'
178+
env:
179+
BaseBranch: master
180+
GeneratePullRequest: true
181+
GhAppId: $(microsoft-graph-devx-bot-appid)
182+
GhAppKey: $(microsoft-graph-devx-bot-privatekey)
183+
OverrideSkipCI: false
184+
RepoName: 'microsoftgraph/msgraph-metadata'
185+
ScriptsDirectory: $(scriptsDirectory)
186+
# Version is intentionally left empty for OpenAPI PRs as versioning is not applicable in this context.
187+
Version: ''
188+
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 }}

.github/workflows/codeql.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ jobs:
5252

5353
# Initializes the CodeQL tools for scanning.
5454
- name: Initialize CodeQL
55-
uses: github/codeql-action/init@v3
55+
uses: github/codeql-action/init@v4
5656
with:
5757
languages: ${{ matrix.language }}
5858
# If you wish to specify custom queries, you can do so here or in a config file.
@@ -66,7 +66,7 @@ jobs:
6666
# Autobuild attempts to build any compiled languages (C/C++, C#, Go, Java, or Swift).
6767
# If this step fails, then you should remove it and run the build manually (see below)
6868
- name: Autobuild
69-
uses: github/codeql-action/autobuild@v3
69+
uses: github/codeql-action/autobuild@v4
7070
with:
7171
working-directory: ${{ github.workspace }}/src/Typewriter
7272

@@ -81,6 +81,6 @@ jobs:
8181
# ./location_of_script_within_repo/buildscript.sh
8282

8383
- name: Perform CodeQL Analysis
84-
uses: github/codeql-action/analyze@v3
84+
uses: github/codeql-action/analyze@v4
8585
with:
8686
category: "/language:${{matrix.language}}"

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)