generated from tool3/publisher
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.ts
58 lines (45 loc) · 1.7 KB
/
index.ts
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
import { setFailed, getInput, setOutput } from '@actions/core';
import github from '@actions/github';
import { exec } from '@actions/exec';
async function run() {
try {
const { payload } = github.context;
type Args = Record<string, string>;
const args: Args = {};
// get input credentials
const inputUser = getInput('user');
const inputEmail = getInput('email');
if (payload.head_commit) {
args.email = payload.head_commit.committer.email;
args.username = payload.head_commit.committer.username;
args.message = payload.head_commit.message;
}
const { email, username } = args;
const userName = inputUser || username;
const userEmail = inputEmail || email;
if (!userName || !userEmail) {
const errorMessage = `failed to extract username or email from github context, please provide 'username' and 'email' through the workflow file.`;
return setFailed(errorMessage);
}
// get input
const destinationDir = getInput('dir');
const docsifyArgs = getInput('docsify_args');
const commitMsg = getInput('commit_msg');
const destBranch = getInput('branch');
const docsArgs = ['docsify-cli', 'init', destinationDir];
if (docsifyArgs) {
docsArgs.push(docsifyArgs);
}
// generate docs
await exec('npx', docsArgs);
// push dist
await exec('git', ['config', '--local', 'user.name', userName]);
await exec('git', ['config', '--local', 'user.email', userEmail]);
await exec('git', ['add', '.']);
await exec('git', ['commit', '-a', '-m', commitMsg]);
await exec('git', ['push', 'origin', `HEAD:${destBranch}`]);
} catch (error) {
setFailed(`Failed to publish ${error.message}`);
}
}
run();