generated from actions/javascript-action
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
72 lines (57 loc) · 2.13 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
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
const core = require('@actions/core');
const github = require('@actions/github');
const getApiFilenames = require('./getApiFilenames');
const generateApiDoc = require('./generateApiDoc');
const commitApiDoc = require('./commitApiDoc');
const dispatchGithubWorkflow = require('./dispatchGithubWorkflow');
async function run() {
try {
const root = process.env.GITHUB_WORKSPACE || process.cwd();
const owner = core.getInput('owner', { required: true });
const repo = core.getInput('repo', { required: true });
const ref = core.getInput('ref', { required: true });
const token = core.getInput('token', { required: true });
const targetOwner = core.getInput('targetOwner', { required: true });
const targetRepo = core.getInput('targetRepo', { required: true });
const targetRef = core.getInput('targetRef', { required: true });
const targetWorkflowId = core.getInput('targetWorkflowId', { required: true });
const themeVariables = core.getInput('themeVariables', { required: false });
const themeTemplate = core.getInput('themeTemplate', { required: false });
core.startGroup('🕹 INPUTS ↴');
core.info(`Root → ${root}`);
core.info(`Owner → ${owner}`);
core.info(`Repository → ${repo}`);
core.info(`Ref(tag/branch) → ${ref}`);
core.endGroup();
const octokit = github.getOctokit(token);
const apiFilenames = getApiFilenames(root);
core.startGroup('🗂 API FILES ↴');
core.info(`Files → ${apiFilenames}`);
core.endGroup();
core.info('🔄 Processing ↴');
const docFilenames = apiFilenames
.map(file => generateApiDoc(file, themeVariables, themeTemplate))
.filter(file => file != null)
for(const doc of docFilenames) {
await commitApiDoc({
octokit,
owner,
repo,
ref,
file: doc,
});
}
core.info(`📩 Dispatching Workflow`);
await dispatchGithubWorkflow({
octokit,
owner: targetOwner,
repo: targetRepo,
workflow_id: targetWorkflowId,
ref: targetRef,
});
} catch (error) {
core.setFailed(error);
}
}
run();
module.exports = run;