-
-
Notifications
You must be signed in to change notification settings - Fork 31.7k
/
upload.js
53 lines (45 loc) · 1.42 KB
/
upload.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
/* eslint-disable no-console */
const aws = require('aws-sdk');
const fse = require('fs-extra');
const path = require('path');
const workspaceRoot = path.join(__dirname, '../../');
const snapshotDestPath = path.join(workspaceRoot, 'size-snapshot.json');
async function main() {
function uploadArtifact(artifact, options) {
// eslint-disable-next-line no-async-promise-executor
return new Promise(async (resolve, reject) => {
const s3 = new aws.S3();
s3.upload(
{
...options,
Body: JSON.stringify(artifact, null, 2),
ContentType: 'application/json',
},
(err, data) => {
if (err) {
reject(err);
} else {
resolve(data);
}
},
);
});
}
const branch = process.env.BUILD_SOURCEBRANCHNAME.replace(/^refs\/head\//, '');
const snapshot = await fse.readJSON(snapshotDestPath);
function upload(revision) {
const uploadOptions = {
Bucket: 'eps1lon-material-ui',
Key: `artifacts/${branch}/${revision}/size-snapshot.json`,
};
return uploadArtifact(snapshot, uploadOptions);
}
// save snapshot under the commit id as well as imitating a symlink `latest`
// to the commit id
const [uploaded] = await Promise.all([upload(process.env.BUILD_SOURCEVERSION), upload('latest')]);
console.log(uploaded);
}
main().catch(error => {
console.error(error);
process.exit(1);
});