Skip to content

Commit

Permalink
fix(deployment): do not fail if cannot resolve effective S3 publish c…
Browse files Browse the repository at this point in the history
…onfig if not publish will be not performed

Close #2670
  • Loading branch information
develar committed Mar 10, 2018
1 parent e77769a commit e5d97bc
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 15 deletions.
18 changes: 9 additions & 9 deletions packages/electron-builder-lib/src/publish/PublishManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export class PublishManager implements PublishContext {
return
}

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

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

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

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

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

if (serviceName != null) {
log.debug(null, `Detect ${serviceName} as publish provider`)
return [(await getResolvedPublishConfig(packager, {provider: serviceName}, arch))!]
return [(await getResolvedPublishConfig(packager, {provider: serviceName}, arch, errorIfCannot))!]
}
}

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

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

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

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

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

const providerClass = requireProviderClass(options.provider)
if (providerClass != null && providerClass.checkAndResolveOptions != null) {
await providerClass.checkAndResolveOptions(options, channelFromAppVersion)
await providerClass.checkAndResolveOptions(options, channelFromAppVersion, errorIfCannot)
return options
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export default class AppImageTarget extends Target {
return
}

const publishConfig = await getAppUpdatePublishConfiguration(packager, arch)
const publishConfig = await getAppUpdatePublishConfiguration(packager, arch, false /* in any case validation will be done on publish */)
if (publishConfig != null) {
await outputFile(path.join(packager.getResourcesDir(stageDir.getTempFile("app")), "app-update.yml"), serializeToYaml(publishConfig))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class WebInstallerTarget extends NsisTarget {

let appPackageUrl = options.appPackageUrl
if (appPackageUrl == null) {
const publishConfigs = await getPublishConfigsForUpdateInfo(packager, await getPublishConfigs(packager, this.options, null), null)
const publishConfigs = await getPublishConfigsForUpdateInfo(packager, await getPublishConfigs(packager, this.options, null, false), null)
if (publishConfigs == null || publishConfigs.length === 0) {
throw new Error("Cannot compute app package download URL")
}
Expand Down
16 changes: 13 additions & 3 deletions packages/electron-publisher-s3/src/s3Publisher.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import S3, { ClientConfiguration, ServerSideEncryption, StorageClass } from "aws-sdk/clients/s3"
import { InvalidConfigurationError } from "builder-util"
import { InvalidConfigurationError, log } from "builder-util"
import { S3Options } from "builder-util-runtime"
import { PublishContext } from "electron-publish"
import { BaseS3Publisher } from "./BaseS3Publisher"
Expand All @@ -11,7 +11,7 @@ export default class S3Publisher extends BaseS3Publisher {
super(context, info)
}

static async checkAndResolveOptions(options: S3Options, channelFromAppVersion: string | null) {
static async checkAndResolveOptions(options: S3Options, channelFromAppVersion: string | null, errorIfCannot: boolean) {
const bucket = options.bucket
if (bucket == null) {
throw new InvalidConfigurationError(`Please specify "bucket" for "s3" publish provider`)
Expand All @@ -20,7 +20,17 @@ export default class S3Publisher extends BaseS3Publisher {
if (options.endpoint == null && (bucket.includes(".") && options.region == null)) {
// on dotted bucket names, we need to use a path-based endpoint URL. Path-based endpoint URLs need to include the region.
const s3 = new S3({signatureVersion: "v4"})
options.region = (await s3.getBucketLocation({Bucket: bucket}).promise()).LocationConstraint
try {
options.region = (await s3.getBucketLocation({Bucket: bucket}).promise()).LocationConstraint
}
catch (e) {
if (errorIfCannot) {
throw e
}
else {
log.warn(`cannot compute region for bucket (required because on dotted bucket names, we need to use a path-based endpoint URL): ${e}`)
}
}
}

if (options.channel == null && channelFromAppVersion != null) {
Expand Down
2 changes: 1 addition & 1 deletion packages/electron-publisher-s3/src/spacesPublisher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default class SpacesPublisher extends BaseS3Publisher {
super(context, info)
}

static async checkAndResolveOptions(options: SpacesOptions, channelFromAppVersion: string | null) {
static async checkAndResolveOptions(options: SpacesOptions, channelFromAppVersion: string | null, errorIfCannot: boolean) {
if (options.name == null) {
throw new InvalidConfigurationError(`Please specify "name" for "spaces" publish provider (see https://www.electron.build/configuration/publish#spacesoptions)`)
}
Expand Down
12 changes: 12 additions & 0 deletions test/out/windows/__snapshots__/oneClickInstallerTest.js.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`big file pack 1`] = `
Object {
"win": Array [
Object {
"arch": "x64",
"file": "Test App ßW Setup 1.1.0.exe",
"safeArtifactName": "TestApp-Setup-1.1.0.exe",
},
],
}
`;

exports[`custom include 1`] = `
Object {
"win": Array [
Expand Down
13 changes: 13 additions & 0 deletions test/src/PublishManagerTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,17 @@ test.ifAll.ifNotWindows("os macro", app({
await assertThat(dir).isDirectory()
await checkDirContents(dir)
}
}))

// https://github.com/electron-userland/electron-builder/issues/2670
test.ifAll.ifNotWindows("dotted s3 bucket", app({
targets: createTargets([Platform.LINUX], "zip"),
config: {
publish: {
provider: "s3",
bucket: "bucket.dotted.name",
},
},
}, {
publish: "never"
}))

0 comments on commit e5d97bc

Please sign in to comment.