-
Notifications
You must be signed in to change notification settings - Fork 358
92 lines (89 loc) · 3.6 KB
/
generate-ref-toc.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
name: Generate reference TOC
on:
workflow_call:
inputs:
target:
description: The target branch to generate the TOC for
default: main
required: false
type: string
pull_request:
description: Indicates if the TOC should be submitted via a PR
default: true
required: false
type: boolean
outputs:
result:
description: Indicates if TOC generation resulted in changes
value: ${{ jobs.generate-ref-toc.outputs.result }}
permissions:
contents: write
pull-requests: write
jobs:
generate-ref-toc:
name: Generate reference TOC
runs-on: ubuntu-latest
outputs:
result: ${{ steps.commit-if-needed.outputs.result }}
steps:
- name: Checkout docs repo
uses: actions/[email protected]
with:
ref: ${{ inputs.target }}
path: docs
- name: Checkout tool repo
uses: actions/[email protected]
with:
repository: microsoftgraph/msgraph-toc-gen
path: tool
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.x
- name: Build TOC generation tool
working-directory: ./tool
run: dotnet build --configuration Release
- name: Run cloud support tool
env:
TOOL: ./tool/src/bin/Release/net8.0/GenerateTOC
run: |
$TOOL --api-docs ./docs/api-reference/v1.0/api --resource-docs ./docs/api-reference/v1.0/resources --mapping ./docs/api-reference/v1.0/toc/toc.mapping.json --terms-override ./docs/api-reference/toc.terms.overrides.json --toc ./docs/api-reference/v1.0/toc.yml --static-toc ./docs/api-reference/v1.0/toc/static-toc.yml
$TOOL --api-docs ./docs/api-reference/beta/api --resource-docs ./docs/api-reference/beta/resources --mapping ./docs/api-reference/beta/toc/toc.mapping.json --terms-override ./docs/api-reference/toc.terms.overrides.json --toc ./docs/api-reference/beta/toc.yml --static-toc ./docs/api-reference/beta/toc/static-toc.yml
- name: Get token
id: get_token
if: ${{ inputs.pull_request }}
uses: microsoftgraph/[email protected]
continue-on-error: true
with:
application-id: ${{ secrets.APPLICATION_ID }}
application-private-key: ${{ secrets.APPLICATION_PRIVATE_KEY }}
- name: Commit updates and open pull request
id: commit-if-needed
working-directory: ./docs
shell: pwsh
env:
GH_TOKEN: ${{ steps.get_token.outputs.app-token }}
PULL_REQUEST: ${{ inputs.pull_request }}
run: |
$status = git status --porcelain
if ($status -eq $null) {
echo "result=TOC generation resulted in no changes" >> $env:GITHUB_OUTPUT
Write-Host "No changes to commit." -ForegroundColor Green
} else {
git config user.email "[email protected]"
git config user.name "Microsoft Graph DevX Tooling"
if ($Env:PULL_REQUEST -eq $true) {
$timestamp = Get-Date -Format FileDateTimeUniversal
git checkout -b ref-toc-generation/$timestamp
git add .
git commit -m "Update reference TOC"
git push --set-upstream origin ref-toc-generation/$timestamp
gh pr create --base main --title "Update reference TOC" --body "Ran TOC generation tool" --label "ready to merge"
echo "result=TOC generation changes submitted via PR" >> $env:GITHUB_OUTPUT
} else {
git add .
git commit -m "Update reference TOC"
git push
echo "result=TOC generation changes committed successfully" >> $env:GITHUB_OUTPUT
}
}