1+ # Copyright (c) Microsoft Corporation. All rights reserved.
2+ # Licensed under the MIT License.
3+
4+ name : $(BuildDefinitionName)_$(SourceBranchName)_$(Date:yyyyMMdd)$(Rev:.r)
5+
6+ trigger : none # disable triggers based on commits.
7+ pr : none # disable triggers based on pull requests.
8+
9+ resources :
10+ repositories :
11+ - repository : msgraph-sdk-java # The name used to reference this repository in the checkout step
12+ type : github
13+ endpoint : microsoftgraph
14+ name : microsoftgraph/msgraph-sdk-java
15+ ref : dev # checkout the dev branch
16+ - repository : msgraph-metadata
17+ type : github
18+ endpoint : microsoftgraph
19+ name : microsoftgraph/msgraph-metadata
20+ ref : master #
21+ pipelines :
22+ - pipeline : publishMetadata # This pipeline validates and produces an metadata artifact that we use for generation.
23+ source : (v1.0 - 3) msgraph-publish-cleanmetadata
24+ trigger :
25+ branches :
26+ - master
27+
28+ pool :
29+ vmImage : windows-latest # Info about this image: [0][1]
30+
31+ variables :
32+ - group : MicrosoftGraph # Variable group, where variables not set here come from. Set in Azure DevOps
33+
34+ steps :
35+ - checkout : msgraph-sdk-java
36+ clean : true
37+ fetchDepth : 1
38+ persistCredentials : true
39+ - checkout : msgraph-metadata
40+ clean : true
41+ fetchDepth : 1
42+
43+ - task : PowerShell@2 # Setup environment variables and make them available to all tasks. See [1] for more info.
44+ displayName : ' Calculate and set pipeline variables for this job'
45+ inputs :
46+ targetType : inline
47+ script : |
48+
49+ $repoModelsDir = "$env:Build_SourcesDirectory\msgraph-sdk-java\src\main\java\com\microsoft\graph\models\generated\"
50+ $repoModelsExtensionDir = "$env:Build_SourcesDirectory\msgraph-sdk-java\src\main\java\com\microsoft\graph\models\extensions\"
51+ $repoRequestExtensionDir = "$env:Build_SourcesDirectory\msgraph-sdk-java\src\main\java\com\microsoft\graph\requests\extensions\"
52+ Write-Host "Path to repo model directory: $repoModelsDir"
53+ Write-Host "Path to repo model extension directory: $repoModelsExtensionDir"
54+ Write-Host "Path to repo request directory: $repoRequestExtensionDir"
55+ Write-Host "##vso[task.setvariable variable=repoModelsDir]$repoModelsDir"
56+ Write-Host "##vso[task.setvariable variable=repoModelsExtensionDir]$repoModelsExtensionDir"
57+ Write-Host "##vso[task.setvariable variable=repoRequestExtensionDir]$repoRequestExtensionDir"
58+
59+ $outputPath = Join-Path $env:Build_SourcesDirectory "output"
60+ Write-Host "Path to typewriter.exe output $outputPath"
61+ Write-Host "##vso[task.setvariable variable=outputPath]$outputPath"
62+
63+ $cleanMetadata = "https://raw.githubusercontent.com/microsoftgraph/msgraph-metadata/master/clean_v10_metadata/cleanMetadataWithDescriptionsv1.0.xml"
64+ Write-Host "Path to clean metadata $cleanMetadata"
65+ Write-Host "##vso[task.setvariable variable=cleanMetadata]$cleanMetadata"
66+
67+ $branchName = "v1.0/pipelinebuild/$env:Build_BuildId" # Match the spec in the GH Action
68+ Write-Host "Branch path spec for the pull request will be $branchName"
69+ Write-Host "##vso[task.setvariable variable=branchName]$branchName"
70+
71+ - task : PowerShell@2
72+ displayName : ' Git: checkout dev'
73+ inputs :
74+ targetType : inline
75+ workingDirectory : ' $(Build.SourcesDirectory)/msgraph-sdk-java'
76+ script : |
77+ git checkout dev | Write-Host
78+
79+ - task : PowerShell@2
80+ displayName : ' Git: branch from dev named with the build id: $(Build.BuildId)'
81+ inputs :
82+ targetType : inline
83+ workingDirectory : ' $(Build.SourcesDirectory)/msgraph-sdk-java'
84+ script : |
85+
86+ Write-Host "The new branch name will be: $env:branchName"
87+ git checkout -B $env:branchName | Write-Host
88+
89+ - task : PowerShell@2
90+ displayName : ' Git: set user config'
91+ inputs :
92+ targetType : inline
93+ workingDirectory : ' $(Build.SourcesDirectory)/msgraph-sdk-java'
94+ script : |
95+ git config user.email "[email protected] " 96+ git config user.name "Microsoft Graph DevX Tooling"
97+
98+ - task : PowerShell@2
99+ displayName : ' Remove generated models and requests from the repo'
100+ inputs :
101+ targetType : inline
102+ script : |
103+ Remove-Item -Recurse $env:repoModelsDir | Write-Host
104+ Remove-Item -Recurse $env:repoModelsExtensionDir | Write-Host
105+ Remove-Item -Recurse $env:repoRequestExtensionDir | Write-Host
106+ Write-Host "Removed the existing generated files in the repo." -ForegroundColor Green
107+ enabled : false # The old GUI pipeline wasn't doing this. I recall that there was a reason
108+ # for this but I can't recall the reason but I think it was related to reducing number of
109+ # generated files.
110+
111+ - task : PowerShell@2
112+ displayName : ' Typewriter: generate v1.0 Java files'
113+ inputs :
114+ targetType : filePath
115+ filePath : ' $(Build.SourcesDirectory)/msgraph-metadata/scripts/runTypewriter.ps1'
116+ arguments : ' -verbosity Info -language Java -metadata $(cleanMetadata) -output $(outputPath) -generationMode Files'
117+ workingDirectory : ' $(Build.SourcesDirectory)' # Set the root for a multi-repo pipeline. /s
118+ enabled : true
119+
120+ - task : PowerShell@2
121+ displayName : ' Copy generated requests and models into the repo'
122+ inputs :
123+ targetType : inline
124+ script : |
125+ # Path to typewriter output
126+ $modelsDirectory = Join-Path $env:outputPath "\com\microsoft\graph\models\generated\*"
127+ $modelsExtensionsDirectory = Join-Path $env:outputPath "\com\microsoft\graph\models\extensions\*"
128+ $requestsExtensionsDirectory = Join-Path $env:outputPath "\com\microsoft\graph\requests\extensions\*"
129+
130+ # models\generated - excluding Base* should not be necessary as those files shouldn't be generated.
131+ Copy-Item $modelsDirectory -Destination $env:repoModelsDir -Exclude Base*
132+ Write-Host "Copied the generated models\generated files into the repo. Excluded Base* files." -ForegroundColor Green
133+
134+ # models\extensions
135+ Copy-Item $modelsExtensionsDirectory -Destination $env:repoModelsExtensionDir
136+ Write-Host "Copied the generated models\extensions files into the repo." -ForegroundColor Green
137+
138+ # requests\extensions
139+ Copy-Item $requestsExtensionsDirectory -Destination $env:repoRequestExtensionDir
140+ Write-Host "Copied the generated requests\extensions files into the repo." -ForegroundColor Green
141+
142+ - task : PowerShell@2
143+ displayName : ' Git: stage and commit generated files'
144+ env : # [2]
145+ GIT_REDIRECT_STDERR : " 2>&1"
146+ inputs :
147+ targetType : inline
148+ workingDirectory : ' $(Build.SourcesDirectory)/msgraph-sdk-java'
149+ script : |
150+ Write-Host "About to add files....." -ForegroundColor Green
151+ git add . | Write-Host
152+
153+ if ($env:Build_Reason -eq 'Manual') # Skip CI if manually running this pipeline.
154+ {
155+ git commit -m "Update generated v1.0 Java models and requests with build $env:Build_BuildId [skip ci]" | Write-Host
156+ }
157+ else
158+ {
159+ git commit -m "Update generated v1.0 Java models and requests with build $env:Build_BuildId" | Write-Host
160+ }
161+
162+ Write-Host "Added and committed generated java files." -ForegroundColor Green
163+
164+ - task : PowerShell@2
165+ displayName : ' Git: push updates'
166+ env : # [2]
167+ GIT_REDIRECT_STDERR : " 2>&1"
168+ inputs :
169+ targetType : inline
170+ workingDirectory : ' $(Build.SourcesDirectory)/msgraph-sdk-java'
171+ script : |
172+ git push --set-upstream origin $env:branchName | Write-Host
173+ Write-Host "Pushed the results of the build to the $env:branchName branch." -ForegroundColor Green
174+ enabled : true
175+
176+ # Send a notification to our Graph Tooling channel to let us know that
177+ # that automated build failed. This won't notify on manual builds.
178+
179+ - task : YodLabs.O365PostMessage.O365PostMessageBuild.O365PostMessageBuild@0
180+ displayName : ' Graph Client Tooling pipeline fail notification'
181+ inputs :
182+ addressType : serviceEndpoint
183+ serviceEndpointName : ' microsoftgraph pipeline status'
184+ title : ' $(Build.DefinitionName) failure notification'
185+ text : ' This automated pipeline has failed. View the build details for further information. This is a blocking failure.'
186+ condition : and(failed(), ne(variables['Build.Reason'], 'Manual')) # Only notify if the automated build failed.
187+ enabled : true
188+
189+ # References
190+ # [0] https://docs.microsoft.com/en-us/azure/devops/pipelines/agents/hosted?view=azure-devops#use-a-microsoft-hosted-agent
191+ # [1] https://github.com/actions/virtual-environments/blob/master/images/win/Windows2019-Readme.md
192+ # [2] https://github.com/actions/virtual-environments/issues/617#issuecomment-603664319
0 commit comments