This repository was archived by the owner on Apr 22, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmain.js
54 lines (45 loc) · 1.56 KB
/
main.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
import { getInput, setFailed } from '@actions/core';
import { exec } from '@actions/exec';
import { GitHub, context } from '@actions/github';
import {
normaliseFingerprint,
diffSizes,
buildOutputText,
getPullRequest,
getAssetSizes,
buildAssets,
} from './lib/helpers';
let octokit;
async function run() {
try {
const myToken = getInput('repo-token', { required: true });
const files = JSON.parse(getInput('files', { required: false }));
const withSame = getInput('with-same', { required: false }) === 'true';
const buildAssetsCommand = getInput('build-assets', { required: false });
octokit = new GitHub(myToken);
const pullRequest = await getPullRequest(context, octokit);
await buildAssets(buildAssetsCommand);
const prAssets = await getAssetSizes(files);
await exec(`git checkout ${pullRequest.base.sha}`);
await buildAssets(buildAssetsCommand);
const masterAssets = await getAssetSizes(files);
const fileDiffs = diffSizes(normaliseFingerprint(masterAssets), normaliseFingerprint(prAssets));
let body;
try {
body = buildOutputText(fileDiffs, withSame);
await octokit.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pullRequest.number,
body,
});
} catch (e) {
console.log('Could not create a comment automatically.');
console.log(`Copy and paste the following into a comment yourself if you want to still show the diff:
${body}`);
}
} catch (error) {
setFailed(error.message);
}
}
export default run;