-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathpublish-size.js
30 lines (27 loc) · 1.06 KB
/
publish-size.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
import { repo, sha, event, branch, pull_request_number, ci } from 'ci-env';
import axios from 'axios';
const SIZE_STORE_ENDPOINT = process.env.SIZE_STORE_ENDPOINT || 'https://size-plugin-store.now.sh' ;
// TODO: add option to turn off publishing of sizes.
export async function publishDiff(diff,filename) {
if (process.env.NODE_ENV !=='test' && ci && event == 'pull_request') {
try {
const params = { ci,repo, branch, sha, pull_request_number, diff,filename };
await axios.post(`${SIZE_STORE_ENDPOINT}/diff`, params);
}
catch (error) {
console.error('error: while publishing diff', error);
}
}
}
export async function publishSizes(size,filename) {
// TODO: read allowed branch from configuration
if (process.env.NODE_ENV !=='test' && ci && event == 'push' && branch==='master') {
try {
const params = { ci,repo, branch, sha, pull_request_number, size,filename };
await axios.post(`${SIZE_STORE_ENDPOINT}/size`, params);
}
catch (error) {
console.error('error: while publishing sizes', error);
}
}
}