Skip to content

Commit d0487b0

Browse files
committed
fix(deployment): Bintray publisher doesn't escape filename
Close #2600
1 parent ba4809a commit d0487b0

File tree

6 files changed

+72
-66
lines changed

6 files changed

+72
-66
lines changed

packages/builder-util/src/nodeHttpExecutor.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ export class NodeHttpExecutor extends HttpExecutor<ClientRequest> {
1010
.then(() => destination)
1111
}
1212

13+
// noinspection JSMethodCanBeStatic
14+
// noinspection JSUnusedGlobalSymbols
1315
doRequest(options: any, callback: (response: any) => void): any {
1416
return (options.protocol === "http:" ? httpRequest : https.request)(options, callback)
1517
}

packages/electron-publish/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"out"
1212
],
1313
"dependencies": {
14+
"lazy-val": "^1.0.3",
1415
"fs-extra-p": "^4.5.2",
1516
"mime": "^2.2.0",
1617
"bluebird-lst": "^1.0.5",

packages/electron-publish/src/BintrayPublisher.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
import BluebirdPromise from "bluebird-lst"
21
import { Arch, InvalidConfigurationError, isEmptyOrSpaces, isTokenCharValid, log, toLinuxArchString } from "builder-util"
32
import { BintrayOptions, configureRequestOptions, HttpError } from "builder-util-runtime"
43
import { BintrayClient, Version } from "builder-util-runtime/out/bintray"
54
import { httpExecutor } from "builder-util/out/nodeHttpExecutor"
65
import { ClientRequest, RequestOptions } from "http"
6+
import { Lazy } from "lazy-val"
77
import { HttpPublisher, PublishContext, PublishOptions } from "./publisher"
88

99
export class BintrayPublisher extends HttpPublisher {
10-
private _versionPromise: BluebirdPromise<Version>
10+
private readonly _versionPromise = new Lazy(() => this.init())
1111

1212
private readonly client: BintrayClient
1313

@@ -31,7 +31,6 @@ export class BintrayPublisher extends HttpPublisher {
3131
}
3232

3333
this.client = new BintrayClient(info, httpExecutor, this.context.cancellationToken, token)
34-
this._versionPromise = this.init() as BluebirdPromise<Version>
3534
}
3635

3736
private async init(): Promise<Version | null> {
@@ -54,15 +53,15 @@ export class BintrayPublisher extends HttpPublisher {
5453
}
5554

5655
protected async doUpload(fileName: string, arch: Arch, dataLength: number, requestProcessor: (request: ClientRequest, reject: (error: Error) => void) => void) {
57-
const version = await this._versionPromise
56+
const version = await this._versionPromise.value
5857
if (version == null) {
5958
log.notice({file: fileName, reason: "version doesn't exist and is not created", version: this.version}, "skipped publishing")
6059
return
6160
}
6261

6362
const options: RequestOptions = {
6463
hostname: "api.bintray.com",
65-
path: `/content/${this.client.owner}/${this.client.repo}/${this.client.packageName}/${version.name}/${fileName}`,
64+
path: `/content/${this.client.owner}/${this.client.repo}/${this.client.packageName}/${encodeURI(`${version.name}/${fileName}`)}`,
6665
method: "PUT",
6766
headers: {
6867
"Content-Length": dataLength,
@@ -97,13 +96,15 @@ export class BintrayPublisher extends HttpPublisher {
9796
}
9897

9998
//noinspection JSUnusedGlobalSymbols
100-
deleteRelease(): Promise<any> {
101-
if (!this._versionPromise.isFulfilled()) {
102-
return BluebirdPromise.resolve()
99+
async deleteRelease(): Promise<void> {
100+
if (!this._versionPromise.hasValue) {
101+
return
103102
}
104103

105-
const version = this._versionPromise.value()
106-
return version == null ? BluebirdPromise.resolve() : this.client.deleteVersion(version.name)
104+
const version = (await this._versionPromise.value)
105+
if (version != null) {
106+
await this.client.deleteVersion(version.name)
107+
}
107108
}
108109

109110
toString() {

packages/electron-publish/src/gitHubPublisher.ts

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import BluebirdPromise from "bluebird-lst"
21
import { Arch, InvalidConfigurationError, isEmptyOrSpaces, isEnvTrue, isTokenCharValid, log } from "builder-util"
32
import { configureRequestOptions, GithubOptions, HttpError, parseJson } from "builder-util-runtime"
43
import { Fields } from "builder-util/out/log"
54
import { httpExecutor } from "builder-util/out/nodeHttpExecutor"
65
import { ClientRequest } from "http"
6+
import { Lazy } from "lazy-val"
77
import mime from "mime"
88
import { parse as parseUrl } from "url"
99
import { getCiTag, HttpPublisher, PublishContext, PublishOptions } from "./publisher"
@@ -26,8 +26,8 @@ interface Asset {
2626
}
2727

2828
export class GitHubPublisher extends HttpPublisher {
29-
private tag: string
30-
private _releasePromise: Promise<Release | null> | null = null
29+
private readonly tag: string
30+
readonly _release = new Lazy(() => this.token === "__test__" ? Promise.resolve(null as any) : this.getOrCreateRelease())
3131

3232
private readonly token: string
3333

@@ -37,14 +37,6 @@ export class GitHubPublisher extends HttpPublisher {
3737

3838
private releaseLogFields: Fields | null = null
3939

40-
/** @private */
41-
get releasePromise(): Promise<Release | null> {
42-
if (this._releasePromise == null) {
43-
this._releasePromise = this.token === "__test__" ? BluebirdPromise.resolve(null as any) : this.getOrCreateRelease()
44-
}
45-
return this._releasePromise
46-
}
47-
4840
constructor(context: PublishContext, private readonly info: GithubOptions, private readonly version: string, private readonly options: PublishOptions = {}) {
4941
super(context, true)
5042

@@ -169,7 +161,7 @@ export class GitHubPublisher extends HttpPublisher {
169161
}
170162

171163
protected async doUpload(fileName: string, arch: Arch, dataLength: number, requestProcessor: (request: ClientRequest, reject: (error: Error) => void) => void): Promise<any> {
172-
const release = await this.releasePromise
164+
const release = await this._release.value
173165
if (release == null) {
174166
log.warn({file: fileName, ...this.releaseLogFields}, "skipped publishing")
175167
return
@@ -215,16 +207,16 @@ export class GitHubPublisher extends HttpPublisher {
215207
// test only
216208
//noinspection JSUnusedGlobalSymbols
217209
async getRelease(): Promise<any> {
218-
return this.githubRequest<Release>(`/repos/${this.info.owner}/${this.info.repo}/releases/${(await this._releasePromise)!.id}`, this.token)
210+
return this.githubRequest<Release>(`/repos/${this.info.owner}/${this.info.repo}/releases/${(await this._release.value)!.id}`, this.token)
219211
}
220212

221213
//noinspection JSUnusedGlobalSymbols
222214
async deleteRelease(): Promise<any> {
223-
const release = await this._releasePromise
224-
if (release == null) {
215+
if (!this._release.hasValue) {
225216
return
226217
}
227218

219+
const release = await this._release.value
228220
for (let i = 0; i < 3; i++) {
229221
try {
230222
return await this.githubRequest(`/repos/${this.info.owner}/${this.info.repo}/releases/${release.id}`, this.token, null, "DELETE")

test/src/ArtifactPublisherTest.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ const publishContext: PublishContext = {
3838

3939
test("GitHub unauthorized", async () => {
4040
try {
41-
await new GitHubPublisher(publishContext, {provider: "github", owner: "actperepo", repo: "ecb2", token: "incorrect token"}, versionNumber()).releasePromise
41+
await new GitHubPublisher(publishContext, {provider: "github", owner: "actperepo", repo: "ecb2", token: "incorrect token"}, versionNumber())._release.value
4242
}
4343
catch (e) {
4444
expect(e.message).toMatch(/(Bad credentials|Unauthorized|API rate limit exceeded)/)
@@ -78,7 +78,7 @@ test("Bintray upload", async () => {
7878
const version = versionNumber()
7979

8080
const tmpDir = new TmpDir("artifact-publisher-test")
81-
const artifactPath = await tmpDir.getTempFile({suffix: ".icns"})
81+
const artifactPath = await tmpDir.getTempFile({suffix: " test space.icns"})
8282
await copyFile(iconPath, artifactPath)
8383

8484
//noinspection SpellCheckingInspection

yarn.lock

Lines changed: 49 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,8 @@
127127
"@types/lodash" "*"
128128

129129
"@types/lodash@*":
130-
version "4.14.103"
131-
resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.103.tgz#56ac640f029f67655f0721f479f1faa982bd8122"
130+
version "4.14.104"
131+
resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.104.tgz#53ee2357fa2e6e68379341d92eb2ecea4b11bb80"
132132

133133
"@types/node-emoji@^1.8.0":
134134
version "1.8.0"
@@ -855,15 +855,16 @@ braces@^1.8.2:
855855
repeat-element "^1.1.2"
856856

857857
braces@^2.3.0:
858-
version "2.3.0"
859-
resolved "https://registry.yarnpkg.com/braces/-/braces-2.3.0.tgz#a46941cb5fb492156b3d6a656e06c35364e3e66e"
858+
version "2.3.1"
859+
resolved "https://registry.yarnpkg.com/braces/-/braces-2.3.1.tgz#7086c913b4e5a08dbe37ac0ee6a2500c4ba691bb"
860860
dependencies:
861861
arr-flatten "^1.1.0"
862862
array-unique "^0.3.2"
863863
define-property "^1.0.0"
864864
extend-shallow "^2.0.1"
865865
fill-range "^4.0.0"
866866
isobject "^3.0.1"
867+
kind-of "^6.0.2"
867868
repeat-element "^1.1.2"
868869
snapdragon "^0.8.1"
869870
snapdragon-node "^2.0.1"
@@ -1462,6 +1463,13 @@ define-property@^1.0.0:
14621463
dependencies:
14631464
is-descriptor "^1.0.0"
14641465

1466+
define-property@^2.0.2:
1467+
version "2.0.2"
1468+
resolved "https://registry.yarnpkg.com/define-property/-/define-property-2.0.2.tgz#d459689e8d654ba77e02a817f8710d702cb16e9d"
1469+
dependencies:
1470+
is-descriptor "^1.0.2"
1471+
isobject "^3.0.1"
1472+
14651473
delayed-stream@~1.0.0:
14661474
version "1.0.0"
14671475
resolved "https://registry.yarnpkg.com/delayed-stream/-/delayed-stream-1.0.0.tgz#df3ae199acadfb7d440aaae0b29e2272b24ec619"
@@ -1753,8 +1761,8 @@ es-to-primitive@^1.1.1:
17531761
is-symbol "^1.0.1"
17541762

17551763
es5-ext@^0.10.35, es5-ext@^0.10.9, es5-ext@~0.10.11, es5-ext@~0.10.14, es5-ext@~0.10.2, es5-ext@~0.10.5, es5-ext@~0.10.6:
1756-
version "0.10.38"
1757-
resolved "https://registry.yarnpkg.com/es5-ext/-/es5-ext-0.10.38.tgz#fa7d40d65bbc9bb8a67e1d3f9cc656a00530eed3"
1764+
version "0.10.39"
1765+
resolved "https://registry.yarnpkg.com/es5-ext/-/es5-ext-0.10.39.tgz#fca21b67559277ca4ac1a1ed7048b107b6f76d87"
17581766
dependencies:
17591767
es6-iterator "~2.0.3"
17601768
es6-symbol "~3.1.1"
@@ -1915,7 +1923,7 @@ extend-shallow@^2.0.1:
19151923
dependencies:
19161924
is-extendable "^0.1.0"
19171925

1918-
extend-shallow@^3.0.0:
1926+
extend-shallow@^3.0.0, extend-shallow@^3.0.2:
19191927
version "3.0.2"
19201928
resolved "https://registry.yarnpkg.com/extend-shallow/-/extend-shallow-3.0.2.tgz#26a71aaf073b39fb2127172746131c2704028db8"
19211929
dependencies:
@@ -2106,14 +2114,7 @@ front-matter@^2.1.0:
21062114
dependencies:
21072115
js-yaml "^3.10.0"
21082116

2109-
fs-extra-p@^4.4.4, fs-extra-p@^4.5.0:
2110-
version "4.5.0"
2111-
resolved "https://registry.yarnpkg.com/fs-extra-p/-/fs-extra-p-4.5.0.tgz#b79f3f3fcc0b5e57b7e7caeb06159f958ef15fe8"
2112-
dependencies:
2113-
bluebird-lst "^1.0.5"
2114-
fs-extra "^5.0.0"
2115-
2116-
fs-extra-p@^4.5.2:
2117+
fs-extra-p@^4.4.4, fs-extra-p@^4.5.0, fs-extra-p@^4.5.2:
21172118
version "4.5.2"
21182119
resolved "https://registry.yarnpkg.com/fs-extra-p/-/fs-extra-p-4.5.2.tgz#0a22aba489284d17f375d5dc5139aa777fe2df51"
21192120
dependencies:
@@ -2712,7 +2713,7 @@ is-descriptor@^0.1.0:
27122713
is-data-descriptor "^0.1.4"
27132714
kind-of "^5.0.0"
27142715

2715-
is-descriptor@^1.0.0:
2716+
is-descriptor@^1.0.0, is-descriptor@^1.0.2:
27162717
version "1.0.2"
27172718
resolved "https://registry.yarnpkg.com/is-descriptor/-/is-descriptor-1.0.2.tgz#3b159746a66604b04f8c81524ba365c5f14d86ec"
27182719
dependencies:
@@ -2803,15 +2804,19 @@ is-number@^3.0.0:
28032804
dependencies:
28042805
kind-of "^3.0.2"
28052806

2807+
is-number@^4.0.0:
2808+
version "4.0.0"
2809+
resolved "https://registry.yarnpkg.com/is-number/-/is-number-4.0.0.tgz#0026e37f5454d73e356dfe6564699867c6a7f0ff"
2810+
28062811
is-obj@^1.0.0:
28072812
version "1.0.1"
28082813
resolved "https://registry.yarnpkg.com/is-obj/-/is-obj-1.0.1.tgz#3e4729ac1f5fde025cd7d83a896dab9f4f67db0f"
28092814

2810-
is-odd@^1.0.0:
2811-
version "1.0.0"
2812-
resolved "https://registry.yarnpkg.com/is-odd/-/is-odd-1.0.0.tgz#3b8a932eb028b3775c39bb09e91767accdb69088"
2815+
is-odd@^2.0.0:
2816+
version "2.0.0"
2817+
resolved "https://registry.yarnpkg.com/is-odd/-/is-odd-2.0.0.tgz#7646624671fd7ea558ccd9a2795182f2958f1b24"
28132818
dependencies:
2814-
is-number "^3.0.0"
2819+
is-number "^4.0.0"
28152820

28162821
is-path-inside@^1.0.0:
28172822
version "1.0.1"
@@ -2867,6 +2872,10 @@ is-utf8@^0.2.0:
28672872
version "0.2.1"
28682873
resolved "https://registry.yarnpkg.com/is-utf8/-/is-utf8-0.2.1.tgz#4b0da1442104d1b336340e80797e865cf39f7d72"
28692874

2875+
is-windows@^1.0.2:
2876+
version "1.0.2"
2877+
resolved "https://registry.yarnpkg.com/is-windows/-/is-windows-1.0.2.tgz#d1850eb9791ecd18e6182ce12a30f396634bb19d"
2878+
28702879
is@^3.1.0:
28712880
version "3.2.1"
28722881
resolved "https://registry.yarnpkg.com/is/-/is-3.2.1.tgz#d0ac2ad55eb7b0bec926a5266f6c662aaa83dca5"
@@ -3432,7 +3441,7 @@ kind-of@^4.0.0:
34323441
dependencies:
34333442
is-buffer "^1.1.5"
34343443

3435-
kind-of@^5.0.0, kind-of@^5.0.2:
3444+
kind-of@^5.0.0:
34363445
version "5.1.0"
34373446
resolved "https://registry.yarnpkg.com/kind-of/-/kind-of-5.1.0.tgz#729c91e2d857b7a419a1f9aa65685c4c33f5845d"
34383447

@@ -3672,8 +3681,8 @@ map-visit@^1.0.0:
36723681
object-visit "^1.0.0"
36733682

36743683
marked@^0.3.12, marked@~0.3.6:
3675-
version "0.3.12"
3676-
resolved "https://registry.yarnpkg.com/marked/-/marked-0.3.12.tgz#7cf25ff2252632f3fe2406bde258e94eee927519"
3684+
version "0.3.15"
3685+
resolved "https://registry.yarnpkg.com/marked/-/marked-0.3.15.tgz#de96982e54c880962f5093a2fa93d0866bf73668"
36773686

36783687
media-typer@0.3.0:
36793688
version "0.3.0"
@@ -3762,15 +3771,15 @@ micromatch@^2.1.5, micromatch@^2.3.11:
37623771
parse-glob "^3.0.4"
37633772
regex-cache "^0.4.2"
37643773

3765-
mime-db@~1.30.0:
3766-
version "1.30.0"
3767-
resolved "https://registry.yarnpkg.com/mime-db/-/mime-db-1.30.0.tgz#74c643da2dd9d6a45399963465b26d5ca7d71f01"
3774+
mime-db@~1.33.0:
3775+
version "1.33.0"
3776+
resolved "https://registry.yarnpkg.com/mime-db/-/mime-db-1.33.0.tgz#a3492050a5cb9b63450541e39d9788d2272783db"
37683777

3769-
mime-types@^2.1.12, mime-types@~2.1.15, mime-types@~2.1.17, mime-types@~2.1.7:
3770-
version "2.1.17"
3771-
resolved "https://registry.yarnpkg.com/mime-types/-/mime-types-2.1.17.tgz#09d7a393f03e995a79f8af857b70a9e0ab16557a"
3778+
mime-types@^2.1.12, mime-types@~2.1.17, mime-types@~2.1.18, mime-types@~2.1.7:
3779+
version "2.1.18"
3780+
resolved "https://registry.yarnpkg.com/mime-types/-/mime-types-2.1.18.tgz#6f323f60a83d11146f831ff11fd66e2fe5503bb8"
37723781
dependencies:
3773-
mime-db "~1.30.0"
3782+
mime-db "~1.33.0"
37743783

37753784
mime@1.3.4:
37763785
version "1.3.4"
@@ -3844,16 +3853,17 @@ nan@^2.3.0:
38443853
resolved "https://registry.yarnpkg.com/nan/-/nan-2.8.0.tgz#ed715f3fe9de02b57a5e6252d90a96675e1f085a"
38453854

38463855
nanomatch@^1.2.5:
3847-
version "1.2.7"
3848-
resolved "https://registry.yarnpkg.com/nanomatch/-/nanomatch-1.2.7.tgz#53cd4aa109ff68b7f869591fdc9d10daeeea3e79"
3856+
version "1.2.9"
3857+
resolved "https://registry.yarnpkg.com/nanomatch/-/nanomatch-1.2.9.tgz#879f7150cb2dab7a471259066c104eee6e0fa7c2"
38493858
dependencies:
38503859
arr-diff "^4.0.0"
38513860
array-unique "^0.3.2"
3852-
define-property "^1.0.0"
3853-
extend-shallow "^2.0.1"
3861+
define-property "^2.0.2"
3862+
extend-shallow "^3.0.2"
38543863
fragment-cache "^0.2.1"
3855-
is-odd "^1.0.0"
3856-
kind-of "^5.0.2"
3864+
is-odd "^2.0.0"
3865+
is-windows "^1.0.2"
3866+
kind-of "^6.0.2"
38573867
object.pick "^1.3.0"
38583868
regex-not "^1.0.0"
38593869
snapdragon "^0.8.1"
@@ -5431,11 +5441,11 @@ type-check@~0.3.2:
54315441
prelude-ls "~1.1.2"
54325442

54335443
type-is@~1.6.10:
5434-
version "1.6.15"
5435-
resolved "https://registry.yarnpkg.com/type-is/-/type-is-1.6.15.tgz#cab10fb4909e441c82842eafe1ad646c81804410"
5444+
version "1.6.16"
5445+
resolved "https://registry.yarnpkg.com/type-is/-/type-is-1.6.16.tgz#f89ce341541c672b25ee7ae3c73dee3b2be50194"
54365446
dependencies:
54375447
media-typer "0.3.0"
5438-
mime-types "~2.1.15"
5448+
mime-types "~2.1.18"
54395449

54405450
typescript@2.7.2:
54415451
version "2.7.2"

0 commit comments

Comments
 (0)