Skip to content

Commit

Permalink
fix: to preserve compatibility with old electron-auto-updater (< 0.10…
Browse files Browse the repository at this point in the history
….0), we upload file with path specific for GitHub
  • Loading branch information
develar committed Jan 6, 2017
1 parent 06b0103 commit c06f3f4
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 16 deletions.
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ cache:
- '%USERPROFILE%\.electron'

environment:
TEST_FILES: BuildTest,extraMetadataTest,filesTest,globTest,nsisUpdaterTest
TEST_FILES: BuildTest,extraMetadataTest,filesTest,globTest,nsisUpdaterTest,nsisTest

install:
- ps: Install-Product node 6 x64
Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@
"test-deps-mac": "brew install rpm dpkg mono lzip gnu-tar graphicsmagick xz && brew install wine --without-x11",
"postinstall": "lerna bootstrap",
"update-deps": "lerna exec -- npm-check-updates --reject 'electron-builder-http,electron-builder-util' -a",
"lerna-publish": "node test/out/helpers/setVersions.js p && lerna publish --skip-npm --skip-git && node test/out/helpers/setVersions.js && conventional-changelog -p angular -i CHANGELOG.md -s",
"npm-publish": "./packages/npm-publish.sh"
"lerna-publish": "node test/out/helpers/setVersions.js p && lerna publish --skip-npm --skip-git && node test/out/helpers/setVersions.js",
"npm-publish": "yarn compile && ./packages/npm-publish.sh && conventional-changelog -p angular -i CHANGELOG.md -s"
},
"//": "repository must be specified otherwise conventional-changelog will use forked repo (currently cloned)",
"repository": "electron-userland/electron-builder",
"devDependencies": {
"@types/electron": "^1.4.30",
"@types/ini": "^1.3.29",
Expand Down
7 changes: 6 additions & 1 deletion packages/electron-builder/src/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,12 @@ function publishManager(packager: Packager, publishTasks: Array<BluebirdPromise<
if (it == null) {
return null
}
return publishTasks.push(<BluebirdPromise<any>>it.upload(event.file, event.artifactName))
if (event.file == null) {
return publishTasks.push(<BluebirdPromise<any>>it.uploadData(event.data!, event.artifactName!))
}
else {
return publishTasks.push(<BluebirdPromise<any>>it.upload(event.file!, event.artifactName))
}
})
}
}
Expand Down
3 changes: 2 additions & 1 deletion packages/electron-builder/src/platformPackager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,8 @@ export interface RepositoryInfo {
export interface ArtifactCreated {
readonly packager: PlatformPackager<any>

readonly file: string
readonly file?: string
readonly data?: Buffer

readonly artifactName?: string

Expand Down
8 changes: 7 additions & 1 deletion packages/electron-builder/src/targets/nsis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,14 @@ export default class NsisTarget extends Target {

const githubPublishConfig = publishConfigs.find(it => it.provider === "github")
if (githubPublishConfig != null) {
// to preserve compatibility with old electron-auto-updater (< 0.10.0), we upload file with path specific for GitHub
packager.info.eventEmitter.emit("artifactCreated", <ArtifactCreated>{
file: updateInfoFile,
data: new Buffer(safeDump(<UpdateInfo>{
version: version,
path: githubArtifactName,
sha2: sha2,
})),
artifactName: `${channel}.yml`,
packager: packager,
publishConfig: githubPublishConfig,
})
Expand Down
31 changes: 31 additions & 0 deletions test/out/windows/__snapshots__/nsisTest.js.snap
Original file line number Diff line number Diff line change
@@ -1,7 +1,38 @@
exports[`test allowToChangeInstallationDirectory 1`] = `
Object {
"owner": "foo",
"provider": "github",
"repo": "bar",
}
`;

exports[`test allowToChangeInstallationDirectory 2`] = `
Object {
"githubArtifactName": "test-custom-inst-dir-Setup-1.1.0.exe",
"path": "Test Custom Installation Dir Setup 1.1.0.exe",
"version": "1.1.0",
}
`;

exports[`test one-click 1`] = `
Object {
"owner": "actperepo",
"package": "TestApp",
"provider": "bintray",
}
`;

exports[`test perMachine, no run after finish 1`] = `
Object {
"provider": "generic",
"url": "https://develar.s3.amazonaws.com/test",
}
`;

exports[`test perMachine, no run after finish 2`] = `
Object {
"githubArtifactName": "TestApp-Setup-1.1.0.exe",
"path": "TestApp Setup 1.1.0.exe",
"version": "1.1.0",
}
`;
4 changes: 4 additions & 0 deletions test/src/helpers/packTester.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ async function packAndCheck(outDir: string, packagerOptions: PackagerOptions, ch

const artifacts: Map<Platform, Array<ArtifactCreated>> = new Map()
packager.artifactCreated(event => {
if (event.file == null) {
return
}

assertThat(event.file).isAbsolute()
let list = artifacts.get(event.packager.platform)
if (list == null) {
Expand Down
27 changes: 17 additions & 10 deletions test/src/windows/nsisTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { extractFile } from "asar-electron-builder"
import { walk } from "electron-builder-util/out/fs"
import { WineManager, diff } from "../helpers/wine"
import { safeLoad } from "js-yaml"
import { archFromString } from "electron-builder-core"

const nsisTarget = Platform.WINDOWS.createTarget(["nsis"])

Expand Down Expand Up @@ -60,16 +61,11 @@ test.ifDevOrLinuxCi("perMachine, no run after finish", app({
)])
},
packed: async(context) => {
expect(safeLoad(await readFile(path.join(context.getResources(Platform.WINDOWS, Arch.ia32), "app-update.yml"), "utf-8"))).toMatchObject({
provider: "generic",
url: "https://develar.s3.amazonaws.com/test",
})
expect(safeLoad(await readFile(path.join(context.getResources(Platform.WINDOWS, Arch.ia32), "app-update.yml"), "utf-8"))).toMatchSnapshot()
const updateInfo = safeLoad(await readFile(path.join(context.outDir, "latest.yml"), "utf-8"))
expect(updateInfo).toMatchObject({
version: "1.1.0",
path: "TestApp Setup 1.1.0.exe",
})
expect(updateInfo.sha2).not.toEqual("")
delete updateInfo.sha2
expect(updateInfo).toMatchSnapshot()
await doTest(context.outDir, false)
},
}))
Expand Down Expand Up @@ -169,18 +165,29 @@ test.ifDevOrLinuxCi("custom script", app({targets: nsisTarget}, {
packed: context => assertThat(path.join(context.projectDir, "build", "customInstallerScript")).isFile(),
}))

test.ifDevOrLinuxCi("allowToChangeInstallationDirectory", app({
// todo why failed on CI?
test.ifNotCi("allowToChangeInstallationDirectory", app({
targets: nsisTarget,
appMetadata: {
name: "test-custom-inst-dir",
productName: "Test Custom Installation Dir"
productName: "Test Custom Installation Dir",
repository: "foo/bar",
},
config: {
nsis: {
allowToChangeInstallationDirectory: true,
oneClick: false,
}
}
}, {
packed: async(context) => {
expect(safeLoad(await readFile(path.join(context.getResources(Platform.WINDOWS, archFromString(process.arch)), "app-update.yml"), "utf-8"))).toMatchSnapshot()
const updateInfo = safeLoad(await readFile(path.join(context.outDir, "latest.yml"), "utf-8"))
expect(updateInfo.sha2).not.toEqual("")
delete updateInfo.sha2
expect(updateInfo).toMatchSnapshot()
await doTest(context.outDir, false)
}
}))

test("menuCategory", app({
Expand Down

0 comments on commit c06f3f4

Please sign in to comment.