Skip to content

Commit 5594fb8

Browse files
author
George Ndungu
committed
Add download pipeline file and openapi download script
1 parent 4efc983 commit 5594fb8

File tree

2 files changed

+158
-0
lines changed

2 files changed

+158
-0
lines changed
+113
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.
3+
4+
# Generates a release build artifact (nuget) from HEAD of master for auth module.
5+
name: $(BuildDefinitionName)_$(SourceBranchName)_$(Date:yyyyMMdd)$(Rev:.r)
6+
7+
pool:
8+
vmImage: "windows-latest"
9+
10+
variables:
11+
BRANCH: 'weeklyOpenApiDocsDownload'
12+
13+
schedules:
14+
- cron: "0 12 * * 5" # Run Every Friday at Midnight UTC Time
15+
displayName: "Weekly OpenApiDocs Download and PR"
16+
branches:
17+
include:
18+
- gn/generateOpenApiDocs
19+
- dev
20+
always: true
21+
22+
steps:
23+
- checkout: self
24+
persistCredentials: true
25+
clean: true
26+
- task: securedevelopmentteam.vss-secure-development-tools.build-task-credscan.CredScan@2
27+
displayName: 'Run CredScan'
28+
inputs:
29+
debugMode: false
30+
31+
- task: PowerShell@2
32+
displayName: "Compute Branch"
33+
inputs:
34+
targetType: inline
35+
script: |
36+
$branch = "{0}.{1}" -f "weeklyOpenApiDocsDownload", (Get-Date -Format yyyyMMdd)
37+
Write-Host "##vso[task.setvariable variable=BRANCH;]$branch"
38+
- task: PowerShell@2
39+
displayName: "Configure User"
40+
inputs:
41+
targetType: 'inline'
42+
script: |
43+
git config --global user.email "[email protected]"
44+
git config --global user.name "Azure Devops"
45+
46+
- task: PowerShell@2
47+
displayName: "Show Directory"
48+
inputs:
49+
targetType: 'inline'
50+
script: |
51+
Write-Host $(System.DefaultWorkingDirectory)
52+
ls $(System.DefaultWorkingDirectory)
53+
ls $(System.DefaultWorkingDirectory)/tools
54+
55+
- task: PowerShell@2
56+
displayName: Download v1.0 OpenApiDocs
57+
inputs:
58+
filePath: '$(System.DefaultWorkingDirectory)/tools/UpdateOpenApi.ps1'
59+
pwsh: true
60+
61+
- task: PowerShell@2
62+
displayName: Download beta OpenApiDocs
63+
inputs:
64+
filePath: '$(System.DefaultWorkingDirectory)/tools/UpdateOpenApi.ps1'
65+
arguments: '-BetaGraphVersion'
66+
pwsh: true
67+
68+
- task: Bash@3
69+
displayName : "Create PR $(BRANCH)"
70+
inputs:
71+
targetType: 'inline'
72+
script: |
73+
git status
74+
git checkout dev
75+
git branch $(BRANCH)
76+
git checkout $(BRANCH)
77+
git status
78+
79+
- task: Bash@3
80+
displayName : "Commit Downloaded Files"
81+
env:
82+
GITHUB_TOKEN: $(GITHUB_TOKEN)
83+
inputs:
84+
targetType: 'inline'
85+
script: |
86+
git status
87+
git add .
88+
git commit -m 'Weekly OpenApiDocs Download'
89+
git status
90+
git push --set-upstream origin $(BRANCH)
91+
git status
92+
93+
- task: Bash@3
94+
displayName: "Create Pull Request"
95+
env:
96+
GITHUB_TOKEN: $(GITHUB_TOKEN)
97+
MESSAGE_TITLE: Weekly OpenApiDocs Download
98+
MESSAGE_BODY: "This pull request was automatically created by Azure Devops, \n\n Contains Weekly OpenApiDocs Download files for v1.0 and beta"
99+
REVIEWERS: peombwa,ddyett
100+
ASSIGNEDTO: finsharp
101+
LABELS: generated
102+
BASE: dev
103+
BRANCH: $(BRANCH)
104+
inputs:
105+
targetType: 'inline'
106+
script: |
107+
curl -fsSL https://github.com/github/hub/raw/master/script/get | bash -s 2.14.1
108+
bin/hub pull-request -b "$BASE" -h "$BRANCH" -m "$MESSAGE_TITLE" -m "$MESSAGE_BODY" -r "$REVIEWERS" -a "$ASSIGNEDTO" -l "$LABELS"
109+
110+
# References
111+
# [0] https://help.github.com/en/actions/configuring-and-managing-workflows/using-environment-variables
112+
# [1] https://hub.github.com/hub-pull-request.1.html
113+
# https://help.github.com/en/actions/configuring-and-managing-workflows/authenticating-with-the-github_token

tools/UpdateOpenApi.ps1

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.
3+
Param(
4+
[string] $ModuleMappingConfigPath = (Join-Path $PSScriptRoot "..\config\ModulesMapping.jsonc"),
5+
[string] $OpenApiDocOutput = (Join-Path $PSScriptRoot "..\openApiDocs"),
6+
[switch] $BetaGraphVersion
7+
)
8+
9+
$ErrorActionPreference = 'Stop'
10+
$LASTEXITCODE = $null
11+
if ($PSEdition -ne 'Core') {
12+
Write-Error 'This script requires PowerShell Core to execute. [Note] Generated cmdlets will work in both PowerShell Core or Windows PowerShell.'
13+
}
14+
# Install Powershell-yaml
15+
Install-Module powershell-yaml -Force
16+
17+
$GraphVersion = "v1.0"
18+
if ($BetaGraphVersion) {
19+
$GraphVersion = "beta"
20+
}
21+
22+
$OpenApiDocOutput = Join-Path $OpenApiDocOutput $GraphVersion
23+
24+
# PS Scripts
25+
$DownloadOpenApiDocPS1 = Join-Path $PSScriptRoot ".\DownloadOpenApiDoc.ps1" -Resolve
26+
27+
if (-not (Test-Path $ModuleMappingConfigPath)) {
28+
Write-Error "Module mapping file not be found: $ModuleMappingConfigPath."
29+
}
30+
31+
[HashTable] $ModuleMapping = Get-Content $ModuleMappingConfigPath | ConvertFrom-Json -AsHashTable
32+
$ModuleMapping.Keys | ForEach-Object {
33+
$ModuleName = $_
34+
35+
try {
36+
# Download OpenAPI document for module.
37+
& $DownloadOpenApiDocPS1 -ModuleName $ModuleName -ModuleRegex $ModuleMapping[$ModuleName] -OpenApiDocOutput $OpenApiDocOutput -GraphVersion $GraphVersion
38+
}
39+
catch {
40+
Write-Error $_.Exception
41+
}
42+
}
43+
44+
45+
Write-Host -ForegroundColor Green "-------------Done-------------"

0 commit comments

Comments
 (0)