-
Notifications
You must be signed in to change notification settings - Fork 15
89 lines (76 loc) · 3.51 KB
/
monorepo-wiki.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
name: 'Monorepo: Wiki'
on:
repository_dispatch:
types: [monorepo_release]
jobs:
update-wiki:
runs-on: ubuntu-latest
name: 'Update Wiki'
steps:
- uses: dawidd6/action-download-artifact@v2
with:
workflow: unused
run_id: ${{ github.event.client_payload.run_id }}
path: outputs
- name: Checkout wiki
uses: actions/checkout@v2
with:
repository: ${{ github.repository }}.wiki
token: ${{ secrets.GH_PAT_FREIGHTBOT }}
path: wiki
fetch-depth: 0
- name: Ensure wiki folder
run: "[ -d wiki/generated ] || mkdir wiki/generated"
- name: Display structure of retrieved files
run: ls -R
- uses: actions/github-script@v2
id: write-changes
with:
script: |
const { owner, repo } = context.repo;
const { readdir, readFile, writeFile } = require('fs').promises;
const utf8 = { encoding: 'utf-8' };
const msgParts = [];
const newPage = `<!--
Replace this comment with an introduction about the module!
Text and markdown up here will be preserved over time,
while the rest of the wiki page is generated from the release process.
-->
<!-- WARNING: Sections below this comment will be replaced and/or added to automatically. -->
`;
for (const folder of await readdir('outputs', { withFileTypes: true })) {
if (!folder.isDirectory()) continue;
const readText = (name) => readFile(name, utf8).then(x => x.trim());
const wikiPath = `wiki/generated/${folder.name}.md`;
const prevWiki = await readText(wikiPath)
.catch(err => err.code === 'ENOENT' ? newPage : Promise.reject(err));
if (!prevWiki) console.warn('Starting new wiki page for', folder.name);
const newVersion = await readText(`outputs/${folder.name}/new-version.txt`);
const docs = await readText(`outputs/${folder.name}/documentation.md`);
const changelog = await readText(`outputs/${folder.name}/changelog.md`);
let newWiki = prevWiki;
if (!newWiki.match(/^<!-- BEGIN DOCS -->$/m)) {
newWiki += `\n<!-- BEGIN DOCS -->\n<!-- END DOCS -->\n`;
}
newWiki = newWiki.replace(/^<!-- BEGIN DOCS -->$[^]+^<!-- END DOCS -->$/m,
`<!-- BEGIN DOCS -->\n${docs}\n<!-- END DOCS -->`);
if (!newWiki.match(/^<!-- CHANGELOG MARKER -->$/m)) {
newWiki += `\n\n# Changelog\n<!-- CHANGELOG MARKER -->\n`;
}
const changelogHeader = `## ${newVersion} (${new Date().toISOString().split('T')[0]})`
newWiki = newWiki.replace(/^<!-- CHANGELOG MARKER -->$/m,
`<!-- CHANGELOG MARKER -->\n${changelogHeader}\n${changelog}\n`);
await writeFile(wikiPath, newWiki, utf8);
msgParts.push(`${folder.name} @ ${newVersion}`);
console.log(`Updated ${folder.name} @ ${newVersion}`);
}
return msgParts.join(', ');
result-encoding: string
- name: Push changes to wiki
working-directory: wiki
run: |
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git add -A
git commit -m "${{ steps.write-changes.outputs.result }}"
git push