forked from App-vNext/Polly
-
Notifications
You must be signed in to change notification settings - Fork 0
97 lines (81 loc) · 3.4 KB
/
on-push-do-docs.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
93
94
95
96
97
name: on-push-do-docs
on:
push:
branches: [main]
paths: [ "src/Snippets/**" ]
workflow_dispatch:
permissions: {}
jobs:
update-docs:
name: update-docs
runs-on: ubuntu-latest
steps:
- name: Generate GitHub application token
id: generate-application-token
uses: peter-murray/workflow-application-token-action@8e1ba3bf1619726336414f1014e37f17fbadf1db # v2.1.0
with:
application_id: ${{ secrets.POLLY_UPDATER_BOT_APP_ID }}
application_private_key: ${{ secrets.POLLY_UPDATER_BOT_KEY }}
permissions: "contents:write, pull_requests:write"
- name: Checkout code
uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0
with:
token: ${{ steps.generate-application-token.outputs.token }}
- name: Setup .NET SDK
uses: actions/setup-dotnet@3447fd6a9f9e57506b15f895c5b76d3b197dc7c2 # v3.2.0
- name: Update documentation
id: update-docs
shell: pwsh
env:
DOTNET_CLI_TELEMETRY_OPTOUT: true
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
run: |
$ErrorActionPreference = "Stop"
$ProgressPreference = "SilentlyContinue"
dotnet tool restore
dotnet mdsnippets
$GitStatus = (git status --porcelain)
if ([string]::IsNullOrEmpty($GitStatus)) {
Write-Host "No changes to commit."
exit 0
}
$TimeStamp = Get-Date -Format "yyyy-MM-dd-HH-mm"
$BranchName = "docs/update-docs-$TimeStamp"
"branchName=$BranchName" >> $env:GITHUB_OUTPUT
$GitEmail = "138034000+polly-updater-bot[bot]@users.noreply.github.com"
$GitUser = "polly-updater-bot[bot]"
git config user.email $GitEmail | Out-Null
git config user.name $GitUser | Out-Null
git remote set-url "${{ github.server_url }}/${{ github.repository }}.git" | Out-Null
git fetch origin | Out-Null
git rev-parse --verify --quiet ("remotes/origin/" + $BranchName) | Out-Null
if ($LASTEXITCODE -eq 0) {
Write-Host "Branch $BranchName already exists."
exit 0
}
git checkout -b $BranchName
git add .
git commit -m "Update the code-snippets in the documentation"
git push -u origin $BranchName
"updated-docs=true" >> $env:GITHUB_OUTPUT
- name: Create pull request
if: steps.update-docs.outputs.updated-docs == 'true'
uses: actions/github-script@d7906e4ad0b1822421a7e6a35d5ca353c962f410 # v6.4.1
with:
github-token: ${{ steps.generate-application-token.outputs.token }}
script: |
const { repo, owner } = context.repo;
const workflowUrl = `${{ github.server_url }}/${owner}/${repo}/actions/runs/${process.env.GITHUB_RUN_ID}`;
const branchName = "${{ steps.update-docs.outputs.branchName }}";
const result = await github.rest.pulls.create({
title: 'Update the code-snippets in the documentation',
owner,
repo,
head: branchName,
base: 'main',
body: [
'This PR updates the code-snippets in the documentation.',
'',
`This pull request was generated by [GitHub Actions](${workflowUrl}).`
].join('\n')
});