Skip to content

Commit

Permalink
fix(deployment): when releasing for macOS & Windows at once, all file…
Browse files Browse the repository at this point in the history
…s get uploaded to path in mac publish config

Close #1323
  • Loading branch information
develar committed Jul 11, 2017
1 parent ee82371 commit c2e656e
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 12 deletions.
11 changes: 6 additions & 5 deletions packages/electron-builder/src/publish/PublishManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ export class PublishManager implements PublishContext {
break
}

const publisher = this.getOrCreatePublisher(publishConfig, packager.info)
const publisher = this.getOrCreatePublisher(publishConfig, packager)
if (publisher == null) {
debug(`${eventFile} is not published: publisher is null, ${safeStringifyJson(publishConfig)}`)
continue
Expand All @@ -158,11 +158,12 @@ export class PublishManager implements PublishContext {
}
}

private getOrCreatePublisher(publishConfig: PublishConfiguration, buildInfo: Packager): Publisher | null {
let publisher = this.nameToPublisher.get(publishConfig.provider)
private getOrCreatePublisher(publishConfig: PublishConfiguration, platformPackager: PlatformPackager<any>): Publisher | null {
const providerCacheKey = `${publishConfig.provider}-${platformPackager.platform.name}`
let publisher = this.nameToPublisher.get(providerCacheKey)
if (publisher == null) {
publisher = createPublisher(this, buildInfo.metadata.version!, publishConfig, this.publishOptions)
this.nameToPublisher.set(publishConfig.provider, publisher)
publisher = createPublisher(this, platformPackager.info.metadata.version!, publishConfig, this.publishOptions)
this.nameToPublisher.set(providerCacheKey, publisher)
log(`Publishing to ${publisher}`)
}
return publisher
Expand Down
14 changes: 12 additions & 2 deletions packages/electron-publisher-s3/src/s3Publisher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { S3Options } from "electron-builder-http/out/publishOptions"
import { debug } from "electron-builder-util"
import { PublishContext, Publisher } from "electron-publish"
import { ProgressCallback } from "electron-publish/out/progress"
import { stat } from "fs-extra-p"
import { ensureDir, stat, symlink } from "fs-extra-p"
import * as path from "path"
import { basename } from "path"
import { S3Client } from "./uploader"

Expand Down Expand Up @@ -40,7 +41,16 @@ export default class S3Publisher extends Publisher {
const client = new S3Client({s3Options: {signatureVersion: "v4"}})
const cancellationToken = this.context.cancellationToken

const uploader = client.createFileUploader(file, (this.info.path == null ? "" : `${this.info.path}/`) + fileName, {
const target = (this.info.path == null ? "" : `${this.info.path}/`) + fileName

if (process.env.__TEST_S3_PUBLISHER__ != null) {
const testFile = path.join(process.env.__TEST_S3_PUBLISHER__!, target)
await ensureDir(path.dirname(testFile))
await symlink(file, testFile)
return
}

const uploader = client.createFileUploader(file, target, {
Bucket: this.info.bucket!,
ACL: this.info.acl || "public-read",
StorageClass: this.info.storageClass || undefined
Expand Down
39 changes: 39 additions & 0 deletions test/out/__snapshots__/PublishManagerTest.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,42 @@ Object {
],
}
`;

exports[`os macro 1`] = `
Object {
"linux": Array [
Object {
"arch": "x64",
"file": "TestApp-1.1.0.zip",
"safeArtifactName": "TestApp-1.1.0.zip",
},
],
"mac": Array [
Object {
"file": "latest-mac.json",
},
Object {
"file": "latest-mac.yml",
"fileContent": Object {
"githubArtifactName": "TestApp-1.1.0-mac.zip",
"path": "Test App ßW-1.1.0-mac.zip",
"version": "1.1.0",
},
},
Object {
"arch": "x64",
"file": "Test App ßW-1.1.0-mac.zip",
"safeArtifactName": "TestApp-1.1.0-mac.zip",
},
],
}
`;

exports[`os macro 2`] = `
Array [
"latest/mac/Test App ßW-1.1.0-mac.zip",
"latest/mac/latest-mac.json",
"latest/mac/latest-mac.yml",
"latest/linux/TestApp-1.1.0.zip",
]
`;
6 changes: 3 additions & 3 deletions test/out/windows/__snapshots__/appxTest.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ exports[`AppX 1`] = `
Object {
"win": Array [
Object {
"arch": 0,
"arch": "ia32",
"file": "Test App ßW-1.1.0-ia32.appx",
"safeArtifactName": "TestApp-1.1.0.appx",
},
Object {
"arch": 1,
"arch": "x64",
"file": "Test App ßW-1.1.0.appx",
"safeArtifactName": "TestApp-1.1.0.appx",
},
Expand All @@ -21,7 +21,7 @@ exports[`languages 1`] = `
Object {
"win": Array [
Object {
"arch": 1,
"arch": "x64",
"file": "Test App ßW-1.1.0.appx",
"safeArtifactName": "TestApp-1.1.0.appx",
},
Expand Down
25 changes: 24 additions & 1 deletion test/src/PublishManagerTest.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { Platform } from "electron-builder"
import { createTargets, Platform } from "electron-builder"
import { walk } from "electron-builder-util/out/fs"
import * as path from "path"
import { app } from "./helpers/packTester"

const target = Platform.MAC.createTarget("zip")
Expand All @@ -17,4 +19,25 @@ test.ifDevOrLinuxCi("generic and github", app({
},
]
},
}))

test.ifAll.ifNotWindows("os macro", app({
targets: createTargets([Platform.LINUX, Platform.MAC], "zip"),
config: {
publish: {
provider: "s3",
bucket: "my bucket",
// tslint:disable:no-invalid-template-strings
path: "${channel}/${os}"
}
},
}, {
publish: "always",
projectDirCreated: async projectDir => {
process.env.__TEST_S3_PUBLISHER__ = path.join(projectDir, "dist/s3")
},
packed: async context => {
const dir = path.join(context.projectDir, "dist/s3")
expect((await walk(dir, file => !path.basename(file).startsWith("."))).map(it => it.substring(dir.length + 1))).toMatchSnapshot()
}
}))
5 changes: 4 additions & 1 deletion test/src/helpers/packTester.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { executeFinally } from "electron-builder-util/out/promise"
import { PublishManager } from "electron-builder/out/publish/PublishManager"
import { computeArchToTargetNamesMap } from "electron-builder/out/targets/targetFactory"
import { getLinuxToolsPath } from "electron-builder/out/util/bundledTool"
import { PublishPolicy } from "electron-publish"
import { emptyDir, mkdir, readFile, readJson, remove, writeJson } from "fs-extra-p"
import { safeLoad } from "js-yaml"
import * as path from "path"
Expand Down Expand Up @@ -37,6 +38,8 @@ interface AssertPackOptions {
readonly signedWin?: boolean

readonly installDepsBefore?: boolean

readonly publish?: PublishPolicy
}

export interface PackedContext {
Expand Down Expand Up @@ -155,7 +158,7 @@ export function getFixtureDir() {
async function packAndCheck(packagerOptions: PackagerOptions, checkOptions: AssertPackOptions) {
const cancellationToken = new CancellationToken()
const packager = new Packager(packagerOptions, cancellationToken)
const publishManager = new PublishManager(packager, {publish: "never"}, cancellationToken)
const publishManager = new PublishManager(packager, {publish: checkOptions.publish || "never"}, cancellationToken)

const artifacts: Map<Platform, Array<ArtifactCreated>> = new Map()
packager.artifactCreated(event => {
Expand Down

0 comments on commit c2e656e

Please sign in to comment.