Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: pass publish options to snap publisher #7908

Merged
merged 4 commits into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .changeset/swift-dingos-live.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
"app-builder-lib": patch
"dmg-builder": patch
"electron-builder": patch
"electron-builder-squirrel-windows": patch
"electron-forge-maker-appimage": patch
"electron-forge-maker-nsis": patch
"electron-forge-maker-nsis-web": patch
"electron-forge-maker-snap": patch
---

fix: pass publish options to snap publisher
58 changes: 55 additions & 3 deletions packages/app-builder-lib/src/targets/snap.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import { Arch, deepAssign, executeAppBuilder, InvalidConfigurationError, log, replaceDefault as _replaceDefault, serializeToYaml, toLinuxArchString } from "builder-util"
import { asArray } from "builder-util-runtime"
import { SnapStoreOptions, asArray } from "builder-util-runtime"
import { outputFile, readFile } from "fs-extra"
import { load } from "js-yaml"
import * as path from "path"
import * as semver from "semver"
import { Target } from "../core"
import { Publish, Target } from "../core"
import { LinuxPackager } from "../linuxPackager"
import { PlugDescriptor, SnapOptions } from "../options/SnapOptions"
import { getTemplatePath } from "../util/pathManager"
import { LinuxTargetHelper } from "./LinuxTargetHelper"
import { createStageDirPath } from "./targetUtil"
import { Configuration } from "../configuration"

const defaultPlugs = ["desktop", "desktop-legacy", "home", "x11", "wayland", "unity7", "browser-support", "network", "gsettings", "audio-playback", "pulseaudio", "opengl"]

Expand Down Expand Up @@ -245,13 +246,15 @@ export default class SnapTarget extends Target {

await executeAppBuilder(args)

const publishConfig = findSnapPublishConfig(this.packager.config)

await packager.info.callArtifactBuildCompleted({
file: artifactPath,
safeArtifactName: packager.computeSafeArtifactName(artifactName, "snap", arch, false),
target: this,
arch,
packager,
publishConfig: options.publish == null ? { provider: "snapStore" } : null,
publishConfig: publishConfig == null ? { provider: "snapStore" } : publishConfig,
})
}

Expand All @@ -260,6 +263,55 @@ export default class SnapTarget extends Target {
}
}

function findSnapPublishConfig(config?: Configuration): SnapStoreOptions | null {
if (!config) {
return null
}

if (config.linux?.publish) {
const configCandidate = findSnapPublishConfigInPublishNode(config.linux.publish)

if (configCandidate) {
return configCandidate
}
}

if (config.publish) {
const configCandidate = findSnapPublishConfigInPublishNode(config.publish)

if (configCandidate) {
return configCandidate
}
}

return null
}

function findSnapPublishConfigInPublishNode(configPublishNode: Publish): SnapStoreOptions | null {
if (!configPublishNode) {
return null
}

if (Array.isArray(configPublishNode)) {
for (const configObj of configPublishNode) {
if (isSnapStoreOptions(configObj)) {
return configObj
}
}
}

if (typeof configPublishNode === `object` && isSnapStoreOptions(configPublishNode)) {
return configPublishNode
}

return null
}

function isSnapStoreOptions(configPublishNode: Publish): configPublishNode is SnapStoreOptions {
const snapStoreOptionsCandidate = configPublishNode as SnapStoreOptions
return snapStoreOptionsCandidate?.provider === `snapStore`
}

function archNameToTriplet(arch: Arch): string {
switch (arch) {
case Arch.x64:
Expand Down