From f6a2fc8e32ae5dbe15ca35702177fb83105efee0 Mon Sep 17 00:00:00 2001 From: develar Date: Wed, 21 Jun 2017 19:30:46 +0200 Subject: [PATCH] feat(deployment): set electron-updater releaseNotes at build time Close #1511 --- packages/electron-builder/src/metadata.ts | 28 +++++++++++++++++++ .../src/publish/PublishManager.ts | 19 ++++++++++--- .../__snapshots__/installerTest.js.snap | 3 ++ test/src/windows/installerTest.ts | 8 ++++-- 4 files changed, 52 insertions(+), 6 deletions(-) diff --git a/packages/electron-builder/src/metadata.ts b/packages/electron-builder/src/metadata.ts index 36741359d0e..6f00b005afd 100644 --- a/packages/electron-builder/src/metadata.ts +++ b/packages/electron-builder/src/metadata.ts @@ -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`). @@ -447,4 +452,27 @@ export interface FilePattern { * The [glob patterns](#file-patterns). */ filter?: Array | 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 } \ No newline at end of file diff --git a/packages/electron-builder/src/publish/PublishManager.ts b/packages/electron-builder/src/publish/PublishManager.ts index 718e0ca2802..07e401aabdb 100644 --- a/packages/electron-builder/src/publish/PublishManager.ts +++ b/packages/electron-builder/src/publish/PublishManager.ts @@ -10,7 +10,7 @@ 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" @@ -18,7 +18,7 @@ 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" @@ -258,6 +258,17 @@ async function writeUpdateInfo(event: ArtifactCreated, _publishConfigs: Array(() => hashFile(event.file!, "sha512", "base64")) const isMac = packager.platform === Platform.MAC + const releaseInfo = Object.assign({}, 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 @@ -288,13 +299,13 @@ async function writeUpdateInfo(event: ArtifactCreated, _publishConfigs: Array{ 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 diff --git a/test/out/windows/__snapshots__/installerTest.js.snap b/test/out/windows/__snapshots__/installerTest.js.snap index f1565ad921f..9649cf10a8d 100644 --- a/test/out/windows/__snapshots__/installerTest.js.snap +++ b/test/out/windows/__snapshots__/installerTest.js.snap @@ -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", } `; diff --git a/test/src/windows/installerTest.ts b/test/src/windows/installerTest.ts index e79e3b3e5f5..60973de25fb 100644 --- a/test/src/windows/installerTest.ts +++ b/test/src/windows/installerTest.ts @@ -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" @@ -88,6 +88,7 @@ test.ifNotCiMac("boring, only perMachine", app({ } })) +// test release notes also test.ifAll.ifNotCiMac("allowToChangeInstallationDirectory", app({ targets: nsisTarget, config: { @@ -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"))