-
Notifications
You must be signed in to change notification settings - Fork 3
123 lines (105 loc) · 4.35 KB
/
reusable-docs-pr-changes.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# Documentation Style Guide Lint
# Uses Vale to lint documentation against the Documentation Style Guide
# Current POC uses the Google style guide as a base set of rules
# See .vale.ini for the current set of rules
name: "Documentation Changelist"
on:
workflow_call:
inputs:
pages-modified:
description: 'A list of asciidoc files changed in this PR'
type: string
default: ''
pages-added:
description: 'A list of asciidoc files added in this PR'
type: string
default: ''
jobs:
save-changelog-comment:
runs-on: ubuntu-latest
steps:
- name: Get deploy URL
id: get-deploy-url
env:
ORG: ${{ github.event.repository.owner.login }}
REPO: ${{ github.event.repository.name }}
DEPLOYID: ${{ github.event.number }}
run: |
deployurl=$ORG-$REPO-$DEPLOYID.surge.sh
echo "deploy-url=$deployurl" >> $GITHUB_OUTPUT
- name: Get page list for PR changelog
id: get-page-list
uses: actions/[email protected]
with:
name: page-list
# tbc - checkout the script from a repo so all docs projects can reuse it
- name: Generate PR changelog comment
# if: inputs.pages-modified != '' || inputs.pages-added != ''
uses: actions/github-script@v7
env:
WORKSPACE: ${{ github.workspace }}
DEPLOYURL: ${{ steps.get-deploy-url.outputs.deploy-url }}
MODIFIEDFILES: ${{ inputs.pages-modified }}
NEWFILES: ${{ inputs.pages-added }}
with:
script: |
var { readFileSync, writeFileSync } = require('fs');
const { MODIFIEDFILES, NEWFILES, DEPLOYURL, WORKSPACE } = process.env
const modifiedFiles = MODIFIEDFILES.split(',').slice(0,9)
const newFiles = NEWFILES.split(',').slice(0,9)
const pageFiles = JSON.parse(readFileSync(`${WORKSPACE}/pageList`))
const deployurl = `https://${DEPLOYURL}`
const preamble = `This PR includes documentation updates\n\View the updated docs at ${deployurl}`
let newFilesList = ''
let modifiedFilesList = ''
let others = []
if (newFiles) {
const links = []
for (const file of newFiles) {
if (file.includes('/pages/')) {
if (Object.keys(pageFiles).includes(file)) {
const url = pageFiles[file].url.replace("/index.html", "")
const title = pageFiles[file].title
links.push(`- [${title}](${deployurl}/${url})`)
} else {
others.push(` - ${file} (**NEW**)`)
}
}
}
if (links.length !== 0) {
newFilesList = `\n\nNew pages:\n${links.join('\n')}`
}
}
if (modifiedFiles) {
const links = []
for (const file of modifiedFiles) {
if (file.includes('/pages/')) {
if (Object.keys(pageFiles).includes(file)) {
const url = pageFiles[file].url.replace("/index.html", "")
const title = pageFiles[file].title
links.push(`- [${title}](${deployurl}/${url})`)
} else {
others.push(` - ${file} (updated)`)
}
}
}
if (links.length !== 0) {
modifiedFilesList = `\n\nUpdated pages:\n${links.join('\n')}`
}
}
let comment = preamble
if (newFilesList !== '' || modifiedFilesList !== '') {
comment = comment.concat(newFilesList,modifiedFilesList)
console.log(`Comment: ${comment}`)
}
if (others.length !== 0) {
comment.concat(`\n\nNew or updated pages that are not in the deployed HTML:\n${others.join('\n')}`)
}
writeFileSync(`${WORKSPACE}/changelog`, Buffer.from(comment));
# For upload-artifact v4 we need to provide a unique artifact name
- name: Upload changelog
if: ${{ hashFiles('changelog') != '' }}
uses: actions/upload-artifact@v4
with:
name: changelog
path: changelog