Skip to content

Commit 224e0bd

Browse files
authored
Fix/typespec generation pipeline (#1017)
* First test run * adding missing repo * skip scan repos * updating pipeline * updating network isolation * updating command * verify executable path * debuggin artifact * Checking for folder override * updating exit code * Testing PR updates * Adding dummy file test * adding subdirectory * Fix path * Fixing directory issue * Testing new scripts directory * Testing scripts path * Testing without path * fixing path * Adding missing working directory * updating scripts dir * removing debug step * updating copy of files * Fixing date as version * last attempt to ge t the date * adding test file * removing date from title
1 parent 49d16ad commit 224e0bd

3 files changed

Lines changed: 62 additions & 24 deletions

File tree

.azure-pipelines/msgraph-reference-generation.yml

Lines changed: 44 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information.
22
# contains an end to end validation pipeline using C# compilation tests for staging beta metadata
3+
name: $(BuildDefinitionName)_$(SourceBranchName)_$(Date:yyyyMMdd)$(Rev:.r)
34
trigger:
45
branches:
56
include:
@@ -19,13 +20,24 @@ resources:
1920
- repository: typespec-msgraph-reference
2021
type: git
2122
name: typespec-msgraph-reference
23+
- repository: 1ESPipelineTemplates
24+
type: git
25+
name: 1ESPipelineTemplates/1ESPipelineTemplates
26+
ref: refs/tags/release
2227
variables:
2328
BuildConfiguration: 'Release'
2429
scriptsDirectory: '$(Build.SourcesDirectory)\.azure-pipelines\scripts'
2530

2631
extends:
2732
template: v1/1ES.Official.PipelineTemplate.yml@1ESPipelineTemplates
2833
parameters:
34+
settings:
35+
networkIsolationPolicy: Permissive
36+
sdl:
37+
sourceRepositoriesToScan:
38+
exclude:
39+
- repository: typespec-msgraph
40+
- repository: typespec-msgraph-reference
2941
pool:
3042
name: Azure-Pipelines-1ESPT-ExDShared
3143
vmImage: windows-latest
@@ -62,18 +74,18 @@ extends:
6274
displayName: 'Restore dependencies'
6375
inputs:
6476
command: restore
65-
projects: '$(Build.SourcesDirectory)\typespec-msgraph-reference\typespec-msgraph-reference.sln'
77+
projects: '$(Build.SourcesDirectory)\typespec-msgraph-reference.sln'
6678

6779
# Build the solution
6880
- task: DotNetCoreCLI@2
6981
displayName: 'Build solution'
7082
inputs:
7183
command: build
72-
projects: '$(Build.SourcesDirectory)\typespec-msgraph-reference\typespec-msgraph-reference.sln'
84+
projects: '$(Build.SourcesDirectory)\typespec-msgraph-reference.sln'
7385
arguments: '--configuration $(BuildConfiguration) --no-incremental'
7486
- task: CopyFiles@2
7587
inputs:
76-
sourceFolder: '$(Build.SourcesDirectory)/typespec-msgraph-reference/bin/$(BuildConfiguration)/net10.0'
88+
sourceFolder: '$(Build.SourcesDirectory)/bin/$(BuildConfiguration)/net10.0'
7789
contents: '**/*'
7890
targetFolder: '$(Build.ArtifactStagingDirectory)'
7991
displayName: Copy Typespec Reference executable
@@ -86,8 +98,8 @@ extends:
8698
inputs:
8799
- input: pipelineArtifact
88100
buildType: 'current'
89-
artifactName: 'typespec-reference-tool'
90-
targetPath: '$(Build.SourcesDirectory)/typespec-reference-tool'
101+
artifactName: typespec-reference-tool
102+
targetPath: '$(Build.ArtifactStagingDirectory)/typespecReferenceTool'
91103
outputs:
92104
- output: pipelineArtifact
93105
targetPath: '$(Build.ArtifactStagingDirectory)/lib'
@@ -96,7 +108,13 @@ extends:
96108
- checkout: self # Add this to checkout msgraph-metadata repo
97109
displayName: checkout msgraph-metadata
98110
fetchDepth: 1
99-
- pwsh: '$(Build.SourcesDirectory)/.azure-pipelines/scripts/process-all-schemas.ps1 -ExecPath $(Build.SourcesDirectory)/typespec-reference-tool/typespec-msgraph-reference.exe'
111+
- task: CopyFiles@2
112+
inputs:
113+
sourceFolder: $(Build.ArtifactStagingDirectory)/typespecReferenceTool
114+
contents: '**/*'
115+
targetFolder: '$(Build.SourcesDirectory)/typespecReferenceTool'
116+
displayName: "Validate artifact and list contents"
117+
- pwsh: '$(Build.SourcesDirectory)/.azure-pipelines/scripts/process-all-schemas.ps1 -ExePath $(Build.SourcesDirectory)/typespecReferenceTool/typespec-msgraph-reference.exe'
100118
displayName: "Process all the valid schemas files"
101119
- task: CopyFiles@2
102120
inputs:
@@ -113,8 +131,11 @@ extends:
113131
- input: pipelineArtifact
114132
buildType: 'current'
115133
artifactName: 'referenceLibrary'
116-
targetPath: '$(Build.SourcesDirectory)/tmp_lib'
134+
targetPath: '$(Build.ArtifactStagingDirectory)/tmp_lib'
117135
steps:
136+
- checkout: self # Add this to checkout msgraph-metadata repo
137+
displayName: checkout msgraph-metadata
138+
fetchDepth: 1
118139
- checkout: typespec-msgraph
119140
displayName: checkout typespec-msgraph
120141
fetchDepth: 1
@@ -123,21 +144,30 @@ extends:
123144
git config --global user.email "GraphTooling@service.microsoft.com"
124145
git config --global user.name "Microsoft Graph DevX Tooling"
125146
displayName: 'Git: set user config'
126-
# Copy files from the tmp folder to the checkout repo
127147
- task: CopyFiles@2
128148
inputs:
129-
sourceFolder: '$(Build.SourcesDirectory)/tmp_lib'
149+
sourceFolder: '$(Build.ArtifactStagingDirectory)/tmp_lib'
130150
contents: '**/*'
131-
targetFolder: '$(Build.SourcesDirectory)/typespec-msgraph/packages/typespec-reference-library/lib'
151+
targetFolder: '$(Build.SourcesDirectory)/typespec-msgraph/packages/typespec-msgraph-reference/lib'
132152
overwrite: true
133153
displayName: Copy OpenAPI files to local typespec-msgraph repo
154+
- pwsh: |
155+
$manifestPath = "$(Build.SourcesDirectory)/typespec-msgraph/packages/typespec-msgraph-reference/lib/_manifest"
156+
if (Test-Path $manifestPath) {
157+
Write-Host "Deleting _manifest folder: $manifestPath" -ForegroundColor Yellow
158+
Remove-Item -Path $manifestPath -Recurse -Force
159+
Write-Host "_manifest folder deleted successfully" -ForegroundColor Green
160+
} else {
161+
Write-Host "_manifest folder not found, skipping deletion" -ForegroundColor Cyan
162+
}
163+
displayName: 'Delete _manifest folder'
134164
# Push changes to Typespec msgraph repo
135-
- pwsh: '$(scriptsDirectory)/git-push-reference-files.ps1'
165+
- pwsh: '$(Build.SourcesDirectory)/msgraph-metadata/.azure-pipelines/scripts/git-push-reference-files.ps1'
136166
displayName: Publish new generated files to msgraph-metadata repo
137167
env:
138168
PublishChanges: True
139-
workingDirectory: '$(Build.SourcesDirectory)/typespec-msgraph'
140169
enabled: true
170+
workingDirectory: '$(Build.SourcesDirectory)/typespec-msgraph'
141171

142172
# Create PR
143173
- task: AzureKeyVault@2
@@ -147,7 +177,7 @@ extends:
147177
KeyVaultName: akv-prod-eastus
148178
SecretsFilter: "microsoft-graph-devx-bot-appid,microsoft-graph-devx-bot-privatekey"
149179

150-
- pwsh: '$(scriptsDirectory)/create-pull-request.ps1'
180+
- pwsh: '$(Build.SourcesDirectory)/msgraph-metadata/.azure-pipelines/scripts/create-pull-request.ps1'
151181
displayName: 'Create Pull Request for the generated OpenAPI files for msgraph-metadata'
152182
env:
153183
BaseBranch: main
@@ -156,9 +186,5 @@ extends:
156186
GhAppKey: $(microsoft-graph-devx-bot-privatekey)
157187
OverrideSkipCI: false
158188
RepoName: 'microsoftgraph/typespec-msgraph'
159-
ScriptsDirectory: $(scriptsDirectory)
160-
# Version is intentionally left empty for OpenAPI PRs as versioning is not applicable in this context.
161-
Version: ''
189+
scriptDir: $(Build.SourcesDirectory)\msgraph-metadata\.azure-pipelines\scripts
162190
workingDirectory: '$(Build.SourcesDirectory)/typespec-msgraph'
163-
164-

.azure-pipelines/scripts/create-pull-request.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ if (($env:GeneratePullRequest -eq $False)) { # Skip CI if manually running this
44
return;
55
}
66

7-
$title = "Generated $env:Version typespec reference files"
7+
$title = "Chore: Update Generated typespec reference files"
88

99

1010
$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."
1111

1212
# The installed application is required to have the following permissions: read/write on pull requests/
13-
$tokenGenerationScript = "$env:ScriptsDirectory\Generate-Github-Token.ps1"
13+
$tokenGenerationScript = "$env:scriptDir\Generate-Github-Token.ps1"
1414
$env:GITHUB_TOKEN = & $tokenGenerationScript -AppClientId $env:GhAppId -AppPrivateKeyContents $env:GhAppKey -Repository $env:RepoName
1515
Write-Host "Fetched Github Token for PR generation and set as environment variable."
1616

.azure-pipelines/scripts/process-all-schemas.ps1

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,17 @@ param(
88

99
$ErrorActionPreference = "Stop"
1010

11+
# Normalize path separators for Windows
12+
$ExePath = $ExePath -replace '/', '\'
13+
14+
# Validate that the executable exists
15+
if (-not (Test-Path $ExePath)) {
16+
Write-Host "Error: Executable not found at path: $ExePath" -ForegroundColor Red
17+
exit 1
18+
}
19+
20+
Write-Host "Using executable: $ExePath" -ForegroundColor Cyan
21+
1122
# Define the environments
1223
$environments = @(
1324
"Bleu",
@@ -23,8 +34,8 @@ $environments = @(
2334
# Process beta files
2435
Write-Host "Processing beta CSDL files..." -ForegroundColor Cyan
2536
foreach ($env in $environments) {
26-
$csdlFile = "../../schemas/beta-$env.csdl"
27-
$outputDir = "../../generated-lib/$env/Beta/"
37+
$csdlFile = "./schemas/beta-$env.csdl"
38+
$outputDir = "./generated-lib/$env/Beta/"
2839

2940
if (Test-Path $csdlFile) {
3041
Write-Host "Processing $csdlFile -> $outputDir" -ForegroundColor Green
@@ -42,8 +53,8 @@ foreach ($env in $environments) {
4253
# Process v1.0 files
4354
Write-Host "`nProcessing v1.0 CSDL files..." -ForegroundColor Cyan
4455
foreach ($env in $environments) {
45-
$csdlFile = "../../schemas/v1.0-$env.csdl"
46-
$outputDir = "../../generated-lib/$env/V1.0/"
56+
$csdlFile = "./schemas/v1.0-$env.csdl"
57+
$outputDir = "./generated-lib/$env/V1.0/"
4758

4859
if (Test-Path $csdlFile) {
4960
Write-Host "Processing $csdlFile -> $outputDir" -ForegroundColor Green
@@ -59,3 +70,4 @@ foreach ($env in $environments) {
5970
}
6071

6172
Write-Host "`nAll CSDL files processed successfully!" -ForegroundColor Green
73+
exit 0

0 commit comments

Comments
 (0)