-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.js
82 lines (66 loc) · 2.15 KB
/
build.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
const fs = require('fs');
const util = require('util');
const exec = util.promisify(require('child_process').exec);
const process = require('process');
const core = require('@actions/core');
const { rmdirRecursiveSync } = require('./helpers');
async function build({sitePath, deployBranch, shouldCommit}) {
// Pre Build Setup
if (sitePath.startsWith('https://github.com')) {
// if sitePath is repository
if (fs.existsSync('.abell')) {
rmdirRecursiveSync('.abell');
}
try {
const {stdout, stderr} = await exec(`git clone ${sitePath} .abell`);
rmdirRecursiveSync('.abell/.git');
if (stdout) console.log(stdout);
if (stderr) console.log(stderr);
sitePath = '.abell';
} catch (err) {
core.setFailed(err.message);
}
}
// create github meta data
const githubData = {
repository: process.env.GITHUB_REPOSITORY,
owner: process.env.GITHUB_REPOSITORY_OWNER
}
fs.writeFileSync(`./${sitePath}/githubData.json`, JSON.stringify(githubData, null, 2))
// Run Abell Build
{
try {
const {stdout, stderr} = await exec(`cd ${sitePath} && npx abell build`);
if (stdout) console.log(stdout);
if (stderr) console.log(stderr);
console.log('Created Docs site 🚀');
} catch (err) {
core.setFailed(err.message);
}
}
// post-build cleanup
fs.unlinkSync(`./${sitePath}/githubData.json`);
if (sitePath === '.abell' && fs.existsSync('.abell')) {
rmdirRecursiveSync('.abell');
}
// Configure git and commit to branch
if (shouldCommit) {
const gitSetup = `
git config user.email [email protected]
git config user.name abell-bot
git add docs
git commit -m "abell site commited to the repository" --no-verify
git push https://github.com/${process.env.GITHUB_REPOSITORY} ${deployBranch}:gh-pages --force
`;
try {
const {stdout, stderr} = await exec(gitSetup);
if (stdout) console.log(stdout);
if (stderr) console.log(stderr);
console.log('Setting up git');
console.log('Committed to branch 🌻');
} catch (err) {
core.setFailed(err.message);
}
}
}
module.exports = build;