Skip to content

Commit a4fdada

Browse files
committed
ci: fix broken OpenAPI generation
1 parent cf29a38 commit a4fdada

File tree

2 files changed

+74
-36
lines changed

2 files changed

+74
-36
lines changed

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

Lines changed: 33 additions & 25 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,28 +62,33 @@ 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'
66-
67-
# required for the hidi installation validation
69+
displayName: use dotnet sdk 8.x
70+
# required for the hidi installation validation
6871
- template: /.azure-pipelines/generation-templates/use-dotnet-sdk.yml@self
6972
parameters:
7073
version: '9.x'
74+
displayName: use dotnet sdk 9.x
7175

7276
- pwsh: dotnet tool install --global Microsoft.OpenApi.Hidi --version 1.6.24
7377
displayName: install hidi
7478

7579
- pwsh: |
76-
git fetch origin master
77-
git switch master
80+
git fetch origin master | Write-Host -ForegroundColor Yellow
81+
git switch master | Write-Host -ForegroundColor Yellow
7882
displayName: ensure the generation happens from master latest
7983
workingDirectory: $(Build.SourcesDirectory)/msgraph-metadata
8084
81-
- pwsh: '$(scriptsDirectory)/generate-open-api.ps1 -endpointVersion ${{ parameters.endpoint }} -settings "$(conversionSettingsDirectory)/$(File)" -platformName "$(Name)"'
82-
displayName: 'update ${{ parameters.endpoint }} open API description'
85+
- pwsh: |
86+
Write-Host "`nGet status before generation:" -ForegroundColor Green
87+
git status | Write-Host -ForegroundColor Yellow
88+
$(scriptsDirectory)/generate-open-api.ps1 -endpointVersion ${{ parameters.endpoint }} -settings "$(conversionSettingsDirectory)/$(File)" -platformName "$(Name)"
89+
Write-Host "`nGet status after generation:" -ForegroundColor Green
90+
git status | Write-Host -ForegroundColor Yellow
91+
displayName: 'generate ${{ parameters.endpoint }} open API description'
8392
workingDirectory: $(Build.SourcesDirectory)/msgraph-metadata
8493
8594
# publish metadata as an artifact
@@ -88,16 +97,16 @@ jobs:
8897
sourceFolder: ${{ parameters.outputPath }}
8998
contents: '**/$(Name).yaml'
9099
targetFolder: '$(Build.ArtifactStagingDirectory)/$(Name)'
91-
displayName: Copy generated metadata
100+
displayName: Copy generated OpenAPI yaml file to ArtifactStagingDirectory
101+
92102
- pwsh: |
93103
./scripts/run-openapi-validation.ps1 -repoDirectory (Get-Location).Path -version "${{ parameters.endpoint }}" -platformName "$(Name)"
94-
displayName: ensure that OpenAPI docs can be parsed
104+
displayName: Validate that OpenAPI docs can be parsed
95105
workingDirectory: $(Build.SourcesDirectory)/msgraph-metadata
96106
97-
98107
- job: publish_openapi
99108
dependsOn: convert_openapi
100-
displayName: Publish
109+
displayName: Publish OpenAPI files
101110
## If there's new settings added please add them here too
102111
templateContext:
103112
inputs:
@@ -123,32 +132,31 @@ jobs:
123132
displayName: checkout generator
124133
fetchDepth: 1
125134
persistCredentials: true
126-
# Copy files from the maxtrix artifacts to a single folder
135+
136+
# Note that msgraph-metadata repo has detached HEAD
137+
- template: /.azure-pipelines/generation-templates/checkout-metadata.yml@self
138+
139+
- template: /.azure-pipelines/generation-templates/set-user-config.yml@self
140+
141+
# Copy OpenAPI files from the matrix artifacts to the ArtifactStagingDirectory
142+
# This is used for library generation later
127143
- task: CopyFiles@2
128144
inputs:
129145
sourceFolder: '$(Build.SourcesDirectory)/artifacts'
130146
contents: '**/*.yaml'
131147
targetFolder: '$(Build.ArtifactStagingDirectory)'
132-
displayName: Copy artifact metadata
133-
# Copy files from the target path where artifacts should be downloaded
148+
displayName: Copy OpenAPI input artifacts to artifact staging directory
149+
150+
# Copy OpenAPI files from ArtifactStagingDirectory to local msgraph-metadata repo
134151
- task: CopyFiles@2
135152
inputs:
136153
sourceFolder: '$(Build.ArtifactStagingDirectory)'
137154
contents: '**/*.yaml'
138155
targetFolder: '$(Build.SourcesDirectory)/msgraph-metadata/openapi/${{ parameters.endpoint }}'
139-
displayName: Copy downloaded metadata
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-
152160
displayName: push clean ${{ parameters.endpoint }} OpenAPI description to msgraph-metadata repo
153161
env:
154162
EndpointVersion: ${{ parameters.endpoint }}

scripts/git-push-cleanmetadata.ps1

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,61 @@
1+
# git-push-cleanmetadata.ps1
2+
# Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the
3+
# project root for license information.
4+
5+
# This script stashes any changes, checks out the latest master branch, applies the stashed changes, commits, and
6+
# pushes the changes back to the remote repository.
7+
18
if ($env:PublishChanges -eq $False)
29
{
3-
Write-Host "Not publishing changes per the run parameter!" -ForegroundColor Green
10+
Write-Host "Not publishing changes per the run parameter!" -ForegroundColor Red
411
return;
512
}
613

7-
Write-Host "About to add clean $env:EndpointVersion metadata file....."
14+
Write-Host "`nGet status:" -ForegroundColor Green
15+
git status | Write-Host -ForegroundColor Yellow
16+
17+
Write-Host "`nStash the update metadata files.....`nRunning: git stash" -ForegroundColor Green
18+
git stash | Write-Host -ForegroundColor Yellow
819

9-
git fetch origin master
20+
Write-Host "`nFetching latest master branch to ensure we are up to date..." -ForegroundColor Green
21+
git fetch origin master | Write-Host -ForegroundColor Yellow
1022
# checkout master to move from detached HEAD mode
11-
git switch master
23+
git switch master | Write-Host -ForegroundColor Yellow
24+
25+
Write-Host "`nGet status:" -ForegroundColor Green
26+
git status | Write-Host -ForegroundColor Yellow
27+
28+
Write-Host "`nApply stashed metadata files...`nRunning: git stash pop" -ForegroundColor Green
29+
git stash pop | Write-Host -ForegroundColor Yellow
30+
31+
Write-Host "`nGet status:" -ForegroundColor Green
32+
git status | Write-Host -ForegroundColor Yellow
33+
34+
Write-Host "`nStaging clean $env:EndpointVersion metadata files....." -ForegroundColor Green
35+
git add . | Write-Host -ForegroundColor Yellow
36+
37+
Write-Host "`nGet status:" -ForegroundColor Green
38+
git status | Write-Host -ForegroundColor Yellow
39+
40+
Write-Host "`nAttempting to commit clean $env:EndpointVersion metadata files....." -ForegroundColor Green
1241

13-
git add . | Write-Host
1442
if ($env:BUILD_REASON -eq 'Manual') # Skip CI if manually running this pipeline.
1543
{
16-
git commit -m "Update clean metadata file with $env:BUILD_BUILDID [skip ci]" | Write-Host
44+
git commit -m "Update clean metadata file with $env:BUILD_BUILDID [skip ci]" | Write-Host -ForegroundColor Yellow
1745
}
1846
else
1947
{
20-
git commit -m "Update clean metadata file with $env:BUILD_BUILDID" | Write-Host
48+
git commit -m "Update clean metadata file with $env:BUILD_BUILDID" | Write-Host -ForegroundColor Yellow
2149
}
2250

23-
Write-Host "Added and commited cleaned $env:EndpointVersion metadata." -ForegroundColor Green
51+
Write-Host "`nGet status:" -ForegroundColor Green
52+
git status | Write-Host -ForegroundColor Yellow
2453

54+
Write-Host "`nRunning: git pull origin master --rebase..." -ForegroundColor Green
2555
# sync branch before pushing
2656
# this is especially important while running v1 and beta in parallel
2757
# and one process goes out of sync because of the other's check-in
28-
git pull origin master --rebase
58+
git pull origin master --rebase | Write-Host -ForegroundColor Yellow
2959

30-
git push --set-upstream origin master | Write-Host
31-
Write-Host "Pushed the results of the build $env:BUILD_BUILDID to the master branch." -ForegroundColor Green
60+
Write-Host "`nRunning: git push --set-upstream origin master ..." -ForegroundColor Green
61+
git push --set-upstream origin master | Write-Host -ForegroundColor Yellow

0 commit comments

Comments
 (0)