forked from TryGhost/action-deploy-theme
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
40 lines (33 loc) · 1.41 KB
/
index.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
const path = require('path');
const core = require('@actions/core');
const exec = require('@actions/exec');
const GhostAdminApi = require('@tryghost/admin-api');
(async function main() {
try {
const url = core.getInput('api-url');
const api = new GhostAdminApi({
url,
key: core.getInput('api-key'),
version: 'canary'
});
const basePath = process.env.GITHUB_WORKSPACE;
const pkgPath = path.join(process.env.GITHUB_WORKSPACE, 'package.json');
let zipPath = core.getInput('file');
// Zip file was not provided - zip everything up!
if (!zipPath) {
const themeName = core.getInput('theme-name') || require(pkgPath).name;
const themeZip = `${themeName}.zip`;
const exclude = core.getInput('exclude') || '';
zipPath = themeZip;
// Create a zip
await exec.exec(`zip -r ${themeZip} . -x *.git* *.zip yarn* npm* node_modules* *routes.yaml *redirects.yaml *redirects.json ${exclude}`, [], {cwd: basePath});
}
zipPath = path.join(basePath, zipPath);
// Deploy it to the configured site
await api.themes.upload({file: zipPath});
console.log(`${zipPath} successfully uploaded.`); // eslint-disable-line no-console
} catch (err) {
console.error(err); // eslint-disable-line no-console
process.exit(1);
}
}());