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+ $repoDir = "$env:Build_SourcesDirectory\msgraph-sdk-java\"
49+ Write-Host "Path to java repository: $repoDir"
50+ Write-Host "##vso[task.setvariable variable=repoDir]$repoDir"
51+
52+ $outputPath = Join-Path $env:Build_SourcesDirectory "output"
53+ Write-Host "Path to typewriter.exe output $outputPath"
54+ Write-Host "##vso[task.setvariable variable=outputPath]$outputPath"
55+
56+ $cleanMetadata = "https://raw.githubusercontent.com/microsoftgraph/msgraph-metadata/master/clean_v10_metadata/cleanMetadataWithDescriptionsv1.0.xml"
57+ Write-Host "Path to clean metadata $cleanMetadata"
58+ Write-Host "##vso[task.setvariable variable=cleanMetadata]$cleanMetadata"
59+
60+ $branchName = "v1.0/pipelinebuild/$env:Build_BuildId" # Match the spec in the GH Action
61+ Write-Host "Branch path spec for the pull request will be $branchName"
62+ Write-Host "##vso[task.setvariable variable=branchName]$branchName"
63+
64+ - task : PowerShell@2
65+ displayName : ' Git: branch from dev named with the build id: $(Build.BuildId)'
66+ inputs :
67+ targetType : inline
68+ workingDirectory : ' $(Build.SourcesDirectory)/msgraph-sdk-java'
69+ script : |
70+ Write-Host "The new branch name will be: $env:branchName"
71+ git checkout -B $env:branchName | Write-Host
72+
73+ - task : PowerShell@2
74+ displayName : ' Git: set user config'
75+ inputs :
76+ targetType : inline
77+ workingDirectory : ' $(Build.SourcesDirectory)/msgraph-sdk-java'
78+ script : |
79+ git config user.email "[email protected] " 80+ git config user.name "Microsoft Graph DevX Tooling"
81+
82+ - task : PowerShell@2
83+ displayName : ' Remove generated models and requests from the repo'
84+ inputs :
85+ targetType : inline
86+ script : |
87+ $mainDir = Join-Path $env:repoDir "\src\main\"
88+ $extensionsAndGeneratedDirectories = Get-ChildItem $mainDir -Include extensions,generated -Recurse -Directory
89+
90+ # this list should be updated if a new hand-crafted extension is added to one of the extensions/ directories
91+ $filesThatShouldNotBeDeleted = "UploadSession.java","DateOnly.java","TimeOfDay.java","Multipart.java","ChunkedUploadRequest.java","ChunkedUploadResult.java","CustomRequestBuilder.java"
92+ foreach ($directory in $extensionsAndGeneratedDirectories)
93+ {
94+ Remove-Item $directory.FullName -Recurse -Force -Exclude $filesThatShouldNotBeDeleted
95+ }
96+ Write-Host "Removed the existing generated files in the repo's main directory: $mainDir" -ForegroundColor Green
97+ enabled : true # The old GUI pipeline wasn't doing this. I recall that there was a reason
98+ # for this but I can't recall the reason but I think it was related to reducing number of
99+ # generated files.
100+
101+ - task : PowerShell@2
102+ displayName : ' Typewriter: generate v1.0 Java files'
103+ inputs :
104+ targetType : filePath
105+ filePath : ' $(Build.SourcesDirectory)/msgraph-metadata/scripts/runTypewriter.ps1'
106+ arguments : ' -verbosity Info -language Java -metadata $(cleanMetadata) -output $(outputPath) -generationMode Files'
107+ workingDirectory : ' $(Build.SourcesDirectory)' # Set the root for a multi-repo pipeline. /s
108+ enabled : true
109+
110+ - task : PowerShell@2
111+ displayName : ' Copy generated requests and models into the repo'
112+ inputs :
113+ targetType : inline
114+ script : |
115+ # Path to typewriter output
116+ $comDirectory = Join-Path $env:outputPath "\com\"
117+
118+ # Path to the destination directory
119+ $comDestinationDirectory = Join-Path $env:repoDir "\src\main\java\"
120+
121+ # copies com/ directory to java SDK repo, by following all the recursive paths
122+ Copy-Item $comDirectory -Destination $comDestinationDirectory -Recurse -Force
123+ Write-Host "Copied the generated com\ files into the repo. From: $comDirectory to: $comDestinationDirectory" -ForegroundColor Green
124+
125+ - task : PowerShell@2
126+ displayName : ' Git: stage and commit generated files'
127+ env : # [2]
128+ GIT_REDIRECT_STDERR : " 2>&1"
129+ inputs :
130+ targetType : inline
131+ workingDirectory : ' $(Build.SourcesDirectory)/msgraph-sdk-java'
132+ script : |
133+ Write-Host "About to add files....." -ForegroundColor Green
134+ git add . | Write-Host
135+
136+ if ($env:Build_Reason -eq 'Manual') # Skip CI if manually running this pipeline.
137+ {
138+ git commit -m "Update generated v1.0 Java models and requests with build $env:Build_BuildId [skip ci]" | Write-Host
139+ }
140+ else
141+ {
142+ git commit -m "Update generated v1.0 Java models and requests with build $env:Build_BuildId" | Write-Host
143+ }
144+
145+ Write-Host "Added and committed generated java files." -ForegroundColor Green
146+
147+ - task : PowerShell@2
148+ displayName : ' Git: push updates'
149+ env : # [2]
150+ GIT_REDIRECT_STDERR : " 2>&1"
151+ inputs :
152+ targetType : inline
153+ workingDirectory : ' $(Build.SourcesDirectory)/msgraph-sdk-java'
154+ script : |
155+ git push --set-upstream origin $env:branchName | Write-Host
156+ Write-Host "Pushed the results of the build to the $env:branchName branch." -ForegroundColor Green
157+ enabled : true
158+
159+ # Send a notification to our Graph Tooling channel to let us know that
160+ # that automated build failed. This won't notify on manual builds.
161+
162+ - task : YodLabs.O365PostMessage.O365PostMessageBuild.O365PostMessageBuild@0
163+ displayName : ' Graph Client Tooling pipeline fail notification'
164+ inputs :
165+ addressType : serviceEndpoint
166+ serviceEndpointName : ' microsoftgraph pipeline status'
167+ title : ' $(Build.DefinitionName) failure notification'
168+ text : ' This automated pipeline has failed. View the build details for further information. This is a blocking failure.'
169+ condition : and(failed(), ne(variables['Build.Reason'], 'Manual')) # Only notify if the automated build failed.
170+ enabled : true
171+
172+ # References
173+ # [0] https://docs.microsoft.com/en-us/azure/devops/pipelines/agents/hosted?view=azure-devops#use-a-microsoft-hosted-agent
174+ # [1] https://github.com/actions/virtual-environments/blob/master/images/win/Windows2019-Readme.md
175+ # [2] https://github.com/actions/virtual-environments/issues/617#issuecomment-603664319
0 commit comments