-
Notifications
You must be signed in to change notification settings - Fork 1
/
github:workflow-configure-gh-pages.js
82 lines (72 loc) · 1.96 KB
/
github:workflow-configure-gh-pages.js
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
import * as pkg from '../lib/pkg.js';
import update from '../lib/update.js';
import contains from '../lib/contains.js';
import parseYAML from '../lib/yaml/parse.js';
export const description =
'Configure workflow to automate gh-pages generation.';
const script = 'npm run build-docs';
export const commit = {
type: 'config',
scope: 'github',
subject: description,
};
export async function postcondition({readPkg, readYAML, assert}) {
const {scripts} = await readPkg();
assert(scripts['build-gh-pages'] === script);
await contains({
assert,
read: () => readYAML(filename),
test: (contents) => assert.deepStrictEqual(contents, parseYAML(config)),
});
}
export async function precondition({readPkg, exists, assert}) {
const pkgjson = await readPkg();
const {scripts} = pkgjson;
const devDeps = pkg.devDeps(pkgjson);
assert(devDeps.has('esdoc'));
assert(scripts['build-docs'] !== undefined);
assert(scripts['build-gh-pages'] === undefined);
assert(!(await exists(filename)));
}
export async function apply({readPkg, writePkg, read, write, fixConfig}) {
await update({
read: readPkg,
write: writePkg,
edit(pkgjson) {
pkgjson.scripts['build-gh-pages'] = script;
return pkgjson;
},
});
await update({
create: true,
overwrite: false,
read: () => read(filename),
write: (data) => write(filename, data),
edit: () => config.trim() + '\n',
});
await fixConfig();
}
const filename = '.github/workflows/gh-pages.yml';
const config = `
name: Build and Deploy GitHub pages
on:
release:
types:
- created
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout 🛎️
uses: actions/checkout@v3
- name: Install 🔧
run: npm install
- name: Build 🏗️
run: npm run build-gh-pages
- name: Deploy 🚀
uses: JamesIves/github-pages-deploy-action@4.1.1
with:
branch: gh-pages
folder: gh-pages
`;
export const dependencies = ['docs:build-setup'];