Skip to content

Commit

Permalink
feat(deployment): publish patterned name if it conforms to GitHub rules
Browse files Browse the repository at this point in the history
  • Loading branch information
develar committed Aug 18, 2017
1 parent 83b1cd7 commit e4430c5
Show file tree
Hide file tree
Showing 14 changed files with 40 additions and 34 deletions.
2 changes: 1 addition & 1 deletion packages/electron-builder-http/src/updateInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export interface VersionInfo {

export interface UpdateInfo extends VersionInfo {
readonly path: string
readonly githubArtifactName?: string | null
githubArtifactName?: string | null

/**
* The release name.
Expand Down
7 changes: 4 additions & 3 deletions packages/electron-builder/src/macPackager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,10 @@ export default class MacPackager extends PlatformPackager<MacOptions> {
throw new Error(`Cannot find valid "${certType}" identity to sign MAS installer, please see https://github.com/electron-userland/electron-builder/wiki/Code-Signing`)
}

const pkg = path.join(outDir!, this.expandArtifactNamePattern(masOptions, "pkg"))
await this.doFlat(appPath, pkg, masInstallerIdentity, keychainName)
this.dispatchArtifactCreated(pkg, null, Arch.x64, this.computeSafeArtifactName("pkg"))
const artifactName = this.expandArtifactNamePattern(masOptions, "pkg")
const artifactPath = path.join(outDir!, artifactName)
await this.doFlat(appPath, artifactPath, masInstallerIdentity, keychainName)
this.dispatchArtifactCreated(artifactPath, null, Arch.x64, this.computeSafeArtifactName(artifactName, "pkg"))
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/electron-builder/src/packagerApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export interface ArtifactCreated {
readonly file?: string
readonly data?: Buffer

readonly safeArtifactName?: string
readonly safeArtifactName?: string | null

readonly publishConfig?: PublishConfiguration

Expand Down
11 changes: 8 additions & 3 deletions packages/electron-builder/src/platformPackager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export abstract class PlatformPackager<DC extends PlatformSpecificBuildOptions>
return this.packagerOptions.prepackaged || path.join(outDir, `${this.platform.buildConfigurationKey}${getArchSuffix(arch)}${this.platform === Platform.MAC ? "" : "-unpacked"}`)
}

dispatchArtifactCreated(file: string, target: Target | null, arch: Arch | null, safeArtifactName?: string) {
dispatchArtifactCreated(file: string, target: Target | null, arch: Arch | null, safeArtifactName?: string | null) {
this.info.dispatchArtifactCreated({
file, safeArtifactName, target, arch,
packager: this,
Expand Down Expand Up @@ -350,7 +350,12 @@ export abstract class PlatformPackager<DC extends PlatformSpecificBuildOptions>
await this.checkFileInPackage(resourcesDir, "package.json", "Application", isAsar)
}

computeSafeArtifactName(ext: string, arch?: Arch | null, skipArchIfX64 = true) {
computeSafeArtifactName(suggestedName: string | null, ext: string, arch?: Arch | null, skipArchIfX64 = true): string | null {
// GitHub only allows the listed characters in file names.
if (suggestedName != null && /^[0-9A-Za-z._-]+$/.test(suggestedName)) {
return null
}

// tslint:disable:no-invalid-template-strings
return this.computeArtifactName("${name}-${version}-${arch}.${ext}", ext, skipArchIfX64 && arch === Arch.x64 ? null : arch)
}
Expand Down Expand Up @@ -542,4 +547,4 @@ export abstract class PlatformPackager<DC extends PlatformSpecificBuildOptions>
// remove leading dot
export function normalizeExt(ext: string) {
return ext.startsWith(".") ? ext.substring(1) : ext
}
}
10 changes: 7 additions & 3 deletions packages/electron-builder/src/publish/PublishManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ export class PublishManager implements PublishContext {

private getOrCreatePublisher(publishConfig: PublishConfiguration, platformPackager: PlatformPackager<any>, target: Target | null): Publisher | null {
let providerCacheKey = `${publishConfig.provider}-${platformPackager.platform.name}`
if (target) {
if (target != null) {
providerCacheKey += `-${target.name}`
}

Expand Down Expand Up @@ -281,9 +281,13 @@ async function writeUpdateInfo(event: ArtifactCreated, _publishConfigs: Array<Pu
const info: UpdateInfo = {
version,
releaseDate: new Date().toISOString(),
githubArtifactName: event.safeArtifactName,
path: path.basename(event.file!),
sha512: await sha512.value, ...releaseInfo as UpdateInfo}
sha512: await sha512.value, ...releaseInfo as UpdateInfo,
}

if (event.safeArtifactName != null) {
info.githubArtifactName = event.safeArtifactName
}

if (packager.platform === Platform.WINDOWS) {
// backward compatibility
Expand Down
7 changes: 4 additions & 3 deletions packages/electron-builder/src/targets/appImage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ export default class AppImageTarget extends Target {

// https://github.com/electron-userland/electron-builder/issues/775
// https://github.com/electron-userland/electron-builder/issues/1726
const resultFile = path.join(this.outDir, this.options.artifactName == null ? packager.computeSafeArtifactName("AppImage", arch, false) : packager.expandArtifactNamePattern(this.options, "AppImage", arch))
const artifactName = this.options.artifactName == null ? packager.computeSafeArtifactName(null, "AppImage", arch, false)!! : packager.expandArtifactNamePattern(this.options, "AppImage", arch)
const resultFile = path.join(this.outDir, artifactName)
await unlinkIfExists(resultFile)

const appImagePath = await appImagePathPromise
Expand Down Expand Up @@ -99,6 +100,6 @@ export default class AppImageTarget extends Target {

await chmod(resultFile, "0755")

packager.dispatchArtifactCreated(resultFile, this, arch, packager.computeSafeArtifactName("AppImage", arch, false))
packager.dispatchArtifactCreated(resultFile, this, arch, packager.computeSafeArtifactName(artifactName, "AppImage", arch, false))
}
}
}
11 changes: 6 additions & 5 deletions packages/electron-builder/src/targets/appx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,9 @@ export default class AppXTarget extends Target {
taskManager.addTask(copyDir(appOutDir, path.join(preAppx, "app")))
await taskManager.awaitTasks()

const destination = path.join(this.outDir, packager.expandArtifactNamePattern(this.options, "appx", arch))
const makeAppXArgs = ["pack", "/o", "/d", preAppx, "/p", destination]
const artifactName = packager.expandArtifactNamePattern(this.options, "appx", arch)
const artifactPath = path.join(this.outDir, artifactName)
const makeAppXArgs = ["pack", "/o", "/d", preAppx, "/p", artifactPath]

// we do not use process.arch to build path to tools, because even if you are on x64, ia32 appx tool must be used if you build appx for ia32
if (isScaledAssetsProvided(userAssets)) {
Expand All @@ -99,13 +100,13 @@ export default class AppXTarget extends Target {
use(this.options.makeappxArgs, (it: Array<string>) => makeAppXArgs.push(...it))
// wine supports only ia32 binary in any case makeappx crashed on wine
await spawn(path.join(vendorPath, "windows-10", Arch[arch], "makeappx.exe"), makeAppXArgs, undefined, {isDebugEnabled: debug.enabled})
await packager.sign(destination)
await packager.sign(artifactPath)

packager.info.dispatchArtifactCreated({
file: destination,
file: artifactPath,
packager,
arch,
safeArtifactName: packager.computeSafeArtifactName("appx"),
safeArtifactName: packager.computeSafeArtifactName(artifactName, "appx"),
target: this,
isWriteUpdateInfo: this.options.electronUpdaterAware,
})
Expand Down
5 changes: 3 additions & 2 deletions packages/electron-builder/src/targets/dmg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@ export class DmgTarget extends Target {
return
}

const artifactPath = path.join(this.outDir, packager.expandArtifactNamePattern(packager.config.dmg, "dmg"))
const artifactName = packager.expandArtifactNamePattern(packager.config.dmg, "dmg")
const artifactPath = path.join(this.outDir, artifactName)

// dmg file must not exist otherwise hdiutil failed (https://github.com/electron-userland/electron-builder/issues/1308#issuecomment-282847594), so, -ov must be specified
//noinspection SpellCheckingInspection
Expand All @@ -176,7 +177,7 @@ export class DmgTarget extends Target {

await addLicenseToDmg(packager, artifactPath)

this.packager.dispatchArtifactCreated(artifactPath, this, arch, packager.computeSafeArtifactName("dmg"))
this.packager.dispatchArtifactCreated(artifactPath, this, arch, packager.computeSafeArtifactName(artifactName, "dmg"))
}

computeVolumeName(custom?: string | null): string {
Expand Down
7 changes: 4 additions & 3 deletions packages/electron-builder/src/targets/pkg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,18 @@ export class PkgTarget extends Target {
throw new Error(`Cannot find valid "${certType}" to sign standalone installer, please see https://github.com/electron-userland/electron-builder/wiki/Code-Signing`)
}

const outFile = path.join(appOutDir, packager.expandArtifactNamePattern(options, "pkg"))
const artifactName = packager.expandArtifactNamePattern(options, "pkg")
const artifactPath = path.join(appOutDir, artifactName)
const args = prepareProductBuildArgs(identity, keychainName)
args.push("--distribution", distInfoFile)
args.push(outFile)
args.push(artifactPath)
use(options.productbuild, it => args.push(...it as any))
await exec("productbuild", args, {
cwd: appOutDir,
})
await BluebirdPromise.all([unlink(innerPackageFile), unlink(distInfoFile)])

packager.dispatchArtifactCreated(outFile, this, arch, packager.computeSafeArtifactName("pkg", arch))
packager.dispatchArtifactCreated(artifactPath, this, arch, packager.computeSafeArtifactName(artifactName, "pkg", arch))
}

private async customizeDistributionConfiguration(distInfoFile: string, appPath: string) {
Expand Down
2 changes: 1 addition & 1 deletion packages/electron-publish/src/publisher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export abstract class Publisher {

abstract get providerName(): string

abstract upload(file: string, arch: Arch, safeArtifactName?: string): Promise<any>
abstract upload(file: string, arch: Arch, safeArtifactName?: string | null): Promise<any>

protected createProgressBar(fileName: string, fileStat: Stats): ProgressBar | null {
if (this.context.progress == null) {
Expand Down
4 changes: 1 addition & 3 deletions test/out/__snapshots__/ExtraBuildTest.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ Object {
Object {
"arch": "x64",
"file": "TestApp-1.1.0-x86_64.AppImage",
"safeArtifactName": "TestApp-1.1.0-x86_64.AppImage",
},
],
}
Expand Down Expand Up @@ -97,7 +96,7 @@ Object {
`;

exports[`scheme validation 1`] = `
"Config is invalid:
"Configuration is invalid:
{
\\"foo\\": \\"Unknown option\\",
\\"mac\\": [
Expand Down Expand Up @@ -136,7 +135,6 @@ Object {
Object {
"arch": "x64",
"file": "TestApp-1.1.0-x86_64.AppImage",
"safeArtifactName": "TestApp-1.1.0-x86_64.AppImage",
},
Object {
"arch": "ia32",
Expand Down
2 changes: 0 additions & 2 deletions test/out/linux/__snapshots__/linuxPackagerTest.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ Object {
Object {
"arch": "x64",
"file": "TestApp-1.1.0-x86_64.AppImage",
"safeArtifactName": "TestApp-1.1.0-x86_64.AppImage",
},
],
}
Expand All @@ -43,7 +42,6 @@ Object {
Object {
"arch": "x64",
"file": "TestApp-1.1.0-x86_64.AppImage",
"safeArtifactName": "TestApp-1.1.0-x86_64.AppImage",
},
],
}
Expand Down
3 changes: 0 additions & 3 deletions test/out/mac/__snapshots__/dmgTest.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ Object {
Object {
"arch": "x64",
"file": "NoApplicationsLink-1.1.0.dmg",
"safeArtifactName": "TestApp-1.1.0.dmg",
},
Object {
"arch": "x64",
Expand All @@ -98,7 +97,6 @@ Object {
Object {
"arch": "x64",
"file": "NoBackground-1.1.0.dmg",
"safeArtifactName": "TestApp-1.1.0.dmg",
},
],
}
Expand All @@ -112,7 +110,6 @@ Object {
Object {
"arch": "x64",
"file": "NoBuildDirectory-1.1.0.dmg",
"safeArtifactName": "TestApp-1.1.0.dmg",
},
],
}
Expand Down
1 change: 0 additions & 1 deletion test/out/mac/__snapshots__/macPackagerTest.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ Object {
Object {
"arch": "x64",
"file": "TestApp-1.1.0-mac.dmg",
"safeArtifactName": "TestApp-1.1.0.dmg",
},
Object {
"file": "latest-mac.json",
Expand Down

0 comments on commit e4430c5

Please sign in to comment.