Skip to content

Commit

Permalink
feat: automatically set channel to version prerelease component
Browse files Browse the repository at this point in the history
BREAKING CHANGE: if app version is `0.12.1-alpha.1`, file `alpha.yml` will be generated instead of `latest.yml`

Close electron-userland#1182
  • Loading branch information
develar committed Apr 15, 2017
1 parent 2c52ed2 commit 39af98a
Show file tree
Hide file tree
Showing 13 changed files with 90 additions and 33 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"electron-is-dev": "^0.1.2",
"electron-osx-sign": "0.4.4",
"fs-extra-p": "^4.1.0",
"hosted-git-info": "^2.4.1",
"hosted-git-info": "^2.4.2",
"ini": "^1.3.4",
"is-ci": "^1.0.10",
"isbinaryfile": "^3.0.2",
Expand All @@ -60,7 +60,7 @@
"tunnel-agent": "^0.6.0",
"update-notifier": "^2.1.0",
"uuid-1345": "^0.99.6",
"yargs": "^7.0.2"
"yargs": "^7.1.0"
},
"devDependencies": {
"@develar/typescript-json-schema": "0.11.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/electron-builder-http/src/publishOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ export interface PublishConfiguration {
* The owner.
*/
readonly owner?: string | null

readonly token?: string | null
}

/**
Expand Down Expand Up @@ -172,6 +170,8 @@ export interface BintrayOptions extends PublishConfiguration {
* The Bintray user account. Used in cases where the owner is an organization.
*/
readonly user?: string | null

readonly token?: string | null
}

export interface VersionInfo {
Expand Down
4 changes: 2 additions & 2 deletions packages/electron-builder/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"electron-osx-sign": "0.4.4",
"electron-publish": "0.0.0-semantic-release",
"fs-extra-p": "^4.1.0",
"hosted-git-info": "^2.4.1",
"hosted-git-info": "^2.4.2",
"is-ci": "^1.0.10",
"isbinaryfile": "^3.0.2",
"js-yaml": "^3.8.3",
Expand All @@ -71,7 +71,7 @@
"semver": "^5.3.0",
"update-notifier": "^2.1.0",
"uuid-1345": "^0.99.6",
"yargs": "^7.0.2"
"yargs": "^7.1.0"
},
"typings": "./out/electron-builder.d.ts",
"publishConfig": {
Expand Down
22 changes: 18 additions & 4 deletions packages/electron-builder/src/publish/PublishManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { createReadStream, ensureDir, outputJson, writeFile } from "fs-extra-p"
import isCi from "is-ci"
import { safeDump } from "js-yaml"
import * as path from "path"
import { prerelease } from "semver"
import * as url from "url"
import { Packager } from "../packager"
import { ArtifactCreated, BuildInfo } from "../packagerApi"
Expand Down Expand Up @@ -441,18 +442,31 @@ function expandPublishConfig(options: any, packager: PlatformPackager<any>, arch
async function getResolvedPublishConfig(packager: PlatformPackager<any>, options: PublishConfiguration, arch: Arch | null, errorIfCannot: boolean = true): Promise<PublishConfiguration | null> {
options = Object.assign(Object.create(null), options)
expandPublishConfig(options, packager, arch)


let channelFromAppVersion: string | null = null
if ((<any>options).channel == null) {
const prereleaseInfo = prerelease(packager.appInfo.version)
if (prereleaseInfo != null && prereleaseInfo.length > 0) {
channelFromAppVersion = prereleaseInfo[0]
}
}

const provider = options.provider
if (provider === "generic") {
if ((<GenericServerOptions>options).url == null) {
const o = <GenericServerOptions>options
if (o.url == null) {
throw new Error(`Please specify "url" for "generic" update server`)
}

if (channelFromAppVersion != null) {
(<any>o).channel = channelFromAppVersion
}
return options
}

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

Expand Down Expand Up @@ -505,7 +519,7 @@ async function getResolvedPublishConfig(packager: PlatformPackager<any>, options
}

if (isGithub) {
if (options.token != null && !(<GithubOptions>options).private) {
if ((<GithubOptions>options).token != null && !(<GithubOptions>options).private) {
warn('"token" specified in the github publish options. It should be used only for [setFeedURL](module:electron-updater/out/AppUpdater.AppUpdater+setFeedURL).')
}
return Object.assign({owner, repo: project}, options)
Expand Down
7 changes: 4 additions & 3 deletions packages/electron-builder/src/targets/nsis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,8 @@ export class NsisTarget extends Target {
const command = path.join(nsisPath, process.platform === "darwin" ? "mac" : (process.platform === "win32" ? "Bin" : "linux"), process.platform === "win32" ? "makensis.exe" : "makensis")
const childProcess = doSpawn(command, args, {
// we use NSIS_CONFIG_CONST_DATA_PATH=no to build makensis on Linux, but in any case it doesn't use stubs as MacOS/Windows version, so, we explicitly set NSISDIR
env: Object.assign({}, process.env, {NSISDIR: nsisPath}),
// set LC_CTYPE to avoid crash https://github.com/electron-userland/electron-builder/issues/503 Even "en_DE.UTF-8" leads to error.
env: Object.assign({}, process.env, {NSISDIR: nsisPath, LC_CTYPE: "en_US.UTF-8"}),
cwd: this.nsisTemplatesDir,
}, true)
handleProcess("close", childProcess, command, resolve, error => {
Expand All @@ -416,10 +417,10 @@ export class NsisTarget extends Target {

private async computeFinalScript(originalScript: string, isInstaller: boolean) {
const packager = this.packager
let scriptHeader = `!addincludedir "${path.win32.join(__dirname, "..", "..", "templates", "nsis", "include")}"\n`
let scriptHeader = `!addincludedir "${path.join(__dirname, "..", "..", "templates", "nsis", "include")}"\n`

const addCustomMessageFileInclude = async (input: string) => {
return "!include " + await this.writeCustomLangFile(computeCustomMessageTranslations(safeLoad(await readFile(path.join(this.nsisTemplatesDir, input), "utf-8"))).join("\n")) + "\n"
return '!include "' + await this.writeCustomLangFile(computeCustomMessageTranslations(safeLoad(await readFile(path.join(this.nsisTemplatesDir, input), "utf-8"))).join("\n")) + '"\n'
}

const tasks: Array<() => Promise<any>> = [
Expand Down
6 changes: 5 additions & 1 deletion packages/electron-publisher-s3/src/s3Publisher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default class S3Publisher extends Publisher {
debug(`Creating S3 Publisher — bucket: ${info.bucket}`)
}

static async checkAndResolveOptions(options: S3Options) {
static async checkAndResolveOptions(options: S3Options, channelFromAppVersion: string | null) {
const bucket = options.bucket
if (bucket == null) {
throw new Error(`Please specify "bucket" for "s3" update server`)
Expand All @@ -27,6 +27,10 @@ export default class S3Publisher extends Publisher {
const s3 = new S3({signatureVersion: "v4"});
(<any>options).region = (await s3.getBucketLocation({Bucket: bucket}).promise()).LocationConstraint
}

if (options.channel == null && channelFromAppVersion != null) {
(<any>options).channel = channelFromAppVersion
}
}

// http://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/s3-example-creating-buckets.html
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/app-executable-deps/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"build": {
"electronVersion": "1.6.3",
"electronVersion": "1.6.6",
"category": "public.app-category.business"
}
}
2 changes: 1 addition & 1 deletion test/fixtures/test-app-one/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"author": "Foo Bar <[email protected]>",
"license": "MIT",
"build": {
"electronVersion": "1.6.3",
"electronVersion": "1.6.6",
"appId": "org.electron-builder.testApp",
"compression": "store",
"npmRebuild": false,
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/test-app/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"build": {
"electronVersion": "1.6.3",
"electronVersion": "1.6.6",
"appId": "org.electron-builder.testApp",
"compression": "store",
"npmRebuild": false,
Expand Down
24 changes: 22 additions & 2 deletions test/out/__snapshots__/ExtraBuildTest.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,35 @@ Object {
exports[`override targets in the config - only arch 1`] = `
Object {
"win": Array [
Object {
"arch": null,
"file": "beta.yml",
},
Object {
"arch": 0,
"file": "Test App ßW Setup 1.1.0.exe",
"safeArtifactName": "TestApp-Setup-1.1.0.exe",
"file": "Test App ßW Setup 1.0.0-beta.1.exe",
"safeArtifactName": "TestApp-Setup-1.0.0-beta.1.exe",
},
],
}
`;

exports[`override targets in the config - only arch 2`] = `
Object {
"channel": "beta",
"provider": "generic",
"url": "https://develar.s3.amazonaws.com/test",
}
`;

exports[`override targets in the config - only arch 3`] = `
Object {
"githubArtifactName": "TestApp-Setup-1.0.0-beta.1.exe",
"path": "Test App ßW Setup 1.0.0-beta.1.exe",
"version": "1.0.0-beta.1",
}
`;

exports[`override targets in the config 1`] = `
Object {
"linux": Array [],
Expand Down
22 changes: 20 additions & 2 deletions test/src/ExtraBuildTest.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { Arch, DIR_TARGET, Platform } from "electron-builder"
import { build } from "electron-builder/out/builder"
import { move } from "fs-extra-p"
import { move, readFile } from "fs-extra-p"
import { safeLoad } from "js-yaml"
import * as path from "path"
import { assertThat } from "./helpers/fileAssert"
import { app, appThrows } from "./helpers/packTester"
import { expectUpdateMetadata } from "./helpers/winHelper"

function createBuildResourcesTest(platform: Platform) {
return app({
Expand Down Expand Up @@ -77,20 +79,36 @@ test.ifAll.ifDevOrLinuxCi("override targets in the config", app({
}
}))


// test https://github.com/electron-userland/electron-builder/issues/1182 also
test.ifAll.ifDevOrWinCi("override targets in the config - only arch", app({
targets: Platform.WINDOWS.createTarget(null, Arch.ia32),
appMetadata: {
version: "1.0.0-beta.1",
},
config: {
// https://github.com/electron-userland/electron-builder/issues/1348
win: {
target: [
"nsis",
],
},
publish: {
provider: "generic",
url: "https://develar.s3.amazonaws.com/test",
},
},
}, {
packed: async (context) => {
await assertThat(path.join(context.projectDir, "dist", "win-unpacked")).doesNotExist()
await assertThat(path.join(context.projectDir, "dist", "latest.yml")).doesNotExist()
await expectUpdateMetadata(context, Arch.ia32)

const updateInfo = safeLoad(await readFile(path.join(context.outDir, "beta.yml"), "utf-8"))
expect(updateInfo.sha2).not.toEqual("")
expect(updateInfo.releaseDate).not.toEqual("")
delete updateInfo.sha2
delete updateInfo.releaseDate
expect(updateInfo).toMatchSnapshot()
},
}))

Expand Down
2 changes: 1 addition & 1 deletion test/src/helpers/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ docker: Error response from daemon: Mounts denied: o Docker.
*/
const baseDir = process.env.ELECTRON_BUILDER_TEST_DIR || (process.platform === "darwin" && !require("is-ci") ? "/tmp" : tmpdir())
export const TEST_DIR = path.join(baseDir, `et-${createHash("md5").update(__dirname).digest("hex")}`)
export const ELECTRON_VERSION = "1.6.3"
export const ELECTRON_VERSION = "1.6.6"
22 changes: 11 additions & 11 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,8 @@ arr-diff@^2.0.0:
arr-flatten "^1.0.1"

arr-flatten@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/arr-flatten/-/arr-flatten-1.0.1.tgz#e5ffe54d45e19f32f216e91eb99c8ce892bb604b"
version "1.0.2"
resolved "https://registry.yarnpkg.com/arr-flatten/-/arr-flatten-1.0.2.tgz#1ec1e63439c54f67d6f72bb4299c3d4f73b2d996"

array-back@^1.0.2, array-back@^1.0.3, array-back@^1.0.4:
version "1.0.4"
Expand Down Expand Up @@ -1471,9 +1471,9 @@ home-path@^1.0.3:
version "1.0.5"
resolved "https://registry.yarnpkg.com/home-path/-/home-path-1.0.5.tgz#788b29815b12d53bacf575648476e6f9041d133f"

hosted-git-info@^2.1.4, hosted-git-info@^2.4.1:
version "2.4.1"
resolved "https://registry.yarnpkg.com/hosted-git-info/-/hosted-git-info-2.4.1.tgz#4b0445e41c004a8bd1337773a4ff790ca40318c8"
hosted-git-info@^2.1.4, hosted-git-info@^2.4.2:
version "2.4.2"
resolved "https://registry.yarnpkg.com/hosted-git-info/-/hosted-git-info-2.4.2.tgz#0076b9f46a270506ddbaaea56496897460612a67"

html-encoding-sniffer@^1.0.1:
version "1.0.1"
Expand Down Expand Up @@ -2938,8 +2938,8 @@ sprintf-js@~1.0.2:
resolved "https://registry.yarnpkg.com/sprintf-js/-/sprintf-js-1.0.3.tgz#04e6926f662895354f3dd015203633b857297e2c"

sshpk@^1.7.0:
version "1.11.0"
resolved "https://registry.yarnpkg.com/sshpk/-/sshpk-1.11.0.tgz#2d8d5ebb4a6fab28ffba37fa62a90f4a3ea59d77"
version "1.13.0"
resolved "https://registry.yarnpkg.com/sshpk/-/sshpk-1.13.0.tgz#ff2a3e4fd04497555fed97b39a0fd82fafb3a33c"
dependencies:
asn1 "~0.2.3"
assert-plus "^1.0.0"
Expand Down Expand Up @@ -3234,7 +3234,7 @@ type-check@~0.3.2:
dependencies:
prelude-ls "~1.1.2"

typescript@^2.2.2:
typescript@^2.3.0:
version "2.3.0"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.3.0.tgz#2e63e09284392bc8158a2444c33e2093795c0418"

Expand Down Expand Up @@ -3558,9 +3558,9 @@ yargs@^6.0.0, yargs@^6.3.0:
y18n "^3.2.1"
yargs-parser "^4.2.0"

yargs@^7.0.2:
version "7.0.2"
resolved "https://registry.yarnpkg.com/yargs/-/yargs-7.0.2.tgz#115b97df1321823e8b8648e8968c782521221f67"
yargs@^7.0.2, yargs@^7.1.0:
version "7.1.0"
resolved "https://registry.yarnpkg.com/yargs/-/yargs-7.1.0.tgz#6ba318eb16961727f5d284f8ea003e8d6154d0c8"
dependencies:
camelcase "^3.0.0"
cliui "^3.2.0"
Expand Down

0 comments on commit 39af98a

Please sign in to comment.