Skip to content

Commit

Permalink
fix(deployment): different channels for different publish providers
Browse files Browse the repository at this point in the history
  • Loading branch information
develar committed May 31, 2017
1 parent 81c95f1 commit 81fd398
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 36 deletions.
36 changes: 22 additions & 14 deletions packages/electron-builder/src/publish/PublishManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export class PublishManager implements PublishContext {
log(`Tag ${tag} is defined, so artifacts will be published`)
publishOptions.publish = "onTag"
}
else if (isCi && !isEmptyOrSpaces(process.env.GH_TOKEN)) {
else if (isCi) {
log("CI detected, so artifacts will be published if draft release exists")
publishOptions.publish = "onTagOrDraft"
}
Expand Down Expand Up @@ -111,6 +111,10 @@ export class PublishManager implements PublishContext {
const target = event.target
const publishConfigs = event.publishConfig == null ? await getPublishConfigs(packager, target == null ? null : target.options, event.arch) : [event.publishConfig]

if (debug.enabled) {
debug(`artifactCreated: ${safeStringifyJson(event)}, publishConfigs: ${safeStringifyJson(publishConfigs)}`)
}

const eventFile = event.file
if (publishConfigs == null) {
if (this.isPublish) {
Expand Down Expand Up @@ -203,13 +207,15 @@ export async function getPublishConfigsForUpdateInfo(packager: PlatformPackager<
}

if (publishConfigs.length === 0) {
debug("No publishConfigs, detect using repository info")
debug("getPublishConfigsForUpdateInfo: no publishConfigs, detect using repository info")
// https://github.com/electron-userland/electron-builder/issues/925#issuecomment-261732378
// default publish config is github, file should be generated regardless of publish state (user can test installer locally or manage the release process manually)
const repositoryInfo = await packager.info.repositoryInfo
debug(`getPublishConfigsForUpdateInfo: ${safeStringifyJson(repositoryInfo)}`)
if (repositoryInfo != null && repositoryInfo.type === "github") {
const resolvedPublishConfig = await getResolvedPublishConfig(packager, {provider: repositoryInfo.type}, arch, false)
if (resolvedPublishConfig != null) {
debug(`getPublishConfigsForUpdateInfo: resolve to publish config ${safeStringifyJson(resolvedPublishConfig)}`)
return [resolvedPublishConfig]
}
}
Expand All @@ -231,13 +237,15 @@ async function writeUpdateInfo(event: ArtifactCreated, _publishConfigs: Array<Pu
await ensureDir(outDir)
}

const version = packager.appInfo.version

for (const publishConfig of publishConfigs) {
if (publishConfig.provider === "bintray") {
continue
}

const version = packager.appInfo.version
const channel = (<GenericServerOptions>publishConfig).channel || "latest"
const createdFiles = new Set<string>()

if (packager.platform === Platform.MAC) {
const isGitHub = publishConfig.provider === "github"
Expand All @@ -256,29 +264,29 @@ async function writeUpdateInfo(event: ArtifactCreated, _publishConfigs: Array<Pu
target: null,
publishConfig: publishConfig,
})

continue
}

const sha2 = await sha256(event.file!)
const updateInfoFile = path.join(outDir, `${channel}${packager.platform === Platform.MAC ? "-mac" : ""}.yml`)
await writeFile(updateInfoFile, safeDump(<UpdateInfo>{
version: version,
releaseDate: new Date().toISOString(),
githubArtifactName: event.safeArtifactName,
path: path.basename(event.file!),
sha2: sha2,
}))
if (!createdFiles.has(updateInfoFile)) {
createdFiles.add(updateInfoFile)
await writeFile(updateInfoFile, safeDump(<UpdateInfo>{
version: version,
releaseDate: new Date().toISOString(),
githubArtifactName: event.safeArtifactName,
path: path.basename(event.file!),
sha2: sha2,
}))
}

// artifact should be uploaded only to designated publish provider
packager.info.dispatchArtifactCreated({
file: updateInfoFile,
arch: null,
packager: packager,
target: null,
publishConfig: publishConfig,
})

break
}
}

Expand Down
90 changes: 68 additions & 22 deletions typings/electron.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Type definitions for Electron 1.7.1
// Type definitions for Electron 1.7.2
// Project: http://electron.atom.io/
// Definitions by: The Electron Team <https://github.com/electron/electron>
// Definitions: https://github.com/electron/electron-typescript-definitions
Expand Down Expand Up @@ -482,23 +482,29 @@ declare namespace Electron {
*/
focus(): void;
/**
* Returns ProcessMemoryInfo[]: Array of ProcessMemoryInfo objects that correspond
* to memory usage statistics of all the processes associated with the app.
* Returns ProcessMetric[]: Array of ProcessMetric objects that correspond to
* memory and cpu usage statistics of all the processes associated with the app.
* Note: This method is deprecated, use app.getAppMetrics() instead.
*/
getAppMemoryInfo(): void;
/**
* Returns ProcessMetric[]: Array of ProcessMetric objects that correspond to
* memory and cpu usage statistics of all the processes associated with the app.
*/
getAppMetrics(): void;
getAppPath(): string;
getBadgeCount(): number;
getCurrentActivityType(): string;
/**
* Fetches a path's associated icon. On Windows, there a 2 kinds of icons: On Linux
* and macOS, icons depend on the application associated with file mime type.
*/
getFileIcon(path: string, options: FileIconOptions, callback: (error: Error, icon: NativeImage) => void): void;
getFileIcon(path: string, callback: (error: Error, icon: NativeImage) => void): void;
/**
* Fetches a path's associated icon. On Windows, there a 2 kinds of icons: On Linux
* and macOS, icons depend on the application associated with file mime type.
*/
getFileIcon(path: string, callback: (error: Error, icon: NativeImage) => void): void;
getFileIcon(path: string, options: FileIconOptions, callback: (error: Error, icon: NativeImage) => void): void;
getJumpListSettings(): JumpListSettings;
/**
* Note: When distributing your packaged app, you have to also ship the locales
Expand Down Expand Up @@ -1735,6 +1741,10 @@ declare namespace Electron {
* to write both a bookmark and fallback text to the clipboard.
*/
writeBookmark(title: string, url: string, type?: string): void;
/**
* Writes the buffer into the clipboard as format.
*/
writeBuffer(format: string, buffer: Buffer, type?: string): void;
/**
* Writes the text into the find pasteboard as plain text. This method uses
* synchronous IPC when called from the renderer process.
Expand Down Expand Up @@ -2505,9 +2515,9 @@ declare namespace Electron {
*/
once(channel: string, listener: Function): this;
/**
* Removes all listeners, or those of the specified channel.
* Removes listeners of the specified channel.
*/
removeAllListeners(channel?: string): this;
removeAllListeners(channel: string): this;
/**
* Removes the specified listener from the listener array for the specified
* channel.
Expand Down Expand Up @@ -2876,18 +2886,36 @@ declare namespace Electron {
stop(id: number): void;
}

interface ProcessMemoryInfo {
interface PrinterInfo {

// Docs: http://electron.atom.io/docs/api/structures/printer-info

description: string;
isDefault: boolean;
name: string;
status: number;
}

// Docs: http://electron.atom.io/docs/api/structures/process-memory-info
interface ProcessMetric {

// Docs: http://electron.atom.io/docs/api/structures/process-metric

/**
* CPU usage of the process.
*/
cpu: CPUUsage;
/**
* Memory information of the process.
* Memory information for the process.
*/
memory: MemoryInfo;
/**
* Process id of the process.
*/
pid: number;
/**
* Process type (Browser or Tab or GPU etc).
*/
type: string;
}

interface Protocol extends EventEmitter {
Expand Down Expand Up @@ -3417,10 +3445,9 @@ declare namespace Electron {
getAccentColor(): string;
getColor(color: '3d-dark-shadow' | '3d-face' | '3d-highlight' | '3d-light' | '3d-shadow' | 'active-border' | 'active-caption' | 'active-caption-gradient' | 'app-workspace' | 'button-text' | 'caption-text' | 'desktop' | 'disabled-text' | 'highlight' | 'highlight-text' | 'hotlight' | 'inactive-border' | 'inactive-caption' | 'inactive-caption-gradient' | 'inactive-caption-text' | 'info-background' | 'info-text' | 'menu' | 'menu-highlight' | 'menubar' | 'menu-text' | 'scrollbar' | 'window' | 'window-frame' | 'window-text'): string;
/**
* Get the value of key in system preferences. This API uses NSUserDefaults on
* macOS. Some popular key and types are:
* This API uses NSUserDefaults on macOS. Some popular key and types are:
*/
getUserDefault(key: string, type: 'string' | 'boolean' | 'integer' | 'float' | 'double' | 'url' | 'array' | 'dictionary'): void;
getUserDefault(key: string, type: 'string' | 'boolean' | 'integer' | 'float' | 'double' | 'url' | 'array' | 'dictionary'): any;
/**
* This method returns true if DWM composition (Aero Glass) is enabled, and false
* otherwise. An example of using it to determine if you should create a
Expand Down Expand Up @@ -4564,7 +4591,8 @@ declare namespace Electron {
* Calling event.preventDefault() will destroy the guest page. This event can be
* used to configure webPreferences for the webContents of a <webview> before it's
* loaded, and provides the ability to set settings that can't be set via <webview>
* attributes.
* attributes. Note: The specified preload script option will be appear as
* preloadURL (not preload) in the webPreferences object emitted with this event.
*/
on(event: 'will-attach-webview', listener: (event: Event,
/**
Expand Down Expand Up @@ -4675,13 +4703,13 @@ declare namespace Electron {
* called with callback(image). The image is an instance of NativeImage that stores
* data of the snapshot. Omitting rect will capture the whole visible page.
*/
capturePage(rect: Rectangle, callback: (image: NativeImage) => void): void;
capturePage(callback: (image: NativeImage) => void): void;
/**
* Captures a snapshot of the page within rect. Upon completion callback will be
* called with callback(image). The image is an instance of NativeImage that stores
* data of the snapshot. Omitting rect will capture the whole visible page.
*/
capturePage(callback: (image: NativeImage) => void): void;
capturePage(rect: Rectangle, callback: (image: NativeImage) => void): void;
/**
* Clears the navigation history.
*/
Expand Down Expand Up @@ -4740,6 +4768,10 @@ declare namespace Electron {
findInPage(text: string, options?: FindInPageOptions): void;
getFrameRate(): number;
getOSProcessId(): number;
/**
* Get the system printer list. Returns PrinterInfo[]
*/
getPrinters(): void;
getTitle(): string;
getURL(): string;
getUserAgent(): string;
Expand Down Expand Up @@ -4827,11 +4859,11 @@ declare namespace Electron {
*/
pasteAndMatchStyle(): void;
/**
* Prints window's web page. When silent is set to true, Electron will pick up
* system's default printer and default settings for printing. Calling
* window.print() in web page is equivalent to calling webContents.print({silent:
* false, printBackground: false}). Use page-break-before: always; CSS style to
* force to print to a new page.
* Prints window's web page. When silent is set to true, Electron will pick the
* system's default printer if deviceName is empty and the default settings for
* printing. Calling window.print() in web page is equivalent to calling
* webContents.print({silent: false, printBackground: false, deviceName: ''}). Use
* page-break-before: always; CSS style to force to print to a new page.
*/
print(options?: PrintOptions): void;
/**
Expand Down Expand Up @@ -5569,7 +5601,8 @@ declare namespace Electron {
* will be loaded by require in guest page under the hood. When the guest page
* doesn't have node integration this script will still have access to all Node
* APIs, but global objects injected by Node will be deleted after this script has
* finished executing.
* finished executing. Note: This option will be appear as preloadURL (not preload)
* in the webPreferences specified to the will-attach-webview event.
*/
preload?: string;
/**
Expand Down Expand Up @@ -6910,6 +6943,10 @@ declare namespace Electron {
* Also prints the background color and image of the web page. Default is false.
*/
printBackground: boolean;
/**
* Set the printer device name to use. Default is ''.
*/
deviceName?: string;
}

interface PrintToPDFOptions {
Expand Down Expand Up @@ -7662,6 +7699,15 @@ declare namespace Electron {
* Whether to use native window.open(). Defaults to false.
*/
nativeWindowOpen?: boolean;
/**
* Whether to enable the . Defaults to the value of the nodeIntegration option. The
* preload script configured for the <webview> will have node integration enabled
* when it is executed so you should ensure remote/untrusted content is not able to
* create a <webview> tag with a possibly malicious preload script. You can use the
* will-attach-webview event on to strip away the preload script and to validate or
* alter the <webview>'s initial settings.
*/
webviewTag?: boolean;
}

interface DefaultFontFamily {
Expand Down

0 comments on commit 81fd398

Please sign in to comment.