@rightkit/release 0.6.40 → 0.6.42
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +110 -11
- package/admission-files.mjs +40 -0
- package/admission-host.mjs +2 -1
- package/app-check.mjs +303 -16
- package/app-closure.mjs +6 -4
- package/bin/rightkit-gate.mjs +177 -32
- package/cargo-contract.mjs +17 -31
- package/cargo-license-notices.mjs +129 -19
- package/cargo-target-shim.mjs +14 -0
- package/carried-cargo.mjs +2 -4
- package/cli/right-release.mjs +24 -2
- package/cross-targets.mjs +24 -0
- package/deterministic-scans.mjs +150 -58
- package/development-signing.mjs +25 -2
- package/development.mjs +34 -1
- package/direct-release-command.mjs +154 -0
- package/disk-policy.mjs +16 -0
- package/feature-coverage.mjs +134 -0
- package/gate-coverage.mjs +38 -0
- package/gate-stages.mjs +1 -0
- package/ghsa-audit.mjs +95 -0
- package/install-app.mjs +33 -5
- package/install-channels.mjs +301 -0
- package/interactive-session-run.mjs +105 -0
- package/legal-contract.mjs +10 -1
- package/legion-freeze-consumer.mjs +241 -0
- package/linux-publish.mjs +136 -0
- package/local-publish.mjs +31 -8
- package/nsis-pack.mjs +95 -0
- package/nsis-upgrade-template.mjs +93 -0
- package/outdated-command.mjs +19 -0
- package/ownership-class-rules.mjs +32 -10
- package/ownership-mandatory-set.json +23 -0
- package/ownership-mandatory-set.mjs +66 -8
- package/package-recipe-targets.mjs +54 -19
- package/package.json +1 -1
- package/payload-root-install.mjs +123 -0
- package/plugin-delivery.mjs +141 -0
- package/prebuild-gates.mjs +8 -4
- package/preflight.mjs +6 -1
- package/provision-model-bundle.mjs +172 -0
- package/pub-upload.mjs +1 -1
- package/publish-local-npm.mjs +34 -9
- package/publish-retention.mjs +106 -0
- package/publish-update.mjs +15 -8
- package/qa-build-features.mjs +24 -15
- package/qa-contract.mjs +5 -6
- package/qa-control-scan.mjs +14 -0
- package/qa-web-pairing.mjs +76 -0
- package/r2-s3-multipart.mjs +190 -0
- package/r2-verified-upload.mjs +28 -16
- package/recipe-build.mjs +53 -3
- package/release-checks.mjs +53 -2
- package/release-config.mjs +8 -3
- package/release-invocation.mjs +12 -2
- package/release-pin-floor.mjs +44 -0
- package/release-qa-audit.mjs +18 -2
- package/release-qa-command.mjs +17 -1
- package/release-qa-policy.mjs +30 -3
- package/release-switch-cfg.mjs +271 -0
- package/release-switch-registry.json +60 -1
- package/release-switch-scan.mjs +398 -23
- package/release.mjs +97 -6
- package/render-views.mjs +141 -0
- package/rightkit-registry-resolver.mjs +1 -1
- package/rightkit-versions.json +140 -103
- package/runtime-artifact-manifest.mjs +9 -0
- package/runtime-manifest-refresh.mjs +88 -0
- package/rustright-stage.mjs +197 -0
- package/scan-digest.mjs +15 -9
- package/scan-tool-enrolment.mjs +1 -1
- package/security-policy.mjs +196 -0
- package/shell-contract.mjs +32 -0
- package/snapshot-broker.mjs +8 -1
- package/snapshot-check.mjs +58 -0
- package/snapshot-request.mjs +25 -2
- package/stage-commands.mjs +33 -4
- package/stage-receipt.mjs +115 -0
- package/stage-sidecar.mjs +188 -17
- package/stage-xcframework.mjs +118 -0
- package/suite-api.generated.mjs +16 -1
- package/unit-gate.mjs +14 -2
- package/upload-large.mjs +4 -4
- package/upload-release.mjs +6 -0
- package/win-package-recipe.mjs +26 -4
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// One-command install channels, generated (rightkit#1191, docs/design/ADR-0004-one-command-install.md).
|
|
3
|
+
//
|
|
4
|
+
// `right-release install-channels --facts <facts.json> --out <dir> [--check]` renders, from the facts a release already verified and uploaded, every
|
|
5
|
+
// channel an app ships and writes them under `<dir>`:
|
|
6
|
+
// install.sh macOS and Linux curl -fsSL https://<host>/<app>/install.sh | sh (--uninstall removes)
|
|
7
|
+
// install.ps1 Windows irm https://<host>/<app>/install.ps1 | iex (-Uninstall removes)
|
|
8
|
+
// Casks/<app>.rb Homebrew brew install <tap>/<app>
|
|
9
|
+
// winget/<Publisher>.<App>.{yaml,installer.yaml,locale.en-US.yaml} a manifest set (submitted only on request, public apps only)
|
|
10
|
+
// install-channels.json the sha256 of every file above, so a publish step can read each back from the host and compare byte for byte (ADR I2)
|
|
11
|
+
// Nothing is hand-written per app, and nothing is uploaded here: this module only renders and writes files.
|
|
12
|
+
//
|
|
13
|
+
// Invariants (ADR-0004): every script pins the exact version, URL and sha256 of the immutable `versions/<ver>/` object (never `current/`) and refuses to
|
|
14
|
+
// run an installer before the sha256 matches (I1); macOS and Windows additionally check the platform signature and the expected signer (Team ID, Authenticode
|
|
15
|
+
// subject); the install lands at the same path and identity right-release's dev install uses (I4). Every fact is validated against a strict alphabet before
|
|
16
|
+
// it reaches a script, so no fact can break out of its quoted literal.
|
|
17
|
+
//
|
|
18
|
+
// Facts: { app, productName, version, publisher, publisherId?, description, homepage, license?, host (https origin the scripts live on), tap? (Homebrew tap, "owner/name"),
|
|
19
|
+
// mac?: { url, sha256, size, teamId, bundleId, appName, destination? ("/Applications") },
|
|
20
|
+
// windows?: { url, sha256, size, signerSubject, installDirectory ("%LOCALAPPDATA%\\Programs\\<Product>"), exe },
|
|
21
|
+
// linux?: { x86_64?: { url, sha256, size }, aarch64?: { url, sha256, size }, binary, glibc? } }
|
|
22
|
+
import { createHash } from "node:crypto";
|
|
23
|
+
import { mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
|
|
24
|
+
import path from "node:path";
|
|
25
|
+
import { pathToFileURL } from "node:url";
|
|
26
|
+
|
|
27
|
+
export class InstallChannelsError extends Error {
|
|
28
|
+
constructor(message) { super(message); this.name = "InstallChannelsError"; this.code = "RK_INSTALL_CHANNELS"; }
|
|
29
|
+
}
|
|
30
|
+
const fail = (message) => { throw new InstallChannelsError(message); };
|
|
31
|
+
const isObject = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
|
|
32
|
+
|
|
33
|
+
const SLUG = /^[a-z][a-z0-9-]{1,40}$/;
|
|
34
|
+
const TEXT = /^[A-Za-z0-9 .,:;'()&+\-_/]{1,200}$/;
|
|
35
|
+
const HTTPS = /^https:\/\/[A-Za-z0-9.-]+(?::\d+)?\/[A-Za-z0-9._~%/+\-]*$/;
|
|
36
|
+
const SHA256 = /^[0-9a-f]{64}$/;
|
|
37
|
+
const VERSION = /^\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.-]+)?$/;
|
|
38
|
+
const TEAM = /^[A-Z0-9]{10}$/;
|
|
39
|
+
const BUNDLE_ID = /^[A-Za-z0-9][A-Za-z0-9.-]{2,120}$/;
|
|
40
|
+
const APP_BUNDLE = /^[A-Za-z0-9][A-Za-z0-9 ._-]{0,60}\.app$/;
|
|
41
|
+
const EXE = /^[A-Za-z0-9][A-Za-z0-9 ._-]{0,60}\.exe$/;
|
|
42
|
+
const BINARY = /^[A-Za-z0-9][A-Za-z0-9._-]{0,60}$/;
|
|
43
|
+
const SUBJECT = /^CN=[A-Za-z0-9 .,&'-]{2,100}$/;
|
|
44
|
+
const WINDOWS_DIR = /^(?:%LOCALAPPDATA%|[A-Za-z]:)\\[A-Za-z0-9 ._\\-]{2,160}$/;
|
|
45
|
+
const MAC_DESTINATION = /^\/[A-Za-z0-9 ._/-]{1,100}$/;
|
|
46
|
+
const LINUX_ARCHES = ["x86_64", "aarch64"];
|
|
47
|
+
|
|
48
|
+
function checked(value, pattern, label) {
|
|
49
|
+
if (typeof value !== "string" || !pattern.test(value)) fail(`${label} is missing or has characters outside its allowed alphabet: ${JSON.stringify(value)}`);
|
|
50
|
+
return value;
|
|
51
|
+
}
|
|
52
|
+
function artifact(value, label) {
|
|
53
|
+
if (!isObject(value)) fail(`${label} must be { url, sha256, size }`);
|
|
54
|
+
checked(value.url, HTTPS, `${label}.url`);
|
|
55
|
+
if (/\/current\//.test(value.url)) fail(`${label}.url must be the immutable versions/<ver>/ object, never current/ (ADR-0004 I3)`);
|
|
56
|
+
checked(value.sha256, SHA256, `${label}.sha256`);
|
|
57
|
+
if (!Number.isSafeInteger(value.size) || value.size <= 0) fail(`${label}.size must be a positive integer`);
|
|
58
|
+
return value;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** Validate the facts and return them (frozen). Throws InstallChannelsError naming the first bad fact. */
|
|
62
|
+
export function validateChannelFacts(facts) {
|
|
63
|
+
if (!isObject(facts)) fail("facts must be an object");
|
|
64
|
+
checked(facts.app, SLUG, "app");
|
|
65
|
+
checked(facts.productName, /^[A-Za-z0-9][A-Za-z0-9 ._-]{0,60}$/, "productName");
|
|
66
|
+
checked(facts.version, VERSION, "version");
|
|
67
|
+
checked(facts.publisher, TEXT, "publisher");
|
|
68
|
+
if (facts.publisherId !== undefined) checked(facts.publisherId, /^[A-Za-z][A-Za-z0-9]{1,40}$/, "publisherId");
|
|
69
|
+
checked(facts.description, TEXT, "description");
|
|
70
|
+
checked(facts.homepage, HTTPS, "homepage");
|
|
71
|
+
checked(facts.host, /^https:\/\/[A-Za-z0-9.-]+$/, "host");
|
|
72
|
+
if (facts.license !== undefined) checked(facts.license, /^[A-Za-z0-9.+ -]{1,60}$/, "license");
|
|
73
|
+
if (facts.tap !== undefined) checked(facts.tap, /^[a-z0-9-]+\/[a-z0-9-]+$/, "tap");
|
|
74
|
+
if (!facts.mac && !facts.windows && !facts.linux) fail("facts declare no platform (mac, windows or linux)");
|
|
75
|
+
if (facts.mac) {
|
|
76
|
+
artifact(facts.mac, "mac");
|
|
77
|
+
if (!/\.dmg$/i.test(facts.mac.url)) fail("mac.url must be the signed .dmg");
|
|
78
|
+
checked(facts.mac.teamId, TEAM, "mac.teamId");
|
|
79
|
+
checked(facts.mac.bundleId, BUNDLE_ID, "mac.bundleId");
|
|
80
|
+
checked(facts.mac.appName, APP_BUNDLE, "mac.appName");
|
|
81
|
+
checked(facts.mac.destination ?? "/Applications", MAC_DESTINATION, "mac.destination");
|
|
82
|
+
}
|
|
83
|
+
if (facts.windows) {
|
|
84
|
+
artifact(facts.windows, "windows");
|
|
85
|
+
if (!/\.exe$/i.test(facts.windows.url)) fail("windows.url must be the signed .exe installer");
|
|
86
|
+
checked(facts.windows.signerSubject, SUBJECT, "windows.signerSubject");
|
|
87
|
+
checked(facts.windows.installDirectory, WINDOWS_DIR, "windows.installDirectory");
|
|
88
|
+
checked(facts.windows.exe, EXE, "windows.exe");
|
|
89
|
+
}
|
|
90
|
+
if (facts.linux) {
|
|
91
|
+
if (!isObject(facts.linux)) fail("linux must be an object");
|
|
92
|
+
const arches = LINUX_ARCHES.filter((arch) => facts.linux[arch] !== undefined);
|
|
93
|
+
if (!arches.length) fail("linux declares no architecture (x86_64, aarch64)");
|
|
94
|
+
for (const arch of arches) { artifact(facts.linux[arch], `linux.${arch}`); if (!/\.tar\.gz$/.test(facts.linux[arch].url)) fail(`linux.${arch}.url must be a .tar.gz`); }
|
|
95
|
+
checked(facts.linux.binary, BINARY, "linux.binary");
|
|
96
|
+
}
|
|
97
|
+
return Object.freeze(facts);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const header = (facts, what) => `Generated by right-release install-channels for ${facts.productName} ${facts.version}. Do not edit: ${what} is regenerated on every release.`;
|
|
101
|
+
|
|
102
|
+
export function renderInstallSh(facts) {
|
|
103
|
+
const { mac, linux } = facts;
|
|
104
|
+
const lines = [
|
|
105
|
+
"#!/bin/sh",
|
|
106
|
+
`# ${header(facts, "this script")}`,
|
|
107
|
+
"# Rerun the same command to upgrade. Uninstall: sh install.sh --uninstall",
|
|
108
|
+
"set -eu",
|
|
109
|
+
`APP='${facts.productName}'`,
|
|
110
|
+
`SLUG='${facts.app}'`,
|
|
111
|
+
`VERSION='${facts.version}'`,
|
|
112
|
+
'TMP="$(mktemp -d)"',
|
|
113
|
+
'trap \'rm -rf "$TMP"\' EXIT INT TERM',
|
|
114
|
+
'die() { printf "%s install: %s\\n" "$SLUG" "$1" >&2; exit 1; }',
|
|
115
|
+
'sha256_of() { if command -v shasum >/dev/null 2>&1; then shasum -a 256 "$1" | cut -d " " -f 1; else sha256sum "$1" | cut -d " " -f 1; fi; }',
|
|
116
|
+
'fetch() { curl -fsSL --proto "=https" --tlsv1.2 -o "$2" "$1" || die "download failed: $1"; }',
|
|
117
|
+
'verify_sha() { [ "$(sha256_of "$1")" = "$2" ] || die "sha256 mismatch for $1: refusing to install"; }',
|
|
118
|
+
'OS="$(uname -s)"; ARCH="$(uname -m)"',
|
|
119
|
+
'UNINSTALL=0; [ "${1:-}" = "--uninstall" ] && UNINSTALL=1',
|
|
120
|
+
'case "$OS" in',
|
|
121
|
+
];
|
|
122
|
+
if (mac) {
|
|
123
|
+
const dest = mac.destination ?? "/Applications";
|
|
124
|
+
lines.push(
|
|
125
|
+
" Darwin)",
|
|
126
|
+
` DEST='${dest}'; APPDIR='${mac.appName}'; TEAM='${mac.teamId}'; BUNDLE='${mac.bundleId}'`,
|
|
127
|
+
` URL='${mac.url}'; SHA='${mac.sha256}'`,
|
|
128
|
+
' if [ "$UNINSTALL" = 1 ]; then rm -rf "$DEST/$APPDIR"; printf "%s removed from %s\\n" "$APP" "$DEST"; exit 0; fi',
|
|
129
|
+
' fetch "$URL" "$TMP/app.dmg"; verify_sha "$TMP/app.dmg" "$SHA"',
|
|
130
|
+
' hdiutil attach -nobrowse -readonly -quiet -mountpoint "$TMP/mnt" "$TMP/app.dmg" || die "cannot mount the disk image"',
|
|
131
|
+
' trap \'hdiutil detach -quiet "$TMP/mnt" >/dev/null 2>&1 || true; rm -rf "$TMP"\' EXIT INT TERM',
|
|
132
|
+
' [ -d "$TMP/mnt/$APPDIR" ] || die "$APPDIR is not in the disk image"',
|
|
133
|
+
' STAGE="$DEST/.${APPDIR%.app}.rightkit-install.app"; rm -rf "$STAGE"',
|
|
134
|
+
' ditto "$TMP/mnt/$APPDIR" "$STAGE" || die "copy failed"',
|
|
135
|
+
' codesign --verify --deep --strict "$STAGE" || { rm -rf "$STAGE"; die "code signature invalid"; }',
|
|
136
|
+
' GOT_TEAM="$(codesign -dvv "$STAGE" 2>&1 | sed -n \'s/^TeamIdentifier=//p\')"',
|
|
137
|
+
' [ "$GOT_TEAM" = "$TEAM" ] || { rm -rf "$STAGE"; die "signed by team $GOT_TEAM, expected $TEAM"; }',
|
|
138
|
+
' GOT_ID="$(/usr/libexec/PlistBuddy -c "Print :CFBundleIdentifier" "$STAGE/Contents/Info.plist")"',
|
|
139
|
+
' [ "$GOT_ID" = "$BUNDLE" ] || { rm -rf "$STAGE"; die "bundle id $GOT_ID, expected $BUNDLE"; }',
|
|
140
|
+
' spctl -a -t exec "$STAGE" >/dev/null 2>&1 || { rm -rf "$STAGE"; die "Gatekeeper rejected the app"; }',
|
|
141
|
+
' osascript -e "tell application \\"$APP\\" to quit" >/dev/null 2>&1 || true',
|
|
142
|
+
' rm -rf "$DEST/$APPDIR.previous"; [ -d "$DEST/$APPDIR" ] && mv "$DEST/$APPDIR" "$DEST/$APPDIR.previous"',
|
|
143
|
+
' if mv "$STAGE" "$DEST/$APPDIR"; then rm -rf "$DEST/$APPDIR.previous"; else [ -d "$DEST/$APPDIR.previous" ] && mv "$DEST/$APPDIR.previous" "$DEST/$APPDIR"; die "install failed; the previous copy was restored"; fi',
|
|
144
|
+
' printf "%s %s installed in %s\\n" "$APP" "$VERSION" "$DEST"',
|
|
145
|
+
" ;;",
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
if (linux) {
|
|
149
|
+
lines.push(
|
|
150
|
+
" Linux)",
|
|
151
|
+
` BINARY='${linux.binary}'`,
|
|
152
|
+
' SHARE="${XDG_DATA_HOME:-$HOME/.local/share}/$SLUG"; BIN="$HOME/.local/bin"',
|
|
153
|
+
' if [ "$UNINSTALL" = 1 ]; then rm -rf "$SHARE" "$BIN/$BINARY"; printf "%s removed\\n" "$APP"; exit 0; fi',
|
|
154
|
+
' case "$ARCH" in',
|
|
155
|
+
...LINUX_ARCHES.filter((arch) => linux[arch]).map((arch) => ` ${arch}) URL='${linux[arch].url}'; SHA='${linux[arch].sha256}' ;;`),
|
|
156
|
+
' *) die "unsupported architecture $ARCH" ;;',
|
|
157
|
+
" esac",
|
|
158
|
+
' fetch "$URL" "$TMP/app.tar.gz"; verify_sha "$TMP/app.tar.gz" "$SHA"',
|
|
159
|
+
' rm -rf "$SHARE.new"; mkdir -p "$SHARE.new" "$BIN"',
|
|
160
|
+
' tar -xzf "$TMP/app.tar.gz" -C "$SHARE.new" || die "extract failed"',
|
|
161
|
+
' [ -x "$SHARE.new/$BINARY" ] || die "$BINARY is not in the archive"',
|
|
162
|
+
' rm -rf "$SHARE"; mv "$SHARE.new" "$SHARE"; ln -sfn "$SHARE/$BINARY" "$BIN/$BINARY"',
|
|
163
|
+
' printf "%s %s installed in %s (link %s/%s)\\n" "$APP" "$VERSION" "$SHARE" "$BIN" "$BINARY"',
|
|
164
|
+
" ;;",
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
lines.push(' *) die "unsupported operating system $OS" ;;', "esac", "");
|
|
168
|
+
if (!mac) lines.splice(lines.indexOf("case \"$OS\" in") + 1, 0, ' Darwin) die "no macOS build of $APP is published" ;;');
|
|
169
|
+
return lines.join("\n");
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
export function renderInstallPs1(facts) {
|
|
173
|
+
const w = facts.windows;
|
|
174
|
+
if (!w) return null;
|
|
175
|
+
return [
|
|
176
|
+
`# ${header(facts, "this script")}`,
|
|
177
|
+
"# Rerun the same command to upgrade. Uninstall: & ([scriptblock]::Create((irm <this url>))) -Uninstall",
|
|
178
|
+
"param([switch]$Uninstall)",
|
|
179
|
+
"$ErrorActionPreference = 'Stop'",
|
|
180
|
+
`$App = '${facts.productName}'`,
|
|
181
|
+
`$Version = '${facts.version}'`,
|
|
182
|
+
`$Url = '${w.url}'`,
|
|
183
|
+
`$Sha = '${w.sha256}'`,
|
|
184
|
+
`$Signer = '${w.signerSubject}'`,
|
|
185
|
+
`$Dest = [Environment]::ExpandEnvironmentVariables('${w.installDirectory}')`,
|
|
186
|
+
`$Exe = '${w.exe}'`,
|
|
187
|
+
"if ($Uninstall) {",
|
|
188
|
+
" $un = Join-Path $Dest 'uninstall.exe'",
|
|
189
|
+
" if (Test-Path -LiteralPath $un) { Start-Process -FilePath $un -ArgumentList '/S' -Wait; Write-Output \"$App removed\" } else { Write-Output \"$App is not installed at $Dest\" }",
|
|
190
|
+
" return",
|
|
191
|
+
"}",
|
|
192
|
+
"$tmp = Join-Path ([IO.Path]::GetTempPath()) ([IO.Path]::GetRandomFileName() + '.exe')",
|
|
193
|
+
"try {",
|
|
194
|
+
" [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12",
|
|
195
|
+
" Invoke-WebRequest -UseBasicParsing -Uri $Url -OutFile $tmp",
|
|
196
|
+
" if ((Get-FileHash -Algorithm SHA256 -LiteralPath $tmp).Hash.ToLowerInvariant() -ne $Sha) { throw \"sha256 mismatch: refusing to run the installer\" }",
|
|
197
|
+
" $sig = Get-AuthenticodeSignature -LiteralPath $tmp",
|
|
198
|
+
" if ($sig.Status -ne 'Valid') { throw \"Authenticode status is $($sig.Status), not Valid\" }",
|
|
199
|
+
" if ($sig.SignerCertificate.Subject -notlike \"$Signer*\") { throw \"signed by $($sig.SignerCertificate.Subject), expected $Signer\" }",
|
|
200
|
+
" Get-Process -ErrorAction SilentlyContinue | Where-Object { $_.Path -and $_.Path.StartsWith($Dest, [StringComparison]::OrdinalIgnoreCase) } | Stop-Process -Force",
|
|
201
|
+
" $p = Start-Process -FilePath $tmp -ArgumentList @('/S', \"/D=$Dest\") -Wait -PassThru",
|
|
202
|
+
" if ($p.ExitCode -ne 0) { throw \"the installer exited $($p.ExitCode)\" }",
|
|
203
|
+
" if (-not (Test-Path -LiteralPath (Join-Path $Dest $Exe))) { throw \"$Exe is not in $Dest after the install\" }",
|
|
204
|
+
" Write-Output \"$App $Version installed in $Dest\"",
|
|
205
|
+
"} finally { Remove-Item -LiteralPath $tmp -Force -ErrorAction SilentlyContinue }",
|
|
206
|
+
"",
|
|
207
|
+
].join("\n");
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
export function renderCask(facts) {
|
|
211
|
+
const m = facts.mac;
|
|
212
|
+
if (!m) return null;
|
|
213
|
+
return [
|
|
214
|
+
`# ${header(facts, "this cask")}`,
|
|
215
|
+
`cask "${facts.app}" do`,
|
|
216
|
+
` version "${facts.version}"`,
|
|
217
|
+
` sha256 "${m.sha256}"`,
|
|
218
|
+
"",
|
|
219
|
+
` url "${m.url}"`,
|
|
220
|
+
` name "${facts.productName}"`,
|
|
221
|
+
` desc "${facts.description}"`,
|
|
222
|
+
` homepage "${facts.homepage}"`,
|
|
223
|
+
"",
|
|
224
|
+
` app "${m.appName}"`,
|
|
225
|
+
"end",
|
|
226
|
+
"",
|
|
227
|
+
].join("\n");
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
export function renderWingetManifests(facts) {
|
|
231
|
+
const w = facts.windows;
|
|
232
|
+
if (!w) return null;
|
|
233
|
+
const id = `${facts.publisherId ?? facts.publisher.replace(/[^A-Za-z0-9]/g, "")}.${facts.productName.replace(/[^A-Za-z0-9]/g, "")}`;
|
|
234
|
+
const schema = "1.6.0";
|
|
235
|
+
const head = (type) => `# yaml-language-server: $schema=https://aka.ms/winget-manifest.${type}.${schema}.schema.json\n`;
|
|
236
|
+
return {
|
|
237
|
+
id,
|
|
238
|
+
files: {
|
|
239
|
+
[`${id}.yaml`]: `${head("version")}PackageIdentifier: ${id}\nPackageVersion: ${facts.version}\nDefaultLocale: en-US\nManifestType: version\nManifestVersion: ${schema}\n`,
|
|
240
|
+
[`${id}.installer.yaml`]: `${head("installer")}PackageIdentifier: ${id}\nPackageVersion: ${facts.version}\nInstallerType: nullsoft\nScope: user\nInstallModes:\n - silent\n - silentWithProgress\nInstallerSwitches:\n Silent: /S\n SilentWithProgress: /S\nInstallers:\n - Architecture: x64\n InstallerUrl: ${w.url}\n InstallerSha256: ${w.sha256.toUpperCase()}\nManifestType: installer\nManifestVersion: ${schema}\n`,
|
|
241
|
+
[`${id}.locale.en-US.yaml`]: `${head("defaultLocale")}PackageIdentifier: ${id}\nPackageVersion: ${facts.version}\nPackageLocale: en-US\nPublisher: ${JSON.stringify(facts.publisher)}\nPackageName: ${JSON.stringify(facts.productName)}\nShortDescription: ${JSON.stringify(facts.description)}\nPackageUrl: ${facts.homepage}\nLicense: ${JSON.stringify(facts.license ?? "Proprietary")}\nManifestType: defaultLocale\nManifestVersion: ${schema}\n`,
|
|
242
|
+
},
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/** Render every channel the facts allow: { files: { "<relative path>": text } }. Pure: nothing is written. */
|
|
247
|
+
export function renderInstallChannels(rawFacts) {
|
|
248
|
+
const facts = validateChannelFacts(rawFacts);
|
|
249
|
+
const files = { "install.sh": renderInstallSh(facts) };
|
|
250
|
+
const ps1 = renderInstallPs1(facts);
|
|
251
|
+
if (ps1) files["install.ps1"] = ps1;
|
|
252
|
+
const cask = renderCask(facts);
|
|
253
|
+
if (cask) files[`Casks/${facts.app}.rb`] = cask;
|
|
254
|
+
const winget = renderWingetManifests(facts);
|
|
255
|
+
if (winget) for (const [name, text] of Object.entries(winget.files)) files[`winget/${name}`] = text;
|
|
256
|
+
const sha = (text) => createHash("sha256").update(text).digest("hex");
|
|
257
|
+
files["install-channels.json"] = `${JSON.stringify({ schema: 1, app: facts.app, version: facts.version, host: facts.host, files: Object.fromEntries(Object.entries(files).map(([name, text]) => [name, { sha256: sha(text), bytes: Buffer.byteLength(text) }])) }, null, 2)}\n`;
|
|
258
|
+
return { files };
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/** Write the rendered files under `out`; with `check`, write nothing and report the files whose bytes on disk differ. */
|
|
262
|
+
export function writeInstallChannels(rawFacts, out, { check = false, fs = { mkdirSync, readFileSync, renameSync, writeFileSync } } = {}) {
|
|
263
|
+
const { files } = renderInstallChannels(rawFacts);
|
|
264
|
+
const root = path.resolve(out);
|
|
265
|
+
const differing = [];
|
|
266
|
+
for (const [name, text] of Object.entries(files)) {
|
|
267
|
+
const file = path.join(root, ...name.split("/"));
|
|
268
|
+
let current = null;
|
|
269
|
+
try { current = String(fs.readFileSync(file, "utf8")); } catch { current = null; }
|
|
270
|
+
if (current !== text) differing.push(name);
|
|
271
|
+
if (check || current === text) continue;
|
|
272
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
273
|
+
const temporary = `${file}.tmp-${process.pid}`;
|
|
274
|
+
fs.writeFileSync(temporary, text);
|
|
275
|
+
fs.renameSync(temporary, file);
|
|
276
|
+
}
|
|
277
|
+
return { out: root, files: Object.keys(files), differing };
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
export function main(argv = process.argv.slice(2)) {
|
|
281
|
+
let factsFile; let out; let check = false;
|
|
282
|
+
for (let i = 0; i < argv.length; i += 1) {
|
|
283
|
+
if (argv[i] === "--facts" && argv[i + 1]) { factsFile = argv[i + 1]; i += 1; }
|
|
284
|
+
else if (argv[i] === "--out" && argv[i + 1]) { out = argv[i + 1]; i += 1; }
|
|
285
|
+
else if (argv[i] === "--check") check = true;
|
|
286
|
+
else { console.error(`right-release install-channels: unknown or incomplete argument ${argv[i]}\nusage: right-release install-channels --facts <facts.json> --out <dir> [--check]`); return 2; }
|
|
287
|
+
}
|
|
288
|
+
if (!factsFile || !out) { console.error("usage: right-release install-channels --facts <facts.json> --out <dir> [--check]"); return 2; }
|
|
289
|
+
try {
|
|
290
|
+
const result = writeInstallChannels(JSON.parse(readFileSync(path.resolve(factsFile), "utf8")), out, { check });
|
|
291
|
+
if (check) {
|
|
292
|
+
if (result.differing.length) { console.error(`right-release install-channels: ${result.differing.length} file(s) differ from the facts: ${result.differing.join(", ")}`); return 1; }
|
|
293
|
+
console.log(`right-release install-channels: ${result.files.length} file(s) match`);
|
|
294
|
+
return 0;
|
|
295
|
+
}
|
|
296
|
+
console.log(`right-release install-channels: wrote ${result.files.length} file(s) to ${result.out}${result.differing.length ? ` (${result.differing.length} changed)` : " (all unchanged)"}`);
|
|
297
|
+
return 0;
|
|
298
|
+
} catch (error) { console.error(`right-release install-channels: ${error.message}`); return error instanceof InstallChannelsError ? 1 : 2; }
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) process.exitCode = main();
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// `right-release session-run [--state-dir <dir>] [--timeout-ms <n>] -- <command> [args...]` (rightkit#816, #428): run one command in the signing user's
|
|
3
|
+
// interactive Windows logon session and return its exit code and output.
|
|
4
|
+
//
|
|
5
|
+
// Why: the Azure signer (sign-windows.mjs) needs the token cache of the logon session (sign-windows.mjs names it: AzureCliCredential finds a token only
|
|
6
|
+
// in the desktop session that signed in). A command started from an SSH shell, a service or an agent shell runs in another session and finds none. The
|
|
7
|
+
// way into the logon session without a prompt is a ONE-SHOT scheduled task registered for the current user with `/IT` (interactive only): it starts,
|
|
8
|
+
// runs the command hidden, and is deleted again. Nothing stays registered, no credential is passed or stored, and nothing runs with elevated rights
|
|
9
|
+
// (`/RL LIMITED`).
|
|
10
|
+
//
|
|
11
|
+
// The command and its arguments travel as JSON in the state folder and are read by a fixed PowerShell wrapper that calls the program with an argument
|
|
12
|
+
// array, so there is no shell quoting of a user string anywhere (no injection through an argument). The wrapper writes `exit.txt` last; the runner
|
|
13
|
+
// polls for it, copies the log to stdout, removes the task and the state folder, and exits with the command's code.
|
|
14
|
+
import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
15
|
+
import os from "node:os";
|
|
16
|
+
import path from "node:path";
|
|
17
|
+
import { pathToFileURL } from "node:url";
|
|
18
|
+
import { spawnSync } from "./background-process.mjs";
|
|
19
|
+
|
|
20
|
+
export class SessionRunError extends Error {
|
|
21
|
+
constructor(message) { super(message); this.name = "SessionRunError"; this.code = "RK_SESSION_RUN"; }
|
|
22
|
+
}
|
|
23
|
+
const fail = (message) => { throw new SessionRunError(message); };
|
|
24
|
+
|
|
25
|
+
export const SESSION_WRAPPER = [
|
|
26
|
+
"$ErrorActionPreference = 'Stop'",
|
|
27
|
+
"$dir = Split-Path -Parent $MyInvocation.MyCommand.Path",
|
|
28
|
+
"$job = Get-Content -Raw -LiteralPath (Join-Path $dir 'job.json') | ConvertFrom-Json",
|
|
29
|
+
"$code = 1",
|
|
30
|
+
"try {",
|
|
31
|
+
" $argList = @(); if ($job.args) { $argList = @($job.args) }",
|
|
32
|
+
" & $job.command @argList *> (Join-Path $dir 'output.log')",
|
|
33
|
+
" if ($null -ne $LASTEXITCODE) { $code = $LASTEXITCODE } else { $code = 0 }",
|
|
34
|
+
"} catch { $_ | Out-String | Add-Content -LiteralPath (Join-Path $dir 'output.log'); $code = 1 }",
|
|
35
|
+
"Set-Content -LiteralPath (Join-Path $dir 'exit.txt') -Value $code -NoNewline",
|
|
36
|
+
"",
|
|
37
|
+
].join("\r\n");
|
|
38
|
+
|
|
39
|
+
export function parseSessionRunArgs(argv) {
|
|
40
|
+
const opts = { stateDir: null, timeoutMs: 30 * 60 * 1000, command: [] };
|
|
41
|
+
for (let i = 0; i < argv.length; i += 1) {
|
|
42
|
+
const flag = argv[i];
|
|
43
|
+
if (flag === "--") { opts.command = argv.slice(i + 1); break; }
|
|
44
|
+
if (flag === "--state-dir" || flag === "--timeout-ms") {
|
|
45
|
+
const value = argv[i + 1];
|
|
46
|
+
if (value === undefined || value.startsWith("--")) fail(`${flag} needs a value`);
|
|
47
|
+
i += 1;
|
|
48
|
+
if (flag === "--state-dir") opts.stateDir = value;
|
|
49
|
+
else { opts.timeoutMs = Number(value); if (!Number.isInteger(opts.timeoutMs) || opts.timeoutMs < 1000) fail("--timeout-ms must be an integer of at least 1000"); }
|
|
50
|
+
} else fail(`unknown argument: ${flag} (put the command after --)`);
|
|
51
|
+
}
|
|
52
|
+
if (!opts.command.length || !opts.command[0]) fail("a command is required after --");
|
|
53
|
+
return opts;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** The one-shot task's `/TR` text: a hidden PowerShell running the fixed wrapper. The wrapper path never holds a user string. */
|
|
57
|
+
export function sessionTaskAction(wrapperPath) {
|
|
58
|
+
if (/["\r\n]/.test(wrapperPath)) fail("the state folder path must not contain a quote or a line break");
|
|
59
|
+
return `powershell.exe -NoProfile -NonInteractive -WindowStyle Hidden -ExecutionPolicy Bypass -File "${wrapperPath}"`;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export async function runInInteractiveSession(opts, deps = {}) {
|
|
63
|
+
const { run = spawnSync, fs = { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync }, platform = process.platform, env = process.env, user = os.userInfo().username, pid = process.pid, now = Date.now, sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms)), log = (line) => console.error(line), write = (text) => process.stdout.write(text) } = deps;
|
|
64
|
+
if (platform !== "win32") fail("session-run is for Windows: it uses a one-shot scheduled task in the interactive logon session");
|
|
65
|
+
const stateRoot = opts.stateDir ?? path.join(env.RIGHT_RELEASE_STATE_ROOT ?? "", "session-run");
|
|
66
|
+
if (!path.isAbsolute(stateRoot)) fail("an absolute --state-dir (or RIGHT_RELEASE_STATE_ROOT) is required: the job and its output live there");
|
|
67
|
+
const dir = path.join(stateRoot, `job-${pid}-${now()}`);
|
|
68
|
+
const task = `RightKit-session-run-${pid}-${now()}`;
|
|
69
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
70
|
+
const wrapper = path.join(dir, "run.ps1");
|
|
71
|
+
fs.writeFileSync(wrapper, SESSION_WRAPPER);
|
|
72
|
+
fs.writeFileSync(path.join(dir, "job.json"), JSON.stringify({ command: opts.command[0], args: opts.command.slice(1) }));
|
|
73
|
+
const schtasks = (args) => run("schtasks.exe", args, { encoding: "utf8", windowsHide: true, shell: false });
|
|
74
|
+
const must = (result, what) => { if (result?.error || result?.status !== 0) fail(`${what} failed (${result?.error?.message ?? `exit ${result?.status}`}): ${String(result?.stderr ?? result?.stdout ?? "").trim()}`); };
|
|
75
|
+
let registered = false;
|
|
76
|
+
try {
|
|
77
|
+
must(schtasks(["/Create", "/TN", task, "/SC", "ONCE", "/ST", "23:59", "/RU", user, "/IT", "/RL", "LIMITED", "/F", "/TR", sessionTaskAction(wrapper)]), "registering the one-shot task");
|
|
78
|
+
registered = true;
|
|
79
|
+
must(schtasks(["/Run", "/TN", task]), "starting the one-shot task (is the user logged on to the desktop?)");
|
|
80
|
+
const deadline = now() + opts.timeoutMs;
|
|
81
|
+
while (!fs.existsSync(path.join(dir, "exit.txt"))) {
|
|
82
|
+
if (now() > deadline) fail(`the command did not finish within ${Math.round(opts.timeoutMs / 1000)}s; the task ${task} is being removed`);
|
|
83
|
+
await sleep(500);
|
|
84
|
+
}
|
|
85
|
+
const output = fs.existsSync(path.join(dir, "output.log")) ? String(fs.readFileSync(path.join(dir, "output.log"), "utf8")) : "";
|
|
86
|
+
const code = Number.parseInt(String(fs.readFileSync(path.join(dir, "exit.txt"), "utf8")).trim(), 10);
|
|
87
|
+
if (output) write(output.endsWith("\n") ? output : `${output}\n`);
|
|
88
|
+
return { code: Number.isInteger(code) ? code : 1, task };
|
|
89
|
+
} finally {
|
|
90
|
+
if (registered) { try { schtasks(["/End", "/TN", task]); } catch { /* not running */ } try { schtasks(["/Delete", "/TN", task, "/F"]); } catch (error) { log(`session-run: could not delete task ${task} (${error.message})`); } }
|
|
91
|
+
fs.rmSync(dir, { recursive: true, force: true });
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export async function main(argv = process.argv.slice(2)) {
|
|
96
|
+
try {
|
|
97
|
+
const result = await runInInteractiveSession(parseSessionRunArgs(argv));
|
|
98
|
+
return result.code;
|
|
99
|
+
} catch (error) {
|
|
100
|
+
console.error(`right-release session-run: ${error.message}`);
|
|
101
|
+
return error instanceof SessionRunError ? 125 : 1;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) main().then((code) => { process.exitCode = code; });
|
package/legal-contract.mjs
CHANGED
|
@@ -2,6 +2,10 @@ import { createHash } from "node:crypto";
|
|
|
2
2
|
import { existsSync, readFileSync, realpathSync } from "node:fs";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
|
|
5
|
+
// The role table mirrors @rightkit/legal src/core.ts (REQUIRED_ROLES, OSS_REQUIRED_ROLES, assertLegalManifest): this package cannot import
|
|
6
|
+
// @rightkit/legal without a dependency cycle (legal declares release as an optional peer, #972), so the two lists are kept identical here.
|
|
7
|
+
// A manifest declares `profile: "proprietary"` (the default) or `"oss"`; every role stays a valid document role, but an oss manifest is
|
|
8
|
+
// required to carry only privacy_notice and third_party_notices (#1043).
|
|
5
9
|
const REQUIRED_ROLES = new Set([
|
|
6
10
|
"license",
|
|
7
11
|
"eula",
|
|
@@ -10,6 +14,7 @@ const REQUIRED_ROLES = new Set([
|
|
|
10
14
|
"privacy_notice",
|
|
11
15
|
"third_party_notices",
|
|
12
16
|
]);
|
|
17
|
+
const OSS_REQUIRED_ROLES = new Set(["privacy_notice", "third_party_notices"]);
|
|
13
18
|
const AGREEMENT_ROLES = new Set(["license", "eula", "acceptable_use", "product_schedule"]);
|
|
14
19
|
const SHA256 = /^[a-f0-9]{64}$/i;
|
|
15
20
|
const APP_KEY = /^[a-z][a-z0-9-]{1,63}$/;
|
|
@@ -69,6 +74,9 @@ export function assertLegalReleaseContract(root, legal, appName, platform) {
|
|
|
69
74
|
if (typeof manifest.acceptanceVersion !== "string" || !manifest.acceptanceVersion.trim()) {
|
|
70
75
|
fail(appName, "manifest acceptanceVersion is required");
|
|
71
76
|
}
|
|
77
|
+
if (manifest.profile !== undefined && manifest.profile !== "proprietary" && manifest.profile !== "oss") {
|
|
78
|
+
fail(appName, "manifest profile must be proprietary or oss");
|
|
79
|
+
}
|
|
72
80
|
if (!Array.isArray(manifest.documents)) fail(appName, "manifest documents must be an array");
|
|
73
81
|
|
|
74
82
|
const seen = new Set();
|
|
@@ -108,7 +116,7 @@ export function assertLegalReleaseContract(root, legal, appName, platform) {
|
|
|
108
116
|
}
|
|
109
117
|
resolvedDocuments.push({ ...document, absolutePath: realFile });
|
|
110
118
|
}
|
|
111
|
-
for (const role of REQUIRED_ROLES) {
|
|
119
|
+
for (const role of manifest.profile === "oss" ? OSS_REQUIRED_ROLES : REQUIRED_ROLES) {
|
|
112
120
|
if (!seen.has(role)) fail(appName, `missing required document role: ${role}`);
|
|
113
121
|
}
|
|
114
122
|
|
|
@@ -160,6 +168,7 @@ export function assertLegalReleaseContract(root, legal, appName, platform) {
|
|
|
160
168
|
return {
|
|
161
169
|
appKey: manifest.appKey,
|
|
162
170
|
acceptanceVersion: manifest.acceptanceVersion,
|
|
171
|
+
profile: manifest.profile ?? "proprietary",
|
|
163
172
|
manifestPath,
|
|
164
173
|
manifestSha256: sha256(manifestBytes),
|
|
165
174
|
documents: resolvedDocuments,
|