Skip to content

Commit

Permalink
feat(deployment): set electron-updater releaseNotes at build time
Browse files Browse the repository at this point in the history
Close #1511
  • Loading branch information
develar committed Jun 21, 2017
1 parent 3c96e88 commit f6a2fc8
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 6 deletions.
28 changes: 28 additions & 0 deletions packages/electron-builder/src/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,11 @@ export interface Config extends PlatformSpecificBuildOptions {
*/
readonly publish?: Publish

/**
* The release info. Intended for command line usage (`-c.releaseInfo.releaseNotes="new features"`) or programmatically.
*/
readonly releaseInfo?: ReleaseInfo

/**
* The build version. Maps to the `CFBundleVersion` on macOS, and `FileVersion` metadata property on Windows. Defaults to the `version`.
* If `TRAVIS_BUILD_NUMBER` or `APPVEYOR_BUILD_NUMBER` or `CIRCLE_BUILD_NUM` or `BUILD_NUMBER` or `bamboo.buildNumber` env defined, it will be used as a build version (`version.build_number`).
Expand Down Expand Up @@ -447,4 +452,27 @@ export interface FilePattern {
* The [glob patterns](#file-patterns).
*/
filter?: Array<string> | string
}

export interface ReleaseInfo {
/**
* The release name.
*/
releaseName?: string | null

/**
* The release notes.
*/

releaseNotes?: string | null

/**
* The path to release notes file. Defaults to `release-notes.md` in the [build resources](#MetadataDirectories-buildResources).
*/
releaseNotesFile?: string | null

/**
* The release date.
*/
releaseDate?: string
}
19 changes: 15 additions & 4 deletions packages/electron-builder/src/publish/PublishManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ import { HttpPublisher, PublishContext, Publisher, PublishOptions } from "electr
import { BintrayPublisher } from "electron-publish/out/BintrayPublisher"
import { GitHubPublisher } from "electron-publish/out/gitHubPublisher"
import { MultiProgress } from "electron-publish/out/multiProgress"
import { ensureDir, outputJson, writeFile } from "fs-extra-p"
import { ensureDir, outputJson, readFile, 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 { WriteStream as TtyWriteStream } from "tty"
import * as url from "url"
import { Arch, Platform, Target } from "../core"
import { PlatformSpecificBuildOptions } from "../metadata"
import { PlatformSpecificBuildOptions, ReleaseInfo } from "../metadata"
import { Packager } from "../packager"
import { ArtifactCreated, BuildInfo } from "../packagerApi"
import { PlatformPackager } from "../platformPackager"
Expand Down Expand Up @@ -258,6 +258,17 @@ async function writeUpdateInfo(event: ArtifactCreated, _publishConfigs: Array<Pu
const sha512 = new Lazy<string>(() => hashFile(event.file!, "sha512", "base64"))
const isMac = packager.platform === Platform.MAC

const releaseInfo = Object.assign(<ReleaseInfo>{}, packager.config.releaseInfo)
if (releaseInfo.releaseNotes == null) {
const releaseNotesFile = await packager.getResource(releaseInfo.releaseNotesFile, "release-notes.md")
const releaseNotes = releaseNotesFile == null ? null : await readFile(releaseNotesFile, "utf-8")
// to avoid undefined in the file, check for null
if (releaseNotes != null) {
releaseInfo.releaseNotes = releaseNotes
}
}
delete releaseInfo.releaseNotesFile

for (const publishConfig of publishConfigs) {
if (publishConfig.provider === "bintray") {
continue
Expand Down Expand Up @@ -288,13 +299,13 @@ async function writeUpdateInfo(event: ArtifactCreated, _publishConfigs: Array<Pu
const updateInfoFile = path.join(outDir, `${channel}${isMac ? "-mac" : ""}.yml`)
if (!createdFiles.has(updateInfoFile)) {
createdFiles.add(updateInfoFile)
const info: UpdateInfo = {
const info = Object.assign(<UpdateInfo>{
version: version,
releaseDate: new Date().toISOString(),
githubArtifactName: event.safeArtifactName,
path: path.basename(event.file!),
sha512: await sha512.value,
}
}, releaseInfo)

if (packager.platform === Platform.WINDOWS) {
// backward compatibility
Expand Down
3 changes: 3 additions & 0 deletions test/out/windows/__snapshots__/installerTest.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ exports[`allowToChangeInstallationDirectory 3`] = `
Object {
"githubArtifactName": "test-custom-inst-dir-setup-1.1.0.exe",
"path": "Test Custom Installation Dir Setup 1.1.0.exe",
"releaseNotes": "New release with new bugs and
without features",
"version": "1.1.0",
}
`;
Expand Down
8 changes: 6 additions & 2 deletions test/src/windows/installerTest.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Arch, archFromString, Platform } from "electron-builder"
import { readFile } from "fs-extra-p"
import { readFile, writeFile } from "fs-extra-p"
import { safeLoad } from "js-yaml"
import * as path from "path"
import { app, assertPack, copyTestAsset } from "../helpers/packTester"
Expand Down Expand Up @@ -88,6 +88,7 @@ test.ifNotCiMac("boring, only perMachine", app({
}
}))

// test release notes also
test.ifAll.ifNotCiMac("allowToChangeInstallationDirectory", app({
targets: nsisTarget,
config: {
Expand All @@ -100,8 +101,11 @@ test.ifAll.ifNotCiMac("allowToChangeInstallationDirectory", app({
allowToChangeInstallationDirectory: true,
oneClick: false,
}
}
},
}, {
projectDirCreated: async (projectDir) => {
await writeFile(path.join(projectDir, "build", "release-notes.md"), "New release with new bugs and\n\nwithout features")
},
packed: async(context) => {
await expectUpdateMetadata(context, archFromString(process.arch))
const updateInfo = safeLoad(await readFile(path.join(context.outDir, "latest.yml"), "utf-8"))
Expand Down

0 comments on commit f6a2fc8

Please sign in to comment.