BintrayPublisher.js
4.79 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.BintrayPublisher = void 0;
function _builderUtil() {
const data = require("builder-util");
_builderUtil = function () {
return data;
};
return data;
}
function _builderUtilRuntime() {
const data = require("builder-util-runtime");
_builderUtilRuntime = function () {
return data;
};
return data;
}
function _bintray() {
const data = require("builder-util-runtime/out/bintray");
_bintray = function () {
return data;
};
return data;
}
function _nodeHttpExecutor() {
const data = require("builder-util/out/nodeHttpExecutor");
_nodeHttpExecutor = function () {
return data;
};
return data;
}
function _lazyVal() {
const data = require("lazy-val");
_lazyVal = function () {
return data;
};
return data;
}
function _electronPublish() {
const data = require("electron-publish");
_electronPublish = function () {
return data;
};
return data;
}
class BintrayPublisher extends _electronPublish().HttpPublisher {
constructor(context, info, version, options = {}) {
super(context);
this.version = version;
this.options = options;
this._versionPromise = new (_lazyVal().Lazy)(() => this.init());
this.providerName = "Bintray";
let token = info.token;
if ((0, _builderUtil().isEmptyOrSpaces)(token)) {
token = process.env.BT_TOKEN;
if ((0, _builderUtil().isEmptyOrSpaces)(token)) {
throw new (_builderUtil().InvalidConfigurationError)(`Bintray token is not set, neither programmatically, nor using env "BT_TOKEN" (see https://www.electron.build/configuration/publish#bintrayoptions)`);
}
token = token.trim();
if (!(0, _builderUtil().isTokenCharValid)(token)) {
throw new (_builderUtil().InvalidConfigurationError)(`Bintray token (${JSON.stringify(token)}) contains invalid characters, please check env "BT_TOKEN"`);
}
}
this.client = new (_bintray().BintrayClient)(info, _nodeHttpExecutor().httpExecutor, this.context.cancellationToken, token);
}
async init() {
try {
return await this.client.getVersion(this.version);
} catch (e) {
if (e instanceof _builderUtilRuntime().HttpError && e.statusCode === 404) {
if (this.options.publish !== "onTagOrDraft") {
_builderUtil().log.info({
version: this.version
}, "version doesn't exist, creating one");
return await this.client.createVersion(this.version);
} else {
_builderUtil().log.warn({
reason: "version doesn't exist",
version: this.version
}, "skipped publishing");
}
}
throw e;
}
}
async doUpload(fileName, arch, dataLength, requestProcessor) {
const version = await this._versionPromise.value;
if (version == null) {
_builderUtil().log.warn({
file: fileName,
reason: "version doesn't exist and is not created",
version: this.version
}, "skipped publishing");
return;
}
const options = {
hostname: "api.bintray.com",
path: `/content/${this.client.owner}/${this.client.repo}/${this.client.packageName}/${encodeURI(`${version.name}/${fileName}`)}`,
method: "PUT",
headers: {
"Content-Length": dataLength,
"X-Bintray-Override": "1",
"X-Bintray-Publish": "1",
"X-Bintray-Debian-Architecture": (0, _builderUtil().toLinuxArchString)(arch, "deb")
}
};
if (this.client.distribution != null) {
options.headers["X-Bintray-Debian-Distribution"] = this.client.distribution;
}
if (this.client.component != null) {
options.headers["X-Bintray-Debian-Component"] = this.client.component;
}
for (let attemptNumber = 0;; attemptNumber++) {
try {
return await _nodeHttpExecutor().httpExecutor.doApiRequest((0, _builderUtilRuntime().configureRequestOptions)(options, this.client.auth), this.context.cancellationToken, requestProcessor);
} catch (e) {
if (attemptNumber < 3 && (e instanceof _builderUtilRuntime().HttpError && e.statusCode === 502 || e.code === "EPIPE")) {
continue;
}
throw e;
}
}
} //noinspection JSUnusedGlobalSymbols
async deleteRelease(isForce = false) {
if (!isForce && !this._versionPromise.hasValue) {
return;
}
const version = await this._versionPromise.value;
if (version != null) {
await this.client.deleteVersion(version.name);
}
}
toString() {
return `Bintray (user: ${this.client.user || this.client.owner}, owner: ${this.client.owner}, package: ${this.client.packageName}, repository: ${this.client.repo}, version: ${this.version})`;
}
} exports.BintrayPublisher = BintrayPublisher;
// __ts-babel@6.0.4
//# sourceMappingURL=BintrayPublisher.js.map