-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.ts
85 lines (70 loc) · 2.58 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import * as core from '@actions/core';
import * as github from '@actions/github';
import { agent } from '@relative-ci/agent/lib/agent';
import { getWebpackStatsFromFile, getWebpackStatsFromArtifact } from './artifacts';
import { extractParams, extractPullRequestParams, extractWorkflowRunParams } from './params';
import { logger } from './utils';
const { ACTIONS_STEP_DEBUG, GITHUB_WORKSPACE } = process.env;
async function run() {
try {
const token = core.getInput('token');
const key = core.getInput('key');
const slug = core.getInput('slug');
const endpoint = core.getInput('endpoint');
const webpackStatsFile = core.getInput('webpackStatsFile');
const artifactName = core.getInput('artifactName');
const includeCommitMessage = core.getInput('includeCommitMessage') === 'true';
const debug = core.getInput('debug') === 'true';
const { eventName } = github.context;
// Extract data
// @type {AgentParams}
let agentParams;
if (eventName === 'pull_request') {
logger.debug('Extract params for pull_request flow');
agentParams = await extractPullRequestParams(github.context, token, includeCommitMessage);
} else if (eventName === 'workflow_run') {
logger.debug('Extract params for workflow_run flow');
agentParams = await extractWorkflowRunParams(github.context);
} else {
logger.debug('Extract params for default flow');
agentParams = extractParams(github.context);
}
logger.debug(`Agent params: ${JSON.stringify(agentParams)}`)
// Get webpack stats json
let webpackStats = {};
// Get webpack stats file from an artifact
if (eventName === 'workflow_run') {
webpackStats = await getWebpackStatsFromArtifact(token, artifactName, webpackStatsFile);
// Get webpack stats from a file
} else {
if (!webpackStatsFile) {
throw new Error('`webpackStatsFile` input is required!');
}
webpackStats = await getWebpackStatsFromFile(GITHUB_WORKSPACE, webpackStatsFile);
}
// Set RelativeCI service key
// @TODO pass it as an argument to agent
process.env.RELATIVE_CI_KEY = key;
process.env.RELATIVE_CI_ENDPOINT = endpoint;
// Enable debugging for debug input or ACTIONS_STEP_DEBUG is set
if (debug || ACTIONS_STEP_DEBUG) {
process.env.DEBUG = 'relative-ci:agent';
}
await agent(
[
{
key: 'webpack.stats',
data: webpackStats,
},
],
{ includeCommitMessage },
{
slug,
...agentParams,
},
);
} catch (err) {
core.setFailed(err);
}
}
run();