-
Notifications
You must be signed in to change notification settings - Fork 75
Expand file tree
/
Copy pathcapture-openapi.yml
More file actions
188 lines (169 loc) · 7.39 KB
/
capture-openapi.yml
File metadata and controls
188 lines (169 loc) · 7.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
# capture-openapi.yml
# Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information.
# The following template creates multiple artifacts from a matrix, this is the intended behavior to follow the same workflow before the governance migration
# For more information please refer to: https://github.com/microsoftgraph/MSGraph-SDK-Code-Generator/pull/1377#discussion_r2271024012
parameters:
- name: 'endpoint'
type: string
default: "v1.0"
- name: 'outputPath'
type: string
default: $(System.ArtifactsDirectory)
- name: 'cleanMetadataFolder'
type: string
jobs:
- job: get_conversion_settings
displayName: "Get conversion settings"
steps:
- checkout: self
displayName: checkout generator
fetchDepth: 1
persistCredentials: true
- template: /.azure-pipelines/generation-templates/checkout-metadata.yml@self
- pwsh: |
$dirPath = "./conversion-settings"
$endpoint = "${{ parameters.endpoint }}"
Write-Host "endpoint: $endpoint"
Write-Host "directory path: $dirPath"
$jsonBase = @{}
foreach ($f in Get-ChildItem $dirPath -Recurse -Include *.json) {
$name = $f.Name.replace('.json','')
$data = @{"File"=$f.Name;"Name"=$name;}
$key = "$endpoint-$name"
$jsonBase.Add($key,$data)
}
$json = $jsonBase | ConvertTo-Json -Compress
Write-Host "##vso[task.setvariable variable=targets;isOutput=true]$json"
name: setTargets
workingDirectory: $(Build.SourcesDirectory)/msgraph-metadata
- script: echo $(setTargets.targets)
displayName: "Print settings"
- job: convert_openapi
dependsOn: get_conversion_settings
displayName: Convert
strategy:
matrix: $[ dependencies.get_conversion_settings.outputs['setTargets.targets'] ]
variables:
targets: $[ dependencies.get_conversion_settings.outputs['setTargets.targets'] ]
templateContext:
outputs:
- output: pipelineArtifact
targetPath: '$(Build.ArtifactStagingDirectory)/$(Name)'
artifactName: '${{ parameters.cleanMetadataFolder }}-$(Name)'
steps:
- checkout: self
displayName: checkout generator
fetchDepth: 1
persistCredentials: true
- template: /.azure-pipelines/generation-templates/checkout-metadata.yml@self
# required for the hidi to run
- template: /.azure-pipelines/generation-templates/use-dotnet-sdk.yml@self
parameters:
version: '8.x'
# required for the hidi installation validation
- template: /.azure-pipelines/generation-templates/use-dotnet-sdk.yml@self
parameters:
version: '9.x'
- pwsh: dotnet tool install --global Microsoft.OpenApi.Hidi --version 1.6.24
displayName: install hidi
- pwsh: |
git fetch origin master
git switch master
displayName: ensure the generation happens from master latest
workingDirectory: $(Build.SourcesDirectory)/msgraph-metadata
- pwsh: |
Write-Host "`ngit status before generation:"
git status
$(scriptsDirectory)/generate-open-api.ps1 -endpointVersion ${{ parameters.endpoint }} -settings "$(conversionSettingsDirectory)/$(File)" -platformName "$(Name)"
Write-Host "`ngit status after generation:"
git status
displayName: 'generate ${{ parameters.endpoint }} open API description'
workingDirectory: $(Build.SourcesDirectory)/msgraph-metadata
# publish metadata as an artifact
- task: CopyFiles@2
inputs:
sourceFolder: ${{ parameters.outputPath }}
contents: '**/$(Name).yaml'
targetFolder: '$(Build.ArtifactStagingDirectory)/$(Name)'
displayName: Copy generated OpenAPI yaml file to ArtifactStagingDirectory
- pwsh: |
./scripts/run-openapi-validation.ps1 -repoDirectory (Get-Location).Path -version "${{ parameters.endpoint }}" -platformName "$(Name)"
displayName: Validate that OpenAPI docs can be parsed
workingDirectory: $(Build.SourcesDirectory)/msgraph-metadata
- job: publish_openapi
dependsOn: convert_openapi
displayName: Publish OpenAPI files
## If there's new settings added please add them here too
templateContext:
inputs:
- input: pipelineArtifact
artifactName: '${{ parameters.cleanMetadataFolder }}-default'
targetPath: '$(Build.SourcesDirectory)/artifacts'
- input: pipelineArtifact
artifactName: '${{ parameters.cleanMetadataFolder }}-graphexplorer'
targetPath: '$(Build.SourcesDirectory)/artifacts'
- input: pipelineArtifact
artifactName: '${{ parameters.cleanMetadataFolder }}-openapi'
targetPath: '$(Build.SourcesDirectory)/artifacts'
- input: pipelineArtifact
artifactName: '${{ parameters.cleanMetadataFolder }}-powershell_v2'
targetPath: '$(Build.SourcesDirectory)/artifacts'
outputs:
- output: pipelineArtifact
targetPath: '$(Build.ArtifactStagingDirectory)'
artifactName: ${{ parameters.cleanMetadataFolder }}
steps:
# We only need the scripts
- checkout: self
displayName: checkout generator
fetchDepth: 1
persistCredentials: true
# Note that msgraph-metadata repo has detached HEAD
- template: /.azure-pipelines/generation-templates/checkout-metadata.yml@self
- template: /.azure-pipelines/generation-templates/set-user-config.yml@self
# Copy OpenAPI files from the matrix artifacts to the ArtifactStagingDirectory
# This is used for library generation later
- task: CopyFiles@2
inputs:
sourceFolder: '$(Build.SourcesDirectory)/artifacts'
contents: '**/*.yaml'
targetFolder: '$(Build.ArtifactStagingDirectory)'
displayName: Copy OpenAPI input artifacts to artifact staging directory
# Copy OpenAPI files from ArtifactStagingDirectory to local msgraph-metadata repo
- task: CopyFiles@2
inputs:
sourceFolder: '$(Build.ArtifactStagingDirectory)'
contents: '**/*.yaml'
targetFolder: '$(Build.SourcesDirectory)/msgraph-metadata/openapi/${{ parameters.endpoint }}'
overwrite: true
displayName: Copy OpenAPI files to local msgraph-metadata repo
# Push changes to msgraph-metadata repo
- pwsh: '$(scriptsDirectory)/git-push-cleanmetadata.ps1'
displayName: Publish ${{ parameters.endpoint }} OpenAPI description to msgraph-metadata repo
env:
CreateOpenAPIPR: True
EndpointVersion: ${{ parameters.endpoint }}
PublishChanges: $(publishChanges)
workingDirectory: '$(Build.SourcesDirectory)/msgraph-metadata'
enabled: true
# Create PR - note that this PR is not used for gating. It's just for discovery purposes.
# Library generation PRs will still be created based on the OpenAPI files.
- task: AzureKeyVault@2
displayName: "Azure Key Vault: Get Secrets"
inputs:
azureSubscription: "Federated AKV Managed Identity Connection"
KeyVaultName: akv-prod-eastus
SecretsFilter: "microsoft-graph-devx-bot-appid,microsoft-graph-devx-bot-privatekey"
- pwsh: '$(scriptsDirectory)/create-pull-request.ps1'
displayName: 'Create Pull Request for the generated OpenAPI files for msgraph-metadata'
env:
BaseBranch: master
GeneratePullRequest: true
GhAppId: $(microsoft-graph-devx-bot-appid)
GhAppKey: $(microsoft-graph-devx-bot-privatekey)
OverrideSkipCI: false
RepoName: 'microsoftgraph/msgraph-metadata'
ScriptsDirectory: $(scriptsDirectory)
# Version is intentionally left empty for OpenAPI PRs as versioning is not applicable in this context.
Version: ''
workingDirectory: '$(Build.SourcesDirectory)/msgraph-metadata'