forked from openkraken/kraken
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathupload_snapshots.js
58 lines (48 loc) · 1.56 KB
/
upload_snapshots.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
const fs = require('fs');
const archiver = require('archiver');
const { series, task } = require('gulp');
const uploader = require('./utils/uploader');
const path = require('path');
const uuid = require('uuid').v4;
const chalk = require('chalk');
function createSnapshotArchiver(baseDir) {
return new Promise((resolve, reject) => {
const output = fs.createWriteStream(baseDir + '/snapshot.zip');
const archive = archiver('zip', {
zlib: { level: 9 } // Sets the compression level.
});
output.on('close', function () {
resolve();
});
output.on('end', function () {
});
// good practice to catch warnings (ie stat failures and other non-blocking errors)
archive.on('warning', function (err) {
if (err.code === 'ENOENT') {
console.log(err);
} else {
reject(err);
}
});
// good practice to catch this error explicitly
archive.on('error', function (err) {
reject(err);
});
archive.pipe(output);
archive.directory(path.join(baseDir, 'integration_tests/snapshots'), false);
archive.finalize();
});
}
task('upload-snapshots', async (done) => {
await createSnapshotArchiver(path.join(__dirname, '../'));
const filename = uuid() + '.zip';
uploader('snapshots/' + filename, path.join(__dirname, '../snapshot.zip')).then(() => {
console.log('Snapshot Upload Success: https://kraken.oss-cn-hangzhou.aliyuncs.com/snapshots/' + filename);
done();
}).catch(err => done(err));
});
series(
'upload-snapshots'
)(() => {
console.log(chalk.green('Upload Success.'));
});