Skip to content

Commit b57f996

Browse files
authored
Merge branch 'dev' into milestone/0.7.0
2 parents 22cbcf1 + 1d7adc3 commit b57f996

File tree

6 files changed

+213
-8
lines changed

6 files changed

+213
-8
lines changed
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
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+
GitUserEmail: '[email protected]'
13+
GitUserName: 'Microsoft Graph DevX Tooling'
14+
BaseBranch: 'dev'
15+
16+
schedules:
17+
- cron: "0 0 * * WED" # Run Every Wednesday
18+
displayName: "Weekly OpenApiDocs Download and PR"
19+
branches:
20+
include:
21+
- dev
22+
always: true
23+
24+
steps:
25+
- checkout: self
26+
persistCredentials: true
27+
clean: true
28+
fetchDepth: 1
29+
30+
- task: securedevelopmentteam.vss-secure-development-tools.build-task-credscan.CredScan@2
31+
displayName: 'Run CredScan'
32+
inputs:
33+
debugMode: false
34+
35+
- task: PowerShell@2
36+
displayName: "Compute Branch"
37+
inputs:
38+
targetType: inline
39+
script: |
40+
$branch = "{0}.{1}" -f "weeklyOpenApiDocsDownload", (Get-Date -Format yyyyMMdd)
41+
Write-Host "##vso[task.setvariable variable=BRANCH;]$branch"
42+
43+
- task: PowerShell@2
44+
displayName: "Configure User"
45+
inputs:
46+
targetType: 'inline'
47+
script: |
48+
git config --global user.email '$(GitUserEmail)'
49+
git config --global user.name '$(GitUserName)'
50+
51+
- task: PowerShell@2
52+
displayName: "Show Directory"
53+
inputs:
54+
targetType: 'inline'
55+
script: |
56+
ls $(System.DefaultWorkingDirectory)
57+
ls $(System.DefaultWorkingDirectory)/tools
58+
59+
- task: PowerShell@2
60+
displayName: Download v1.0 OpenApiDocs
61+
inputs:
62+
filePath: '$(System.DefaultWorkingDirectory)/tools/UpdateOpenApi.ps1'
63+
pwsh: true
64+
65+
- task: PowerShell@2
66+
displayName: Download beta OpenApiDocs
67+
inputs:
68+
filePath: '$(System.DefaultWorkingDirectory)/tools/UpdateOpenApi.ps1'
69+
arguments: '-BetaGraphVersion'
70+
pwsh: true
71+
72+
- task: Bash@3
73+
displayName : "Create PR $(BRANCH)"
74+
inputs:
75+
targetType: 'inline'
76+
script: |
77+
git status
78+
git checkout $(BaseBranch)
79+
git branch $(BRANCH)
80+
git checkout $(BRANCH)
81+
git status
82+
83+
- task: Bash@3
84+
displayName : "Commit Downloaded Files"
85+
env:
86+
GITHUB_TOKEN: $(GITHUB_TOKEN)
87+
inputs:
88+
targetType: 'inline'
89+
script: |
90+
git status
91+
git add .
92+
git commit -m 'Weekly OpenApiDocs Download'
93+
git status
94+
git push --set-upstream origin $(BRANCH)
95+
git status
96+
97+
# References
98+
# [0] https://help.github.com/en/actions/configuring-and-managing-workflows/using-environment-variables
99+
# [1] https://hub.github.com/hub-pull-request.1.html
100+
# https://help.github.com/en/actions/configuring-and-managing-workflows/authenticating-with-the-github_token

.azure-pipelines/generate-beta-modules.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ jobs:
4545
displayName: 'Build Auth Modules'
4646
inputs:
4747
filePath: '$(System.DefaultWorkingDirectory)/tools/GenerateAuthenticationModule.ps1'
48-
arguments: '-RepositoryApiKey $(Api_Key) -ArtifactsLocation $(Build.ArtifactStagingDirectory) -Build -EnableSigning'
48+
arguments: '-RepositoryApiKey $(Api_Key) -ArtifactsLocation $(Build.ArtifactStagingDirectory) -Build -BuildWhenEqual -EnableSigning'
4949
pwsh: true
5050

5151
- task: SFP.build-tasks.custom-build-task-1.EsrpCodeSigning@1

.github/workflows/main.yml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.
3+
# This is a basic workflow to help you get started with Actions
4+
5+
name: WeeklyOpenApiDocsDownload
6+
# Controls when the action will run. Triggers the workflow on push or pull request
7+
# events but only for the master branch
8+
on:
9+
push:
10+
branches:
11+
- 'weeklyOpenApiDocsDownload.*'
12+
13+
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
14+
jobs:
15+
# This workflow contains a single job called "build"
16+
downloadOpenApiDocs:
17+
if: github.event_name == 'push' && !contains(toJson(github.event.commits), 'NO_CI') && !contains(toJson(github.event.commits), '[ci skip]') && !contains(toJson(github.event.commits), '[skip ci]')
18+
# The type of runner that the job will run on
19+
runs-on: ubuntu-latest
20+
# Steps represent a sequence of tasks that will be executed as part of the job
21+
steps:
22+
- name: Configure User
23+
run: |
24+
git config --global user.email "[email protected]"
25+
git config --global user.name "Microsoft Graph DevX Tooling"
26+
27+
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
28+
- name: Checkout
29+
uses: actions/checkout@v2
30+
31+
- name: List Directory
32+
run: |
33+
echo $GITHUB_WORKSPACE
34+
ls -lsa $GITHUB_WORKSPACE
35+
ls -lsa $GITHUB_WORKSPACE/tools
36+
37+
# Create a pull request [1]
38+
- name: Create PR using the GitHub REST API via hub
39+
shell: bash
40+
env:
41+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
42+
MESSAGE_TITLE: Weekly OpenApiDocs Download
43+
MESSAGE_BODY: "This pull request was automatically created by the GitHub Action,\n\n Contains OpenApiDocs Updates from Graph Explorer API"
44+
REVIEWERS: peombwa,ddyett,darrelmiller
45+
ASSIGNEDTO: finsharp
46+
LABELS: generated
47+
BASE: dev
48+
HEAD: ${{steps.create_branch.outputs.branch}}
49+
run: |
50+
curl -fsSL https://github.com/github/hub/raw/master/script/get | bash -s 2.14.1
51+
bin/hub pull-request -b "$BASE" -h "$HEAD" -m "$MESSAGE_TITLE" -m "$MESSAGE_BODY" -r "$REVIEWERS" -a "$ASSIGNEDTO" -l "$LABELS"
52+
# References
53+
# [0] https://help.github.com/en/actions/configuring-and-managing-workflows/using-environment-variables
54+
# [1] https://hub.github.com/hub-pull-request.1.html
55+
# https://help.github.com/en/actions/configuring-and-managing-workflows/authenticating-with-the-github_token

tools/DownloadOpenApiDoc.ps1

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,19 @@ Param(
22
[string] $ModuleName,
33
[string] $ModuleRegex,
44
[string] $OpenApiDocOutput,
5-
[string] $GraphVersion
5+
[string] $GraphVersion,
6+
[int] $RequestCount
67
)
78

8-
if(-not (Test-Path $OpenApiDocOutput)) {
9+
if (-not (Test-Path $OpenApiDocOutput)) {
910
New-Item -Path $OpenApiDocOutput -Type Directory
1011
}
11-
12+
1213
$OpenApiBaseUrl = "https://graphexplorerapi.azurewebsites.net"
1314
$OpenApiServiceUrl = ("$OpenApiBaseUrl/`$openapi?tags={0}&title=$ModuleName&openapiversion=3&style=Powershell&graphVersion=$GraphVersion" -f $ModuleRegex)
15+
if ($RequestCount -eq 0) {
16+
$OpenApiServiceUrl = "$OpenApiServiceUrl&forceRefresh=true"
17+
}
1418

15-
Write-Host -ForegroundColor Green "Downloading OpenAPI doc for '$ModuleName' module: $OpenApiServiceUrl"
19+
Write-Host -ForegroundColor Green "[$RequestCount] Downloading OpenAPI doc for '$ModuleName' module: $OpenApiServiceUrl"
1620
Invoke-WebRequest $OpenApiServiceUrl -OutFile "$OpenApiDocOutput\$ModuleName.yml"

tools/GenerateAuthenticationModule.ps1

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ Param(
77
[switch] $Build,
88
[switch] $Pack,
99
[switch] $Publish,
10-
[switch] $EnableSigning
10+
[switch] $EnableSigning,
11+
[switch] $BuildWhenEqual
1112
)
1213
enum VersionState {
1314
Invalid
@@ -43,10 +44,10 @@ if ($null -eq $ManifestContent.ModuleVersion) {
4344
if ($VersionState.Equals([VersionState]::Invalid)) {
4445
Write-Error "The specified version in $ModulePrefix.$ModuleName module is either higher or lower than what's on $RepositoryName. Update 'ModuleVersion' in $AuthModulePath$AuthModuleManifest."
4546
}
46-
elseif ($VersionState.Equals([VersionState]::EqualToFeed)) {
47+
elseif ($VersionState.Equals([VersionState]::EqualToFeed) -and !$BuildWhenEqual) {
4748
Write-Warning "$ModulePrefix.$ModuleName module skipped. Version has not changed and is equal to what's on $RepositoryName."
4849
}
49-
elseif ($VersionState.Equals([VersionState]::Valid) -or $VersionState.Equals([VersionState]::NotOnFeed)) {
50+
elseif ($VersionState.Equals([VersionState]::Valid) -or $VersionState.Equals([VersionState]::NotOnFeed) -or $BuildWhenEqual) {
5051
$ModuleVersion = $VersionState.Equals([VersionState]::NotOnFeed) ? "0.1.1" : $ManifestContent.ModuleVersion
5152
# Build and pack generated module.
5253
if ($Build) {

tools/UpdateOpenApi.ps1

Lines changed: 45 additions & 0 deletions
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 -Begin { $RequestCount = 0 } -End { Write-Host -ForeGroundColor Green "Requests: $RequestCount" } -Process {
33+
$ModuleName = $_
34+
try {
35+
# Download OpenAPI document for module.
36+
& $DownloadOpenApiDocPS1 -ModuleName $ModuleName -ModuleRegex $ModuleMapping[$ModuleName] -OpenApiDocOutput $OpenApiDocOutput -GraphVersion $GraphVersion -RequestCount $RequestCount
37+
}
38+
catch {
39+
Write-Error $_.Exception
40+
}
41+
$RequestCount = $RequestCount + 1
42+
}
43+
44+
45+
Write-Host -ForegroundColor Green "-------------Done-------------"

0 commit comments

Comments
 (0)