Skip to content

Commit e5d97bc

Browse files
committed
fix(deployment): do not fail if cannot resolve effective S3 publish config if not publish will be not performed
Close #2670
1 parent e77769a commit e5d97bc

File tree

7 files changed

+50
-15
lines changed

7 files changed

+50
-15
lines changed

packages/electron-builder-lib/src/publish/PublishManager.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ export class PublishManager implements PublishContext {
8484
return
8585
}
8686

87-
const publishConfig = await getAppUpdatePublishConfiguration(packager, event.arch)
87+
const publishConfig = await getAppUpdatePublishConfiguration(packager, event.arch, this.isPublish)
8888
if (publishConfig != null) {
8989
await writeFile(path.join(packager.getResourcesDir(event.appOutDir), "app-update.yml"), serializeToYaml(publishConfig))
9090
}
@@ -125,7 +125,7 @@ export class PublishManager implements PublishContext {
125125
private async artifactCreated(event: ArtifactCreated) {
126126
const packager = event.packager
127127
const target = event.target
128-
const publishConfigs = event.publishConfig == null ? await getPublishConfigs(packager, target == null ? null : target.options, event.arch) : [event.publishConfig]
128+
const publishConfigs = event.publishConfig == null ? await getPublishConfigs(packager, target == null ? null : target.options, event.arch, this.isPublish) : [event.publishConfig]
129129

130130
if (debug.enabled) {
131131
debug(`artifactCreated (isPublish: ${this.isPublish}): ${safeStringifyJson(event, new Set(["packager"]))},\n publishConfigs: ${safeStringifyJson(publishConfigs)}`)
@@ -188,8 +188,8 @@ export class PublishManager implements PublishContext {
188188
}
189189
}
190190

191-
export async function getAppUpdatePublishConfiguration(packager: PlatformPackager<any>, arch: Arch) {
192-
const publishConfigs = await getPublishConfigsForUpdateInfo(packager, await getPublishConfigs(packager, null, arch), arch)
191+
export async function getAppUpdatePublishConfiguration(packager: PlatformPackager<any>, arch: Arch, errorIfCannot: boolean) {
192+
const publishConfigs = await getPublishConfigsForUpdateInfo(packager, await getPublishConfigs(packager, null, arch, errorIfCannot), arch)
193193
if (publishConfigs == null || publishConfigs.length === 0) {
194194
return null
195195
}
@@ -297,7 +297,7 @@ export function computeDownloadUrl(publishConfiguration: PublishConfiguration, f
297297
return `${baseUrl}/${encodeURI(fileName)}`
298298
}
299299

300-
export async function getPublishConfigs(packager: PlatformPackager<any>, targetSpecificOptions: PlatformSpecificBuildOptions | null | undefined, arch: Arch | null): Promise<Array<PublishConfiguration> | null> {
300+
export async function getPublishConfigs(packager: PlatformPackager<any>, targetSpecificOptions: PlatformSpecificBuildOptions | null | undefined, arch: Arch | null, errorIfCannot: boolean): Promise<Array<PublishConfiguration> | null> {
301301
let publishers
302302

303303
// check build.nsis (target)
@@ -335,7 +335,7 @@ export async function getPublishConfigs(packager: PlatformPackager<any>, targetS
335335

336336
if (serviceName != null) {
337337
log.debug(null, `Detect ${serviceName} as publish provider`)
338-
return [(await getResolvedPublishConfig(packager, {provider: serviceName}, arch))!]
338+
return [(await getResolvedPublishConfig(packager, {provider: serviceName}, arch, errorIfCannot))!]
339339
}
340340
}
341341

@@ -344,7 +344,7 @@ export async function getPublishConfigs(packager: PlatformPackager<any>, targetS
344344
}
345345

346346
debug(`Explicit publish provider: ${safeStringifyJson(publishers)}`)
347-
return await (BluebirdPromise.map(asArray(publishers), it => getResolvedPublishConfig(packager, typeof it === "string" ? {provider: it} : it, arch)) as Promise<Array<PublishConfiguration>>)
347+
return await (BluebirdPromise.map(asArray(publishers), it => getResolvedPublishConfig(packager, typeof it === "string" ? {provider: it} : it, arch, errorIfCannot)) as Promise<Array<PublishConfiguration>>)
348348
}
349349

350350
function isSuitableWindowsTarget(target: Target) {
@@ -371,7 +371,7 @@ function isDetectUpdateChannel(packager: PlatformPackager<any>) {
371371
return value == null ? packager.config.detectUpdateChannel !== false : value
372372
}
373373

374-
async function getResolvedPublishConfig(packager: PlatformPackager<any>, options: PublishConfiguration, arch: Arch | null, errorIfCannot: boolean = true): Promise<PublishConfiguration | GithubOptions | BintrayOptions | null> {
374+
async function getResolvedPublishConfig(packager: PlatformPackager<any>, options: PublishConfiguration, arch: Arch | null, errorIfCannot: boolean): Promise<PublishConfiguration | GithubOptions | BintrayOptions | null> {
375375
options = {...options}
376376
expandPublishConfig(options, packager, arch)
377377

@@ -395,7 +395,7 @@ async function getResolvedPublishConfig(packager: PlatformPackager<any>, options
395395

396396
const providerClass = requireProviderClass(options.provider)
397397
if (providerClass != null && providerClass.checkAndResolveOptions != null) {
398-
await providerClass.checkAndResolveOptions(options, channelFromAppVersion)
398+
await providerClass.checkAndResolveOptions(options, channelFromAppVersion, errorIfCannot)
399399
return options
400400
}
401401

packages/electron-builder-lib/src/targets/AppImageTarget.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export default class AppImageTarget extends Target {
7070
return
7171
}
7272

73-
const publishConfig = await getAppUpdatePublishConfiguration(packager, arch)
73+
const publishConfig = await getAppUpdatePublishConfiguration(packager, arch, false /* in any case validation will be done on publish */)
7474
if (publishConfig != null) {
7575
await outputFile(path.join(packager.getResourcesDir(stageDir.getTempFile("app")), "app-update.yml"), serializeToYaml(publishConfig))
7676
}

packages/electron-builder-lib/src/targets/nsis/WebInstallerTarget.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export class WebInstallerTarget extends NsisTarget {
2323

2424
let appPackageUrl = options.appPackageUrl
2525
if (appPackageUrl == null) {
26-
const publishConfigs = await getPublishConfigsForUpdateInfo(packager, await getPublishConfigs(packager, this.options, null), null)
26+
const publishConfigs = await getPublishConfigsForUpdateInfo(packager, await getPublishConfigs(packager, this.options, null, false), null)
2727
if (publishConfigs == null || publishConfigs.length === 0) {
2828
throw new Error("Cannot compute app package download URL")
2929
}

packages/electron-publisher-s3/src/s3Publisher.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import S3, { ClientConfiguration, ServerSideEncryption, StorageClass } from "aws-sdk/clients/s3"
2-
import { InvalidConfigurationError } from "builder-util"
2+
import { InvalidConfigurationError, log } from "builder-util"
33
import { S3Options } from "builder-util-runtime"
44
import { PublishContext } from "electron-publish"
55
import { BaseS3Publisher } from "./BaseS3Publisher"
@@ -11,7 +11,7 @@ export default class S3Publisher extends BaseS3Publisher {
1111
super(context, info)
1212
}
1313

14-
static async checkAndResolveOptions(options: S3Options, channelFromAppVersion: string | null) {
14+
static async checkAndResolveOptions(options: S3Options, channelFromAppVersion: string | null, errorIfCannot: boolean) {
1515
const bucket = options.bucket
1616
if (bucket == null) {
1717
throw new InvalidConfigurationError(`Please specify "bucket" for "s3" publish provider`)
@@ -20,7 +20,17 @@ export default class S3Publisher extends BaseS3Publisher {
2020
if (options.endpoint == null && (bucket.includes(".") && options.region == null)) {
2121
// on dotted bucket names, we need to use a path-based endpoint URL. Path-based endpoint URLs need to include the region.
2222
const s3 = new S3({signatureVersion: "v4"})
23-
options.region = (await s3.getBucketLocation({Bucket: bucket}).promise()).LocationConstraint
23+
try {
24+
options.region = (await s3.getBucketLocation({Bucket: bucket}).promise()).LocationConstraint
25+
}
26+
catch (e) {
27+
if (errorIfCannot) {
28+
throw e
29+
}
30+
else {
31+
log.warn(`cannot compute region for bucket (required because on dotted bucket names, we need to use a path-based endpoint URL): ${e}`)
32+
}
33+
}
2434
}
2535

2636
if (options.channel == null && channelFromAppVersion != null) {

packages/electron-publisher-s3/src/spacesPublisher.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export default class SpacesPublisher extends BaseS3Publisher {
1111
super(context, info)
1212
}
1313

14-
static async checkAndResolveOptions(options: SpacesOptions, channelFromAppVersion: string | null) {
14+
static async checkAndResolveOptions(options: SpacesOptions, channelFromAppVersion: string | null, errorIfCannot: boolean) {
1515
if (options.name == null) {
1616
throw new InvalidConfigurationError(`Please specify "name" for "spaces" publish provider (see https://www.electron.build/configuration/publish#spacesoptions)`)
1717
}

test/out/windows/__snapshots__/oneClickInstallerTest.js.snap

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3+
exports[`big file pack 1`] = `
4+
Object {
5+
"win": Array [
6+
Object {
7+
"arch": "x64",
8+
"file": "Test App ßW Setup 1.1.0.exe",
9+
"safeArtifactName": "TestApp-Setup-1.1.0.exe",
10+
},
11+
],
12+
}
13+
`;
14+
315
exports[`custom include 1`] = `
416
Object {
517
"win": Array [

test/src/PublishManagerTest.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,17 @@ test.ifAll.ifNotWindows("os macro", app({
5151
await assertThat(dir).isDirectory()
5252
await checkDirContents(dir)
5353
}
54+
}))
55+
56+
// https://github.com/electron-userland/electron-builder/issues/2670
57+
test.ifAll.ifNotWindows("dotted s3 bucket", app({
58+
targets: createTargets([Platform.LINUX], "zip"),
59+
config: {
60+
publish: {
61+
provider: "s3",
62+
bucket: "bucket.dotted.name",
63+
},
64+
},
65+
}, {
66+
publish: "never"
5467
}))

0 commit comments

Comments
 (0)