-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy.js
67 lines (67 loc) · 2.17 KB
/
deploy.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
59
60
61
62
63
64
65
66
67
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var request = require("request");
var fs = require("fs");
if (process.env.TRAVIS_BRANCH != "master") {
console.log("Only run on master");
process.exit(0);
}
var uploadFiles = {
"build/proxy.zip": {
name: "proxy.zip",
contentType: "application/zip"
},
"build/webalance.deb": {
name: "webalance.deb",
contentType: "application/octet-stream"
}
};
var packageJ = JSON.parse(fs.readFileSync("package.json", "UTF-8"));
request({
url: "https://api.github.com/repos/ozouai/WeBalance/releases",
method: "POST",
auth: {
pass: "x-oauth-basic",
user: process.env.GITHUB_OAUTH_TOKEN
},
headers: {
'User-Agent': 'Release-Agent',
'Accept': 'application/vnd.github.v3+json',
},
json: {
tag_name: packageJ.version,
name: "Build Results - " + packageJ.version,
body: "Upload results",
draft: true
}
}, function (err, response, body) {
if (body.upload_url) {
for (var _i = 0, _a = Object.keys(uploadFiles); _i < _a.length; _i++) {
var file = _a[_i];
if (fs.existsSync(file)) {
var stats = fs.statSync(file);
var options = {
url: body.upload_url.replace('{?name,label}', ''),
auth: {
pass: "x-oauth-basic",
user: process.env.GITHUB_OAUTH_TOKEN
},
json: true,
headers: {
'User-Agent': 'Release-Agent',
'Accept': 'application/vnd.github.v3+json',
'Content-Type': uploadFiles[file].contentType,
'Content-Length': stats.size
},
qs: {
name: uploadFiles[file].name
}
};
console.log(options);
fs.createReadStream(file).pipe(request.post(options, function (err, res) {
console.log("File Uploaded");
}));
}
}
}
});