Skip to content

Commit da049aa

Browse files
Add yaml generation pipeline for v1.0 typings (#353)
* add yaml pipeline
1 parent 6f8cdb1 commit da049aa

File tree

2 files changed

+195
-1
lines changed

2 files changed

+195
-1
lines changed
Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
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

.github/workflows/create-v1.0-pull-request.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ on:
1818
jobs:
1919
# This workflow contains a single job called "create-pull-request"
2020
create-pull-request:
21+
# GitHub Actions don't support skip ci yet like Azure Pipelines so this check will do the same.
22+
if: github.event_name == 'push' && contains(toJson(github.event.commits), '***NO_CI***') == false && contains(toJson(github.event.commits), '[ci skip]') == false && contains(toJson(github.event.commits), '[skip ci]') == false
2123
# The type of runner that the job will run on
2224
runs-on: ubuntu-latest
2325
# https://github.com/actions/virtual-environments/blob/master/images/linux/Ubuntu1804-README.md
@@ -32,7 +34,7 @@ jobs:
3234
shell: bash
3335
env:
3436
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
35-
MESSAGE_TITLE: Generated models and request builders using Typewriter
37+
MESSAGE_TITLE: Generated v1.0 models and request builders using Typewriter
3638
MESSAGE_BODY: "This pull request was automatically created by the GitHub Action, **${{github.workflow}}**. \n\n The commit hash is _${{github.sha}}_. \n\n **Important** Check for unexpected deletions or changes in this PR. \n\n cc: @darrelmiller"
3739
REVIEWERS: peombwa,ddyett
3840
ASSIGNEDTO: MIchaelMainer

0 commit comments

Comments
 (0)