Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
55 changes: 55 additions & 0 deletions .azure-pipelines/generation-pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,13 @@ variables:
cleanOpenAPIFolderV1: 'clean_v10_openapi'
rawMetadataFileBeta: '$(Build.SourcesDirectory)/msgraph-metadata/schemas/beta-Prod.csdl'
rawMetadataFileV1: '$(Build.SourcesDirectory)/msgraph-metadata/schemas/v1.0-Prod.csdl'
rawMetadataFileFairfaxV1: '$(Build.SourcesDirectory)/msgraph-metadata/schemas/v1.0-Fairfax.csdl'
cleanMetadataFolderFairfaxV1: 'clean_v10_fairfax_metadata'
cleanMetadataFileFairfaxV1OutputPath: '$(Build.SourcesDirectory)/msgraph-metadata/clean_v10_fairfax_metadata/'
cleanMetadataFileFairfaxV1: '$(Build.SourcesDirectory)/msgraph-metadata/clean_v10_fairfax_metadata/cleanMetadataWithDescriptionsv1.0.xml'
cleanMetadataFileWithAnnotationsFairfaxV1: '$(Build.SourcesDirectory)/msgraph-metadata/clean_v10_fairfax_metadata/cleanMetadataWithDescriptionsAndAnnotationsv1.0.xml'
cleanOpenAPIFolderFairfaxV1: 'clean_v10_fairfax_openapi'
cleanOpenAPIFileFairfaxV1OutputPath: '$(Build.SourcesDirectory)/msgraph-metadata/openapi/fairfax/v1.0/'
typewriterDirectory: '$(Build.SourcesDirectory)/typewriter'
kiotaDirectory: '$(Build.SourcesDirectory)/kiota'
typewriterExecutable: '$(typewriterDirectory)/Typewriter'
Expand Down Expand Up @@ -283,6 +290,54 @@ extends:
cleanMetadataFileWithAnnotations: $(cleanMetadataFileWithAnnotationsBeta)
metadataTypeSpecAnnotationsSource: $(metadataTypeSpecAnnotationsSource)

- stage: stage_fairfax_v1_metadata
dependsOn: stage_build_and_publish_typewriter
condition: |
and(succeeded('stage_build_and_publish_typewriter'),
eq( ${{ parameters.skipMetadataCaptureAndClean }}, false))
jobs:
- job: fairfax_v1_metadata
templateContext:
outputs:
- output: pipelineArtifact
targetPath: '$(Build.ArtifactStagingDirectory)'
artifactName: $(cleanMetadataFolderFairfaxV1)
inputs:
- input: pipelineArtifact
buildType: 'current'
artifactName: 'typewriter'
targetPath: '$(Build.SourcesDirectory)/typewriter'
steps:
- template: /.azure-pipelines/generation-templates/capture-metadata.yml@self
parameters:
endpoint: 'v1.0'
cloud: Fairfax
inputMetadata: $(rawMetadataFileFairfaxV1)
outputPath: $(cleanMetadataFileFairfaxV1OutputPath)
cleanMetadataFile: $(cleanMetadataFileFairfaxV1)
cleanMetadataFolder: $(cleanMetadataFolderFairfaxV1)
cleanMetadataFileWithAnnotations: $(cleanMetadataFileWithAnnotationsFairfaxV1)
metadataTypeSpecAnnotationsSource: $(metadataTypeSpecAnnotationsSource)

- stage: stage_fairfax_v1_openapi
dependsOn: stage_fairfax_v1_metadata
condition: and(in(dependencies.stage_fairfax_v1_metadata.result, 'Succeeded', 'Skipped'), eq( ${{ parameters.skipOpenApiCaptureAndClean }}, false))
jobs:
- template: /.azure-pipelines/generation-templates/capture-openapi.yml@self
parameters:
endpoint: 'v1.0'
cloud: Fairfax
outputPath: $(cleanOpenAPIFileFairfaxV1OutputPath)
cleanMetadataFolder: $(cleanOpenAPIFolderFairfaxV1)
${{ if eq(parameters.skipMetadataCaptureAndClean, false) }}:
metadataArtifact: $(cleanMetadataFolderFairfaxV1)
metadataDirectory: '$(Pipeline.Workspace)/$(cleanMetadataFolderFairfaxV1)'
${{ else }}:
metadataDirectory: $(cleanMetadataFileFairfaxV1OutputPath)
serviceRoot: 'https://graph.microsoft.us/v1.0'
publishPath: 'openapi/fairfax/v1.0'
skipOpenAPIPRGeneration: ${{ parameters.skipOpenAPIPRGeneration }}

- stage: stage_v1_openapi
dependsOn: stage_v1_metadata
condition: and(in(dependencies.stage_v1_metadata.result, 'Succeeded', 'Skipped'), eq( ${{ parameters.skipOpenApiCaptureAndClean }}, false))
Expand Down
30 changes: 23 additions & 7 deletions .azure-pipelines/generation-templates/capture-metadata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ parameters:
- name: metadataAnnotationsCopyScriptPath
type: string
default: '/../scripts/copy-annotations-to-csdl.ps1'
- name: cloud
type: string
default: Prod

steps:

Expand Down Expand Up @@ -97,7 +100,7 @@ steps:
endpointVersion: ${{ parameters.endpoint }}
displayName: 'run Typewriter to clean ${{ parameters.endpoint }} metadata'

- pwsh: '. $(metadataTypeSpecAnnotationsSource)/$Env:ScriptPath -targetCsdlPath "$(Build.SourcesDirectory)/msgraph-metadata/clean_$($Env:Endpoint.Replace(''.'', ''''))_metadata/cleanMetadataWithDescriptions${{ parameters.endpoint }}.xml" -sourceCsdlDirectoryPath "$(metadataTypeSpecAnnotationsSource)/${{ parameters.metadataTypeSpecAnnotationsOutputDir }}"'
- pwsh: '. $(metadataTypeSpecAnnotationsSource)/$Env:ScriptPath -targetCsdlPath "${{ parameters.cleanMetadataFile }}" -sourceCsdlDirectoryPath "$(metadataTypeSpecAnnotationsSource)/${{ parameters.metadataTypeSpecAnnotationsOutputDir }}"'
env:
ScriptPath: ${{ parameters.metadataAnnotationsCopyScriptPath }}
Endpoint: ${{ parameters.endpoint }}
Expand All @@ -118,7 +121,7 @@ steps:
OutputMetadataFileName: 'cleanMetadataWithDescriptionsAndAnnotations'
displayName: 'run Typewriter to clean ${{ parameters.endpoint }} metadata and keep capability annotations'

- pwsh: '. $(metadataTypeSpecAnnotationsSource)/$Env:ScriptPath -targetCsdlPath "$(Build.SourcesDirectory)/msgraph-metadata/clean_$($Env:Endpoint.Replace(''.'', ''''))_metadata/cleanMetadataWithDescriptionsAndAnnotations${{ parameters.endpoint }}.xml" -sourceCsdlDirectoryPath "$(metadataTypeSpecAnnotationsSource)/${{ parameters.metadataTypeSpecAnnotationsOutputDir }}"'
- pwsh: '. $(metadataTypeSpecAnnotationsSource)/$Env:ScriptPath -targetCsdlPath "${{ parameters.cleanMetadataFileWithAnnotations }}" -sourceCsdlDirectoryPath "$(metadataTypeSpecAnnotationsSource)/${{ parameters.metadataTypeSpecAnnotationsOutputDir }}"'
env:
ScriptPath: ${{ parameters.metadataAnnotationsCopyScriptPath }}
Endpoint: ${{ parameters.endpoint }}
Expand All @@ -140,7 +143,7 @@ steps:
OutputMetadataFileName: 'cleanMetadataWithDescriptionsAndAnnotationsAndErrors'
displayName: 'run Typewriter to clean ${{ parameters.endpoint }} metadata and keep capability annotations and include error information'

- pwsh: '. $(metadataTypeSpecAnnotationsSource)/$Env:ScriptPath -targetCsdlPath "$(Build.SourcesDirectory)/msgraph-metadata/clean_$($Env:Endpoint.Replace(''.'', ''''))_metadata/cleanMetadataWithDescriptionsAndAnnotationsAndErrors${{ parameters.endpoint }}.xml" -sourceCsdlDirectoryPath "$(metadataTypeSpecAnnotationsSource)/${{ parameters.metadataTypeSpecAnnotationsOutputDir }}"'
- pwsh: '. $(metadataTypeSpecAnnotationsSource)/$Env:ScriptPath -targetCsdlPath "${{ parameters.outputPath }}/cleanMetadataWithDescriptionsAndAnnotationsAndErrors${{ parameters.endpoint }}.xml" -sourceCsdlDirectoryPath "$(metadataTypeSpecAnnotationsSource)/${{ parameters.metadataTypeSpecAnnotationsOutputDir }}"'
env:
ScriptPath: ${{ parameters.metadataAnnotationsCopyScriptPath }}
Endpoint: ${{ parameters.endpoint }}
Expand All @@ -162,12 +165,22 @@ steps:
displayName: 'Install hidi tool'

# verify that generated metadata is parsable as an Edm model
- pwsh: $(Build.SourcesDirectory)/msgraph-metadata/scripts/run-metadata-validation.ps1 -repoDirectory "$(Build.SourcesDirectory)/msgraph-metadata/" -version "${{ parameters.endpoint }}"
displayName: 'verify whether metadata is parsable as an Edm model'
- ${{ if eq(parameters.cloud, 'Prod') }}:
- pwsh: $(Build.SourcesDirectory)/msgraph-metadata/scripts/run-metadata-validation.ps1 -repoDirectory "$(Build.SourcesDirectory)/msgraph-metadata/" -version "${{ parameters.endpoint }}"
displayName: 'verify whether metadata is parsable as an Edm model'

# clean up extra files
- pwsh: Remove-Item "$(Build.SourcesDirectory)/msgraph-metadata/transformed_*_metadata.*" -Verbose -Force
displayName: 'clean up transformed metadata generated by validation'
- pwsh: Remove-Item "$(Build.SourcesDirectory)/msgraph-metadata/transformed_*_metadata.*" -Verbose -Force
displayName: 'clean up transformed metadata generated by validation'

- ${{ if ne(parameters.cloud, 'Prod') }}:
- pwsh: |
$validationOutput = "$(Agent.TempDirectory)/${{ parameters.cloud }}-${{ parameters.endpoint }}-validation.yaml"
hidi transform --csdl "${{ parameters.outputPath }}/cleanMetadataWithDescriptionsAndAnnotationsAndErrors${{ parameters.endpoint }}.xml" --output $validationOutput --co --format yaml --settings-path "$(conversionSettingsDirectory)/openapi.json"
if ($LASTEXITCODE -ne 0) {
throw "Metadata validation failed with exit code $LASTEXITCODE."
}
displayName: 'validate cleaned ${{ parameters.cloud }} ${{ parameters.endpoint }} metadata'

# Checkin clean metadata into metadata repo or make it an artifact.
- pwsh: '$(scriptsDirectory)/git-push-cleanmetadata.ps1'
Expand All @@ -176,5 +189,8 @@ steps:
CreateOpenAPIPR: False
EndpointVersion: ${{ parameters.endpoint }}
PublishChanges: $(publishChanges)
${{ if ne(parameters.cloud, 'Prod') }}:
PublishPath: ${{ parameters.cleanMetadataFolder }}
PublicationIdentifier: '${{ parameters.cloud }}/${{ parameters.endpoint }}'
workingDirectory: '$(Build.SourcesDirectory)/msgraph-metadata'
enabled: true
87 changes: 77 additions & 10 deletions .azure-pipelines/generation-templates/capture-openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,21 @@ parameters:
type: string
- name: 'skipOpenAPIPRGeneration'
type: boolean
- name: cloud
type: string
default: Prod
- name: metadataDirectory
type: string
default: ''
- name: metadataArtifact
type: string
default: ''
- name: serviceRoot
type: string
default: ''
- name: publishPath
type: string
default: ''
jobs:
- job: get_conversion_settings
displayName: "Get conversion settings"
Expand All @@ -34,6 +49,9 @@ jobs:
$name = $f.Name.replace('.json','')
$data = @{"File"=$f.Name;"Name"=$name;}
$key = "$endpoint-$name"
if ("${{ parameters.cloud }}" -ne "Prod") {
$key = "${{ parameters.cloud }}-$key"
}
$jsonBase.Add($key,$data)
}
$json = $jsonBase | ConvertTo-Json -Compress
Expand All @@ -50,6 +68,12 @@ jobs:
variables:
targets: $[ dependencies.get_conversion_settings.outputs['setTargets.targets'] ]
templateContext:
${{ if ne(parameters.metadataArtifact, '') }}:
inputs:
- input: pipelineArtifact
buildType: current
artifactName: ${{ parameters.metadataArtifact }}
targetPath: '$(Pipeline.Workspace)/${{ parameters.metadataArtifact }}'
outputs:
- output: pipelineArtifact
targetPath: '$(Build.ArtifactStagingDirectory)/$(Name)'
Expand Down Expand Up @@ -79,14 +103,30 @@ jobs:

- pwsh: |
git fetch origin master
if ($LASTEXITCODE -ne 0) {
throw "Failed to fetch metadata master."
}
git switch master
if ($LASTEXITCODE -ne 0) {
throw "Failed to switch to metadata 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)"
$arguments = @{
endpointVersion = "${{ parameters.endpoint }}"
settings = "$(conversionSettingsDirectory)/$(File)"
platformName = "$(Name)"
}
if ("${{ parameters.cloud }}" -ne "Prod") {
$arguments.metadataDirectory = "${{ parameters.metadataDirectory }}"
$arguments.outputDirectory = "${{ parameters.outputPath }}"
$arguments.serviceRoot = "${{ parameters.serviceRoot }}"
}
& "$(scriptsDirectory)/generate-open-api.ps1" @arguments
Write-Host "`ngit status after generation:"
git status
displayName: 'generate ${{ parameters.endpoint }} open API description'
Expand All @@ -100,10 +140,19 @@ jobs:
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
- ${{ if eq(parameters.cloud, 'Prod') }}:
- 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
- ${{ if ne(parameters.cloud, 'Prod') }}:
- pwsh: |
hidi validate -d "${{ parameters.outputPath }}/$(Name).yaml"
if ($LASTEXITCODE -ne 0) {
throw "OpenAPI validation failed with exit code $LASTEXITCODE."
}
displayName: Validate that ${{ parameters.cloud }} OpenAPI docs can be parsed
workingDirectory: $(Build.SourcesDirectory)/msgraph-metadata

- job: publish_openapi
dependsOn: convert_openapi
Expand Down Expand Up @@ -153,18 +202,27 @@ jobs:
inputs:
sourceFolder: '$(Build.ArtifactStagingDirectory)'
contents: '**/*.yaml'
targetFolder: '$(Build.SourcesDirectory)/msgraph-metadata/openapi/${{ parameters.endpoint }}'
${{ if eq(parameters.cloud, 'Prod') }}:
targetFolder: '$(Build.SourcesDirectory)/msgraph-metadata/openapi/${{ parameters.endpoint }}'
${{ else }}:
targetFolder: ${{ parameters.outputPath }}
overwrite: true
displayName: Copy OpenAPI files to local msgraph-metadata repo

# Push changes to msgraph-metadata repo
- pwsh: '$(scriptsDirectory)/git-push-cleanmetadata.ps1'
condition: eq('${{ parameters.skipOpenAPIPRGeneration }}', false)
${{ if eq(parameters.cloud, 'Prod') }}:
condition: eq('${{ parameters.skipOpenAPIPRGeneration }}', false)
${{ else }}:
condition: and(succeeded(), eq('${{ parameters.skipOpenAPIPRGeneration }}', false))
displayName: Publish ${{ parameters.endpoint }} OpenAPI description to msgraph-metadata repo
env:
CreateOpenAPIPR: True
EndpointVersion: ${{ parameters.endpoint }}
PublishChanges: $(publishChanges)
${{ if ne(parameters.cloud, 'Prod') }}:
PublishPath: ${{ parameters.publishPath }}
PublicationIdentifier: '${{ parameters.cloud }}/${{ parameters.endpoint }}'
workingDirectory: '$(Build.SourcesDirectory)/msgraph-metadata'
enabled: true

Expand All @@ -174,13 +232,18 @@ jobs:

- task: AzureKeyVault@2
displayName: "Azure Key Vault: Get Secrets"
${{ if ne(parameters.cloud, 'Prod') }}:
condition: and(succeeded(), eq('${{ parameters.skipOpenAPIPRGeneration }}', false), eq(variables.publishChanges, true), eq(variables.publicationHasChanges, true))
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'
condition: eq('${{ parameters.skipOpenAPIPRGeneration }}', false)
${{ if eq(parameters.cloud, 'Prod') }}:
condition: eq('${{ parameters.skipOpenAPIPRGeneration }}', false)
${{ else }}:
condition: and(succeeded(), eq('${{ parameters.skipOpenAPIPRGeneration }}', false), eq(variables.publishChanges, true), eq(variables.publicationHasChanges, true))
displayName: 'Create Pull Request for the generated OpenAPI files for msgraph-metadata'
env:
BaseBranch: master
Expand All @@ -190,6 +253,10 @@ jobs:
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: ''
# Prod retains its existing title; Fairfax is labelled to distinguish its discovery PR.
${{ if eq(parameters.cloud, 'Prod') }}:
Version: ''
${{ else }}:
Version: '${{ parameters.cloud }} ${{ parameters.endpoint }}'
BranchName: 'publish-open-api-files/$(Build.BuildId)/${{ parameters.cloud }}/${{ parameters.endpoint }}'
workingDirectory: '$(Build.SourcesDirectory)/msgraph-metadata'
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,16 @@ The output C# code files will go in to the `output` directory.
- Prerequisite is that `msgraph-metadata` is checked out at the same root folder as `MSGraph-SDK-Code-Generator`.
- `launch.json` file contains main generation scenarios for each language/endpoint pair. Running Typewriter using one of those generation scenarios (e.g. `Generate TypeScript beta`) will output the corresponding models into a folder, which will be a sibling to `MSGraph-SDK-Code-Generator`. The folder will be named as `generator-output-<language>-<endpoint>` e.g. `generator-output-TypeScript-beta`.

## Generator pipeline

`.azure-pipelines/generation-pipeline.yml` cleans CSDL and generates OpenAPI descriptions for Prod v1.0, Prod beta, and Fairfax v1.0. Fairfax uses `schemas/v1.0-Fairfax.csdl` from `microsoftgraph/msgraph-metadata`, the same Typewriter transforms, documentation and TypeSpec annotations, and Hidi conversion profiles (`default`, `graphexplorer`, `openapi`, and `powershell_v2`) as Prod.

Fairfax cleaned CSDL is published under `clean_v10_fairfax_metadata`; OpenAPI descriptions are published under `openapi/fairfax/v1.0` with the service URL `https://graph.microsoft.us/v1.0`. Its pipeline artifacts are `clean_v10_fairfax_metadata` and `clean_v10_fairfax_openapi` (plus one OpenAPI artifact per profile). The OpenAPI stage consumes the current run's cleaned CSDL artifact even when publication is disabled. No Fairfax SDK generation stages are included.

The existing `skipMetadataCaptureAndClean`, `skipOpenApiCaptureAndClean`, `publishChanges`, and `skipOpenAPIPRGeneration` controls also apply to Fairfax. Skipping metadata capture requires previously published Fairfax cleaned CSDL in the metadata repository. Cleaned CSDL is pushed to metadata master; OpenAPI publication uses a separate `publish-open-api-files/<build-id>/Fairfax/v1.0` discovery PR branch. As with Prod, manual runs skip discovery PR creation. `publishChanges: false` produces artifacts without publishing Fairfax changes or creating its PR.

Run the focused generation and publication regression checks with `pwsh -File test/scripts/FairfaxPipeline.Tests.ps1`. Hidi is mocked for these checks; publication uses temporary local Git repositories.

## Use Typewriter to test your beta metadata

We assume that the metadata you are using is based off the beta metadata file.
Expand Down
Loading
Loading