97 lines
No EOL
4.5 KiB
JavaScript
97 lines
No EOL
4.5 KiB
JavaScript
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.SnapStorePublisher = void 0;
|
|
exports.resolveSnapCredentials = resolveSnapCredentials;
|
|
const builder_util_1 = require("builder-util");
|
|
const path = require("path");
|
|
const publisher_1 = require("./publisher");
|
|
class SnapStorePublisher extends publisher_1.Publisher {
|
|
constructor(context, options, credentials) {
|
|
super(context);
|
|
this.context = context;
|
|
this.options = options;
|
|
this.credentials = credentials;
|
|
this.providerName = "snapStore";
|
|
}
|
|
async upload(task) {
|
|
var _a;
|
|
this.createProgressBar(path.basename(task.file), -1);
|
|
await checkSnapcraft();
|
|
// Credentials are injected via SNAPCRAFT_STORE_CREDENTIALS so that the
|
|
// snapcraft subprocess authenticates without an interactive login session.
|
|
// Generate credentials with: snapcraft export-login -
|
|
// https://documentation.ubuntu.com/snapcraft/stable/how-to/publishing/authenticate/
|
|
const credEnv = await resolveSnapCredentials(this.credentials.cscLink, this.credentials.resourcesDir);
|
|
// Channel format: [<track>/]<risk>[/<branch>] e.g. "stable", "edge", "lts/stable"
|
|
// Multiple channels are comma-separated: "beta,edge"
|
|
let channels = (_a = this.options.channels) !== null && _a !== void 0 ? _a : ["edge"];
|
|
if (typeof channels === "string") {
|
|
channels = channels.split(",");
|
|
}
|
|
// `snapcraft upload <snap-file> --release <channels>` uploads the snap and
|
|
// immediately releases it to the specified channels upon store review.
|
|
// https://documentation.ubuntu.com/snapcraft/stable/reference/commands/upload/
|
|
const args = ["upload", task.file];
|
|
if (channels.length > 0) {
|
|
args.push("--release", channels.join(","));
|
|
}
|
|
return (0, builder_util_1.spawn)("snapcraft", args, {
|
|
stdio: ["ignore", "inherit", "inherit"],
|
|
env: { ...process.env, ...credEnv },
|
|
});
|
|
}
|
|
toString() {
|
|
return "Snap Store";
|
|
}
|
|
}
|
|
exports.SnapStorePublisher = SnapStorePublisher;
|
|
// Resolves Snap Store credentials from cscLink / SNAP_CSC_LINK and returns
|
|
// them as { SNAPCRAFT_STORE_CREDENTIALS } so they can be injected into the
|
|
// snapcraft subprocess environment. The value is the raw export-login output
|
|
// (base64-encoded or a file path handled by loadCscLink).
|
|
// https://documentation.ubuntu.com/snapcraft/stable/how-to/publishing/authenticate/
|
|
async function resolveSnapCredentials(cscLink, resourcesDir) {
|
|
var _a;
|
|
const link = (_a = (cscLink !== null && cscLink !== void 0 ? cscLink : process.env.SNAP_CSC_LINK)) === null || _a === void 0 ? void 0 : _a.trim();
|
|
if (!link) {
|
|
return {};
|
|
}
|
|
const credentials = await (0, builder_util_1.loadCscLink)(link, resourcesDir);
|
|
const trimmed = credentials.trim();
|
|
if (!trimmed) {
|
|
throw new Error("Resolved snap store credentials are empty");
|
|
}
|
|
return { SNAPCRAFT_STORE_CREDENTIALS: trimmed };
|
|
}
|
|
// Snapcraft 7 introduced SNAPCRAFT_STORE_CREDENTIALS as the standard
|
|
// non-interactive credential mechanism. Earlier versions used a different
|
|
// auth format that is no longer compatible with this publisher.
|
|
// https://documentation.ubuntu.com/snapcraft/stable/how-to/publishing/authenticate/
|
|
const REQUIRED_SNAPCRAFT_MAJOR = 7;
|
|
async function checkSnapcraft() {
|
|
const installMessage = process.platform === "darwin" ? "brew install snapcraft" : "sudo snap install snapcraft --classic";
|
|
let versionOutput;
|
|
try {
|
|
versionOutput = await (0, builder_util_1.exec)("snapcraft", ["--version"]);
|
|
}
|
|
catch {
|
|
throw new Error(`snapcraft is not installed, please: ${installMessage}`);
|
|
}
|
|
const trimmed = versionOutput.trim();
|
|
// Edge-channel installs report "snapcraft, version edge" with no semver — skip the check.
|
|
if (trimmed === "snapcraft, version edge") {
|
|
return;
|
|
}
|
|
// Handles both output formats:
|
|
// "snapcraft, version X.Y.Z" (snapcraft ≤ 6)
|
|
// "snapcraft X.Y.Z" (snapcraft 7+)
|
|
let s = trimmed.replace(/^snapcraft/, "").trim();
|
|
s = s.replace(/^,/, "").trim();
|
|
s = s.replace(/^version/, "").trim();
|
|
s = s.replace(/^'|'$/g, "");
|
|
const major = parseInt(s.split(".")[0], 10);
|
|
if (!Number.isFinite(major) || major < REQUIRED_SNAPCRAFT_MAJOR) {
|
|
throw new Error(`at least snapcraft ${REQUIRED_SNAPCRAFT_MAJOR}.0.0 is required, but ${trimmed} installed, please: ${installMessage}`);
|
|
}
|
|
}
|
|
//# sourceMappingURL=snapStorePublisher.js.map
|