feat(packaging): a per-user Windows installer, a universal macOS app and dmg, desktop entries with the icon (P15 C1)
Windows: a hand-written NSIS script (per user, no administrator prompt, installs under the profile's Programs folder; one program file; a Start Menu entry named Wanderbooks with the icon; an uninstaller listed in Settings > Apps that removes only what the installer put in its own folder and never names the data folder). The installer asks the person to quit the app fully before it replaces or removes the program. An optional Authenticode signing step runs only when its secrets exist. macOS: the .app is assembled by a script (Info.plist with the bundle identifier, version, name, Documents-folder purpose string; the one program at Contents/MacOS/wanderbooks; the licences), signed with the hardened runtime and an empty entitlements file that says why, put in a dmg with an Applications shortcut, notarized and stapled when the owner's Apple identity is given and skipped with a notice when not. The program is one universal binary (lipo of the two release builds). Linux: both desktop entries name the window's app id and the icon; the rpm now installs the icon; the deb, the pacman tarball and the rpm all carry LICENSE-MIT and LICENSE-APACHE beside the notices. One version: deploy/packaging/version.sh reads crates/ledger-cli's Cargo.toml; every script takes it from there. Tests read the scripts and build a bundle with a stand-in program. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
1 parent
90f663ed54
commit
8e3db472fa
19 files changed
+1110
-86
No files matched your search
@@ -82,5 +82,8 @@ assets = [
|
||||
{ source = "target/release/wanderbooks", dest = "/usr/bin/wanderbooks", mode = "0755" },
|
||||
{ source = "deploy/packaging/install-method-rpm", dest = "/usr/share/wanderbooks/install-method", mode = "0644" },
|
||||
{ source = "deploy/packaging/wanderbooks-static.desktop", dest = "/usr/share/applications/wanderbooks.desktop", mode = "0644" },
|
||||
{ source = "deploy/packaging/icons/512x512.png", dest = "/usr/share/icons/hicolor/512x512/apps/wanderbooks.png", mode = "0644" },
|
||||
{ source = "LICENSE-MIT", dest = "/usr/share/doc/wanderbooks/LICENSE-MIT", mode = "0644" },
|
||||
{ source = "LICENSE-APACHE", dest = "/usr/share/doc/wanderbooks/LICENSE-APACHE", mode = "0644" },
|
||||
{ source = "THIRD-PARTY-NOTICES.txt", dest = "/usr/share/doc/wanderbooks/THIRD-PARTY-NOTICES.txt", mode = "0644" },
|
||||
]
|
||||
@@ -0,0 +1,570 @@
|
||||
//! The packages (plan P15 unit C1; WB-pkg-1 to WB-pkg-7): what can be checked
|
||||
//! on Linux about the Windows installer, the macOS app, the Linux entries and
|
||||
//! the one source of the version. For Windows and macOS the release workflow
|
||||
//! is the real test (each packaging step fails loudly); these tests keep the
|
||||
//! files it builds from true to the rules.
|
||||
//!
|
||||
//! ```text
|
||||
//! GOAL: an installed Wanderbooks is one executable at a stable path, named
|
||||
//! Wanderbooks everywhere a person sees it, with the licences beside
|
||||
//! it; installing a newer one over it, or uninstalling it, never
|
||||
//! touches the person's books.
|
||||
//! SOURCE: WB-pkg-1 (installs like a normal program), WB-pkg-2 (one
|
||||
//! executable, a stable bridge path), WB-pkg-6 (one version, one
|
||||
//! name), WB-pkg-7 (the release carries the licences); D-77.
|
||||
//! INVARIANTS:
|
||||
//! 1. The version is written once (ledger-cli's Cargo.toml); the packaging
|
||||
//! scripts read it through deploy/packaging/version.sh.
|
||||
//! 2. The Windows installer is per user (no administrator), installs one
|
||||
//! program, and its uninstaller names nothing but what the installer
|
||||
//! put in its own folder: no recursive removal, no wildcard, no data
|
||||
//! folder.
|
||||
//! 3. The macOS bundle holds one program at Contents/MacOS/wanderbooks, an
|
||||
//! Info.plist whose identifier, name, version and executable agree with
|
||||
//! the scripts, and the licences.
|
||||
//! 4. The Linux desktop entries launch plain `wanderbooks` (an AppImage's
|
||||
//! launcher appends what it is given) with the icon, the name, and the
|
||||
//! window's app id.
|
||||
//! 5. Every package carries LICENSE-MIT, LICENSE-APACHE and
|
||||
//! THIRD-PARTY-NOTICES.txt.
|
||||
//! SCENARIOS:
|
||||
//! 1. The bundle script run on Linux with a stand-in program makes a
|
||||
//! bundle whose plist and files match the rules above.
|
||||
//! ```
|
||||
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::process::Command;
|
||||
|
||||
fn root() -> PathBuf {
|
||||
Path::new(env!("CARGO_MANIFEST_DIR")).join("../..")
|
||||
}
|
||||
|
||||
fn read(path: &str) -> String {
|
||||
std::fs::read_to_string(root().join(path)).unwrap_or_else(|e| panic!("{path}: {e}"))
|
||||
}
|
||||
|
||||
/// The lines of `text` that are not comments (`;` for NSIS, `#` for shell
|
||||
/// and TOML).
|
||||
fn code(text: &str) -> Vec<&str> {
|
||||
text.lines()
|
||||
.map(str::trim)
|
||||
.filter(|l| !l.is_empty() && !l.starts_with(';') && !l.starts_with('#'))
|
||||
.collect()
|
||||
}
|
||||
|
||||
const LICENCE_FILES: [&str; 3] = ["LICENSE-MIT", "LICENSE-APACHE", "THIRD-PARTY-NOTICES.txt"];
|
||||
|
||||
// ---- the version, written once ---------------------------------------------------
|
||||
|
||||
#[cfg(unix)]
|
||||
#[test]
|
||||
fn the_version_is_written_once_and_every_script_reads_it_from_there() {
|
||||
let out = Command::new("sh")
|
||||
.arg(root().join("deploy/packaging/version.sh"))
|
||||
.output()
|
||||
.unwrap();
|
||||
assert!(out.status.success(), "{out:?}");
|
||||
let said = String::from_utf8(out.stdout).unwrap();
|
||||
assert_eq!(said.trim(), env!("CARGO_PKG_VERSION"));
|
||||
|
||||
// The Linux packager's own file carries a version the build script
|
||||
// overwrites; it must not drift from the source.
|
||||
let packager = read("deploy/packaging/packager.toml");
|
||||
let line = code(&packager)
|
||||
.into_iter()
|
||||
.find(|l| l.starts_with("version = "))
|
||||
.unwrap();
|
||||
assert_eq!(line, format!("version = \"{}\"", env!("CARGO_PKG_VERSION")));
|
||||
|
||||
// No packaging script or workflow assigns a literal version.
|
||||
for file in [
|
||||
"deploy/packaging/windows/build-windows.sh",
|
||||
"deploy/packaging/macos/build-macos.sh",
|
||||
".github/workflows/release.yml",
|
||||
] {
|
||||
for line in code(&read(file)) {
|
||||
let assigns = line.starts_with("version=") || line.starts_with("version:");
|
||||
let literal = line.split(['=', ':']).nth(1).is_some_and(|v| {
|
||||
v.trim()
|
||||
.trim_matches('"')
|
||||
.chars()
|
||||
.next()
|
||||
.is_some_and(|c| c.is_ascii_digit())
|
||||
});
|
||||
assert!(!(assigns && literal), "{file}: a literal version: {line}");
|
||||
}
|
||||
}
|
||||
for file in [
|
||||
"deploy/packaging/windows/build-windows.sh",
|
||||
"deploy/packaging/macos/build-macos.sh",
|
||||
"deploy/packaging/build-linux.sh",
|
||||
] {
|
||||
let text = read(file);
|
||||
assert!(
|
||||
text.contains("version.sh") || text.contains("ledger-cli/Cargo.toml"),
|
||||
"{file} does not read the version from its one source"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
#[test]
|
||||
fn a_version_that_is_not_three_numbers_is_refused() {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
std::fs::create_dir_all(dir.path().join("deploy/packaging")).unwrap();
|
||||
std::fs::create_dir_all(dir.path().join("crates/ledger-cli")).unwrap();
|
||||
std::fs::copy(
|
||||
root().join("deploy/packaging/version.sh"),
|
||||
dir.path().join("deploy/packaging/version.sh"),
|
||||
)
|
||||
.unwrap();
|
||||
for (toml, ok) in [
|
||||
("version = \"0.2.0\"\n", true),
|
||||
("version = \"0.2.0-rc1\"\n", false),
|
||||
("version = \"two\"\n", false),
|
||||
("", false),
|
||||
] {
|
||||
std::fs::write(dir.path().join("crates/ledger-cli/Cargo.toml"), toml).unwrap();
|
||||
let out = Command::new("sh")
|
||||
.arg(dir.path().join("deploy/packaging/version.sh"))
|
||||
.output()
|
||||
.unwrap();
|
||||
assert_eq!(out.status.success(), ok, "{toml:?}: {out:?}");
|
||||
}
|
||||
}
|
||||
|
||||
// ---- Windows --------------------------------------------------------------------
|
||||
|
||||
#[test]
|
||||
fn the_windows_installer_is_per_user_and_installs_one_program() {
|
||||
let nsi = read("deploy/packaging/windows/wanderbooks.nsi");
|
||||
let lines = code(&nsi);
|
||||
let has = |needle: &str| lines.iter().any(|l| l.contains(needle));
|
||||
// No administrator prompt; everything in the person's own profile.
|
||||
assert!(has("RequestExecutionLevel user"));
|
||||
assert!(has(r#"InstallDir "$LOCALAPPDATA\Programs\Wanderbooks""#));
|
||||
assert!(
|
||||
!lines.iter().any(|l| l.contains("HKLM")),
|
||||
"per-machine registry"
|
||||
);
|
||||
assert!(!has("SetShellVarContext all"), "all users' Start Menu");
|
||||
// A Start Menu entry named Wanderbooks, with the icon.
|
||||
assert!(has(
|
||||
r#"CreateShortCut "$SMPROGRAMS\${NAME}.lnk" "$INSTDIR\wanderbooks.exe""#
|
||||
));
|
||||
assert!(has(r#"!define NAME "Wanderbooks""#));
|
||||
assert!(has("wanderbooks.ico"));
|
||||
// An uninstaller, listed in Settings > Apps, whose name is the product's.
|
||||
assert!(has("WriteUninstaller"));
|
||||
assert!(has(r#""DisplayName" "${NAME}""#));
|
||||
assert!(has("UninstallString"));
|
||||
// One program: the only .exe installed besides the uninstaller.
|
||||
let programs: Vec<&&str> = lines
|
||||
.iter()
|
||||
.filter(|l| l.starts_with("File ") && l.contains(".exe"))
|
||||
.collect();
|
||||
assert_eq!(programs.len(), 1, "{programs:?}");
|
||||
assert!(programs[0].contains("/oname=wanderbooks.exe"));
|
||||
// The licences travel with it.
|
||||
for file in LICENCE_FILES {
|
||||
assert!(has(&format!("/oname={file}")), "{file} is not installed");
|
||||
}
|
||||
}
|
||||
|
||||
/// WB-pkg-1: the uninstaller removes what the installer put in its own
|
||||
/// folder and nothing else; the books are in the data folder, which it never
|
||||
/// names.
|
||||
#[test]
|
||||
fn the_uninstaller_never_removes_the_books() {
|
||||
let nsi = read("deploy/packaging/windows/wanderbooks.nsi");
|
||||
let lines = code(&nsi);
|
||||
let start = lines
|
||||
.iter()
|
||||
.position(|l| l.starts_with(r#"Section "Uninstall""#))
|
||||
.expect("an uninstall section");
|
||||
let section = &lines[start..];
|
||||
let mut removals = 0;
|
||||
for line in section {
|
||||
let word = line.split_whitespace().next().unwrap_or("");
|
||||
if matches!(word, "Delete" | "RMDir" | "DeleteRegKey" | "DeleteRegValue") {
|
||||
removals += 1;
|
||||
assert!(!line.contains("/r"), "a recursive removal: {line}");
|
||||
assert!(
|
||||
!line.contains('*') && !line.contains('?'),
|
||||
"a wildcard: {line}"
|
||||
);
|
||||
let ok = line.contains("$INSTDIR")
|
||||
|| line.contains("$SMPROGRAMS")
|
||||
|| line.contains("${UNINSTALL_KEY}")
|
||||
|| line.contains("${APP_KEY}");
|
||||
assert!(
|
||||
ok,
|
||||
"removes something that is not the program's own: {line}"
|
||||
);
|
||||
}
|
||||
}
|
||||
assert!(removals >= 6, "the uninstaller removes the installed files");
|
||||
// The data folder, the roaming settings and the keys are named nowhere
|
||||
// in the script's code (the comments say where the books are).
|
||||
for line in &lines {
|
||||
for data in [
|
||||
"$LOCALAPPDATA\\wanderbooks",
|
||||
"$APPDATA",
|
||||
"\\link",
|
||||
"legacy",
|
||||
"books\\",
|
||||
] {
|
||||
assert!(!line.contains(data), "{data} named: {line}");
|
||||
}
|
||||
}
|
||||
// Only the registry keys of its own.
|
||||
let keys: Vec<&&str> = lines
|
||||
.iter()
|
||||
.filter(|l| l.starts_with("!define") && l.contains("_KEY"))
|
||||
.collect();
|
||||
assert_eq!(keys.len(), 2, "{keys:?}");
|
||||
assert!(keys[0].contains(r"Software\Microsoft\Windows\CurrentVersion\Uninstall\Wanderbooks"));
|
||||
assert!(keys[1].contains(r"Software\Wanderbooks"));
|
||||
}
|
||||
|
||||
/// If NSIS is installed here, the script compiles with stand-in files
|
||||
/// (the release workflow compiles it for real on Windows).
|
||||
#[test]
|
||||
fn the_installer_script_compiles_when_nsis_is_here() {
|
||||
let Some(makensis) = std::env::var_os("PATH").and_then(|p| {
|
||||
std::env::split_paths(&p)
|
||||
.map(|d| d.join("makensis"))
|
||||
.find(|f| f.is_file())
|
||||
}) else {
|
||||
eprintln!(
|
||||
"makensis is not installed here: the Windows job of the release workflow compiles the installer"
|
||||
);
|
||||
return;
|
||||
};
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let p = dir.path();
|
||||
std::fs::write(p.join("wanderbooks.exe"), b"MZ").unwrap();
|
||||
for f in LICENCE_FILES {
|
||||
std::fs::write(p.join(f), b"x").unwrap();
|
||||
}
|
||||
std::fs::copy(
|
||||
root().join("deploy/packaging/icons/wanderbooks.ico"),
|
||||
p.join("wanderbooks.ico"),
|
||||
)
|
||||
.unwrap();
|
||||
let out = Command::new(makensis)
|
||||
.arg("-V2")
|
||||
.arg(format!("-DVERSION={}", env!("CARGO_PKG_VERSION")))
|
||||
.arg(format!("-DPROGRAM={}", p.join("wanderbooks.exe").display()))
|
||||
.arg(format!("-DICON={}", p.join("wanderbooks.ico").display()))
|
||||
.arg(format!("-DLICENSES={}", p.display()))
|
||||
.arg(format!("-DOUTFILE={}", p.join("setup.exe").display()))
|
||||
.arg(root().join("deploy/packaging/windows/wanderbooks.nsi"))
|
||||
.output()
|
||||
.unwrap();
|
||||
assert!(
|
||||
out.status.success(),
|
||||
"{}",
|
||||
String::from_utf8_lossy(&out.stdout)
|
||||
);
|
||||
assert!(p.join("setup.exe").metadata().unwrap().len() > 0);
|
||||
}
|
||||
|
||||
/// WB-pkg-2: on Windows the one executable is built for the GUI subsystem
|
||||
/// (no console window for the app), and gives a terminal its words back.
|
||||
#[test]
|
||||
fn the_windows_program_opens_no_console_window_and_still_speaks_in_a_terminal() {
|
||||
let main = read("crates/ledger-cli/src/main.rs");
|
||||
assert!(
|
||||
main.contains(
|
||||
r#"#![cfg_attr(all(windows, feature = "gui"), windows_subsystem = "windows")]"#
|
||||
)
|
||||
);
|
||||
assert!(main.contains("console::attach_parent_console()"));
|
||||
let console = read("crates/ledger-cli/src/console.rs");
|
||||
assert!(console.contains("AttachConsole(ATTACH_PARENT_PROCESS)"));
|
||||
// The server child the app starts has no console window of its own.
|
||||
assert!(read("crates/ledger-host/src/app_server.rs").contains("NO_WINDOW"));
|
||||
}
|
||||
|
||||
// ---- macOS ----------------------------------------------------------------------
|
||||
|
||||
/// The `<key>`/value pairs of a plist's top-level dict, as text. Good enough
|
||||
/// for the plain plists here (no nesting).
|
||||
fn plist(text: &str) -> Vec<(String, String)> {
|
||||
let mut pairs = Vec::new();
|
||||
let mut key: Option<String> = None;
|
||||
for line in text.lines().map(str::trim) {
|
||||
if let Some(k) = line
|
||||
.strip_prefix("<key>")
|
||||
.and_then(|l| l.strip_suffix("</key>"))
|
||||
{
|
||||
assert!(key.is_none(), "a key with no value: {k}");
|
||||
key = Some(k.to_string());
|
||||
} else if let Some(k) = key.take_if(|_| line.starts_with('<') && !line.starts_with("<!--"))
|
||||
{
|
||||
let value = line
|
||||
.strip_prefix("<string>")
|
||||
.and_then(|l| l.strip_suffix("</string>"))
|
||||
.map(str::to_string)
|
||||
.unwrap_or_else(|| line.to_string());
|
||||
pairs.push((k, value));
|
||||
}
|
||||
}
|
||||
assert!(key.is_none(), "a key with no value at the end");
|
||||
pairs
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
#[test]
|
||||
fn the_macos_bundle_has_one_program_and_a_plist_that_agrees_with_the_scripts() {
|
||||
use std::os::unix::fs::PermissionsExt;
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let stand_in = dir.path().join("program");
|
||||
std::fs::write(&stand_in, b"not a real program").unwrap();
|
||||
let version = "0.0.7";
|
||||
let out = Command::new("bash")
|
||||
.arg(root().join("deploy/packaging/macos/build-macos.sh"))
|
||||
.arg(version)
|
||||
.env("WB_PROGRAM", &stand_in)
|
||||
.env("WB_NO_ICNS", "1")
|
||||
.env("WB_BUNDLE_ONLY", "1")
|
||||
.output()
|
||||
.unwrap();
|
||||
let app = root().join(format!(
|
||||
"target/packages/.stage-macos-{version}/Wanderbooks.app"
|
||||
));
|
||||
let cleanup = Cleanup(root().join(format!("target/packages/.stage-macos-{version}")));
|
||||
assert!(
|
||||
out.status.success(),
|
||||
"{}{}",
|
||||
String::from_utf8_lossy(&out.stdout),
|
||||
String::from_utf8_lossy(&out.stderr)
|
||||
);
|
||||
|
||||
let exe = app.join("Contents/MacOS/wanderbooks");
|
||||
assert!(exe.is_file());
|
||||
assert_ne!(
|
||||
exe.metadata().unwrap().permissions().mode() & 0o111,
|
||||
0,
|
||||
"not executable"
|
||||
);
|
||||
let programs: Vec<_> = std::fs::read_dir(app.join("Contents/MacOS"))
|
||||
.unwrap()
|
||||
.collect();
|
||||
assert_eq!(programs.len(), 1, "one program in the bundle");
|
||||
for file in LICENCE_FILES {
|
||||
assert!(
|
||||
app.join("Contents/Resources").join(file).is_file(),
|
||||
"{file}"
|
||||
);
|
||||
}
|
||||
|
||||
let info = std::fs::read_to_string(app.join("Contents/Info.plist")).unwrap();
|
||||
assert!(!info.contains('@'), "an unfilled placeholder: {info}");
|
||||
let pairs = plist(&info);
|
||||
let get = |k: &str| {
|
||||
pairs
|
||||
.iter()
|
||||
.find(|(key, _)| key == k)
|
||||
.unwrap_or_else(|| panic!("{k} is missing from Info.plist"))
|
||||
.1
|
||||
.clone()
|
||||
};
|
||||
assert_eq!(get("CFBundleIdentifier"), "ai.wanderbooks.app");
|
||||
assert_eq!(get("CFBundleName"), "Wanderbooks");
|
||||
assert_eq!(get("CFBundleDisplayName"), "Wanderbooks");
|
||||
assert_eq!(get("CFBundleExecutable"), "wanderbooks");
|
||||
assert_eq!(get("CFBundleShortVersionString"), version);
|
||||
assert_eq!(get("CFBundleVersion"), version);
|
||||
assert_eq!(get("CFBundlePackageType"), "APPL");
|
||||
assert_eq!(get("LSMinimumSystemVersion"), "11.0");
|
||||
assert_eq!(get("LSMultipleInstancesProhibited"), "<true/>");
|
||||
assert!(get("NSDocumentsFolderUsageDescription").contains("Documents"));
|
||||
drop(cleanup);
|
||||
}
|
||||
|
||||
/// Removes a folder when dropped (a test's own scratch under `target/`).
|
||||
struct Cleanup(PathBuf);
|
||||
impl Drop for Cleanup {
|
||||
fn drop(&mut self) {
|
||||
let _ = std::fs::remove_dir_all(&self.0);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_entitlements_are_empty_on_purpose_and_say_why() {
|
||||
let text = read("deploy/packaging/macos/entitlements.plist");
|
||||
assert!(
|
||||
code(&text).contains(&"<dict/>"),
|
||||
"no entitlement is claimed without a reason"
|
||||
);
|
||||
assert!(text.contains("hardened runtime"));
|
||||
assert!(text.contains("NOT sandboxed"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_macos_script_signs_only_with_an_identity_and_names_no_secret() {
|
||||
let script = read("deploy/packaging/macos/build-macos.sh");
|
||||
// Secrets come from the environment, by name; none is written here.
|
||||
for name in [
|
||||
"WB_SIGN_IDENTITY",
|
||||
"WB_NOTARY_APPLE_ID",
|
||||
"WB_NOTARY_TEAM_ID",
|
||||
"WB_NOTARY_PASSWORD",
|
||||
] {
|
||||
assert!(script.contains(name), "{name}");
|
||||
}
|
||||
assert!(script.contains("--options runtime"), "the hardened runtime");
|
||||
assert!(script.contains("entitlements.plist"));
|
||||
assert!(script.contains("notarytool submit"));
|
||||
assert!(script.contains("stapler staple"));
|
||||
assert!(script.contains("lipo -create"), "universal");
|
||||
for line in code(&script) {
|
||||
assert!(
|
||||
!line.contains("password=") || line.contains("$("),
|
||||
"a literal password: {line}"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// ---- Linux ----------------------------------------------------------------------
|
||||
|
||||
/// The `Key=Value` lines of a desktop entry.
|
||||
fn desktop(text: &str) -> Vec<(String, String)> {
|
||||
text.lines()
|
||||
.filter_map(|l| l.split_once('='))
|
||||
.map(|(k, v)| (k.to_string(), v.to_string()))
|
||||
.collect()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_desktop_entries_launch_plain_wanderbooks_with_the_icon_and_the_window_id() {
|
||||
// The id the window announces, which the launcher matches (Wayland, and
|
||||
// X11's WM class).
|
||||
let gui = read("crates/ledger-gui/src/lib.rs");
|
||||
assert!(gui.contains(r#".with_app_id("wanderbooks")"#));
|
||||
for file in [
|
||||
"deploy/packaging/wanderbooks-static.desktop",
|
||||
"deploy/packaging/wanderbooks.desktop",
|
||||
] {
|
||||
let entries = desktop(&read(file));
|
||||
let get = |k: &str| {
|
||||
entries
|
||||
.iter()
|
||||
.find(|(key, _)| key == k)
|
||||
.unwrap_or_else(|| panic!("{file}: {k} is missing"))
|
||||
.1
|
||||
.clone()
|
||||
};
|
||||
assert_eq!(get("Type"), "Application", "{file}");
|
||||
assert_eq!(get("Terminal"), "false", "{file}");
|
||||
assert_eq!(get("StartupWMClass"), "wanderbooks", "{file}");
|
||||
let categories = get("Categories");
|
||||
assert!(
|
||||
categories.starts_with("{{") || categories.ends_with(';'),
|
||||
"{file}: {categories}"
|
||||
);
|
||||
// An AppImage's launcher appends what it is given to the Exec line:
|
||||
// it names the program and nothing else.
|
||||
let exec = get("Exec");
|
||||
assert!(
|
||||
exec == "wanderbooks" || exec == "{{exec}}",
|
||||
"{file}: {exec}"
|
||||
);
|
||||
let name = get("Name");
|
||||
assert!(
|
||||
name == "Wanderbooks" || name == "{{name}}",
|
||||
"{file}: {name}"
|
||||
);
|
||||
let icon = get("Icon");
|
||||
assert!(
|
||||
icon == "wanderbooks" || icon == "{{icon}}",
|
||||
"{file}: {icon}"
|
||||
);
|
||||
}
|
||||
// The static entry (the .rpm's) is a valid desktop file.
|
||||
if let Some(tool) = std::env::var_os("PATH").and_then(|p| {
|
||||
std::env::split_paths(&p)
|
||||
.map(|d| d.join("desktop-file-validate"))
|
||||
.find(|f| f.is_file())
|
||||
}) {
|
||||
let out = Command::new(tool)
|
||||
.arg(root().join("deploy/packaging/wanderbooks-static.desktop"))
|
||||
.output()
|
||||
.unwrap();
|
||||
assert!(
|
||||
out.status.success(),
|
||||
"{}",
|
||||
String::from_utf8_lossy(&out.stdout)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// WB-pkg-7: every package carries the licences, and the Linux packages
|
||||
/// install the icon their desktop entry names.
|
||||
#[test]
|
||||
fn every_package_carries_the_licences_and_the_icon() {
|
||||
let deb_pacman = read("deploy/packaging/packager.toml");
|
||||
let rpm = read("crates/ledger-cli/Cargo.toml");
|
||||
let rpm_script = read("deploy/packaging/build-linux.sh");
|
||||
let windows = read("deploy/packaging/windows/wanderbooks.nsi");
|
||||
let mac = read("deploy/packaging/macos/build-macos.sh");
|
||||
for file in LICENCE_FILES {
|
||||
assert!(
|
||||
deb_pacman.contains(&format!("\"{file}\" = ")),
|
||||
"deb or pacman lacks {file}"
|
||||
);
|
||||
assert_eq!(
|
||||
deb_pacman.matches(&format!("\"{file}\" = ")).count(),
|
||||
2,
|
||||
"both the deb and the pacman package carry {file}"
|
||||
);
|
||||
assert!(
|
||||
rpm.contains(&format!("source = \"{file}\"")),
|
||||
"rpm lacks {file}"
|
||||
);
|
||||
assert!(
|
||||
rpm_script.contains(&format!("source = \"{file}\"")),
|
||||
"rpm script lacks {file}"
|
||||
);
|
||||
assert!(
|
||||
windows.contains(&format!("/oname={file}")),
|
||||
"windows lacks {file}"
|
||||
);
|
||||
assert!(mac.contains(file), "macos lacks {file}");
|
||||
}
|
||||
assert!(rpm.contains("512x512/apps/wanderbooks.png"));
|
||||
assert!(rpm_script.contains("512x512/apps/wanderbooks.png"));
|
||||
for file in LICENCE_FILES {
|
||||
assert!(
|
||||
root().join(file).is_file(),
|
||||
"{file} is not in the repository"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn no_package_runs_a_script_that_could_touch_the_books() {
|
||||
let packager = read("deploy/packaging/packager.toml");
|
||||
for key in [
|
||||
"postrm",
|
||||
"post-remove",
|
||||
"before-remove",
|
||||
"preinst",
|
||||
"postinst",
|
||||
"after-install",
|
||||
"scripts",
|
||||
] {
|
||||
assert!(!packager.contains(key), "{key} in packager.toml");
|
||||
}
|
||||
let rpm = read("crates/ledger-cli/Cargo.toml");
|
||||
for key in [
|
||||
"post_uninstall",
|
||||
"pre_uninstall",
|
||||
"post_install_script",
|
||||
"pre_install_script",
|
||||
] {
|
||||
assert!(!rpm.contains(key), "{key} in Cargo.toml");
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<!-- Merged by cargo-packager into the Info.plist it generates for the
|
||||
.app (P11a step 6): the keys the generated one lacks. -->
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>LSMultipleInstancesProhibited</key>
|
||||
<true/>
|
||||
<key>NSSupportsAutomaticGraphicsSwitching</key>
|
||||
<true/>
|
||||
</dict>
|
||||
</plist>
|
||||
@@ -37,6 +37,7 @@ sed "s/^version = \".*\"/version = \"$version\"/
|
||||
s#\"target/release\"#\"$PWD/$stage\"#
|
||||
s#\"deploy/packaging/#\"$PWD/deploy/packaging/#
|
||||
s#\"LICENSE-MIT\"#\"$PWD/LICENSE-MIT\"#
|
||||
s#^\"LICENSE-APACHE\"#\"$PWD/LICENSE-APACHE\"#
|
||||
s#^\"THIRD-PARTY-NOTICES.txt\"#\"$PWD/THIRD-PARTY-NOTICES.txt\"#" \
|
||||
deploy/packaging/packager.toml >"$config"
|
||||
# The AppImage tools are themselves AppImages; run them without FUSE.
|
||||
@@ -46,6 +47,9 @@ assets='assets = [
|
||||
{ source = "'$PWD/$stage'/wanderbooks", dest = "/usr/bin/wanderbooks", mode = "0755" },
|
||||
{ source = "deploy/packaging/install-method-rpm", dest = "/usr/share/wanderbooks/install-method", mode = "0644" },
|
||||
{ source = "deploy/packaging/wanderbooks-static.desktop", dest = "/usr/share/applications/wanderbooks.desktop", mode = "0644" },
|
||||
{ source = "deploy/packaging/icons/512x512.png", dest = "/usr/share/icons/hicolor/512x512/apps/wanderbooks.png", mode = "0644" },
|
||||
{ source = "LICENSE-MIT", dest = "/usr/share/doc/wanderbooks/LICENSE-MIT", mode = "0644" },
|
||||
{ source = "LICENSE-APACHE", dest = "/usr/share/doc/wanderbooks/LICENSE-APACHE", mode = "0644" },
|
||||
{ source = "THIRD-PARTY-NOTICES.txt", dest = "/usr/share/doc/wanderbooks/THIRD-PARTY-NOTICES.txt", mode = "0644" },
|
||||
]'
|
||||
cargo generate-rpm -p crates/ledger-cli --set-metadata "version=\"$version\"" --set-metadata "$assets" -o "$out/"
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# The macOS bundle (P11a step 6), UNSIGNED, from the release program
|
||||
# already built at target/release/wanderbooks (`cargo build --release -p
|
||||
# ledger-cli`). Run on a Mac from the repository root:
|
||||
#
|
||||
# build-macos.sh [VERSION]
|
||||
#
|
||||
# Puts Wanderbooks_VERSION_<arch>.dmg into target/packages/VERSION/. It
|
||||
# is not signed or notarized (step 5): Gatekeeper refuses it on a Mac
|
||||
# that downloaded it, and the owner opens it with right-click > Open.
|
||||
# Portable shell: macOS has BSD sed and no GNU mktemp options.
|
||||
set -euo pipefail
|
||||
own=$(sed -n 's/^version = "\(.*\)"/\1/p' crates/ledger-cli/Cargo.toml | head -n1)
|
||||
version=${1:-$own}
|
||||
out="target/packages/$version"
|
||||
program=${WB_PROGRAM:-target/release/wanderbooks}
|
||||
test -x "$program" || { echo "build the release program first: cargo build --release -p ledger-cli" >&2; exit 1; }
|
||||
rm -rf "$out"; mkdir -p "$out"
|
||||
stage="target/packages/.stage-$version"
|
||||
rm -rf "$stage"; mkdir -p "$stage"
|
||||
cp "$program" "$stage/wanderbooks"
|
||||
config="$stage/packager.toml"
|
||||
# cargo-packager reads paths relative to the config file, which is in the
|
||||
# stage folder here, so they are made absolute.
|
||||
sed -e "s/^version = \".*\"/version = \"$version\"/" \
|
||||
-e "s#^out-dir = .*#out-dir = \"$PWD/$out\"#" \
|
||||
-e "s#\"target/release\"#\"$PWD/$stage\"#" \
|
||||
-e "s#\"deploy/packaging/#\"$PWD/deploy/packaging/#" \
|
||||
-e "s#\"LICENSE-MIT\"#\"$PWD/LICENSE-MIT\"#" \
|
||||
deploy/packaging/packager-macos.toml >"$config"
|
||||
cargo packager --config "$config" --formats dmg --release
|
||||
rm -rf "$stage"
|
||||
ls -l "$out"
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 361 KiB |
@@ -0,0 +1,48 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<!-- The Info.plist of Wanderbooks.app (plan P15 unit C1; WB-pkg-1, WB-pkg-6).
|
||||
build-macos.sh replaces @VERSION@ with the program's version
|
||||
(deploy/packaging/version.sh) and @BUNDLE_ID@ with the bundle
|
||||
identifier. -->
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>CFBundleName</key>
|
||||
<string>Wanderbooks</string>
|
||||
<key>CFBundleDisplayName</key>
|
||||
<string>Wanderbooks</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>@BUNDLE_ID@</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>wanderbooks</string>
|
||||
<key>CFBundleIconFile</key>
|
||||
<string>wanderbooks</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>APPL</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>@VERSION@</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>@VERSION@</string>
|
||||
<key>LSMinimumSystemVersion</key>
|
||||
<string>11.0</string>
|
||||
<key>LSApplicationCategoryType</key>
|
||||
<string>public.app-category.finance</string>
|
||||
<key>NSHighResolutionCapable</key>
|
||||
<true/>
|
||||
<!-- One Wanderbooks at a time: it holds the books open. -->
|
||||
<key>LSMultipleInstancesProhibited</key>
|
||||
<true/>
|
||||
<!-- The discrete GPU is not woken for a ledger. -->
|
||||
<key>NSSupportsAutomaticGraphicsSwitching</key>
|
||||
<true/>
|
||||
<key>NSHumanReadableCopyright</key>
|
||||
<string>MIT OR Apache-2.0</string>
|
||||
<!-- macOS asks the person once before an app reads their Documents folder,
|
||||
and shows this sentence. Wanderbooks makes a folder there for each
|
||||
company's assistant (Documents/Wanderbooks) and for the Claude
|
||||
extension; it never reads anything else of theirs there. -->
|
||||
<key>NSDocumentsFolderUsageDescription</key>
|
||||
<string>Wanderbooks keeps a small folder in Documents for each company, where an assistant such as Claude Code works, and the extension file for the Claude app.</string>
|
||||
</dict>
|
||||
</plist>
|
||||
Executable
+143
@@ -0,0 +1,143 @@
|
||||
#!/usr/bin/env bash
|
||||
# The macOS app and its .dmg (plan P15 unit C1; WB-pkg-1). Run on a Mac from
|
||||
# the repository root (CI: the `macos` job of .github/workflows/release.yml):
|
||||
#
|
||||
# build-macos.sh [VERSION]
|
||||
#
|
||||
# Puts Wanderbooks-VERSION-macos-universal.dmg into target/packages/VERSION/.
|
||||
#
|
||||
# One UNIVERSAL program (Apple silicon and Intel in one file, `lipo`ed from
|
||||
# the two release builds): one download for everyone. The program is
|
||||
# WB_PROGRAM if set (any program file), else the lipo of
|
||||
# target/aarch64-apple-darwin/release/wanderbooks and
|
||||
# target/x86_64-apple-darwin/release/wanderbooks.
|
||||
#
|
||||
# Signing and notarization need the owner's Apple Developer identity and run
|
||||
# only when it is given, in the environment (the release workflow sets these
|
||||
# from secrets; nothing here is a secret and nothing prints one):
|
||||
# WB_SIGN_IDENTITY the signing identity, e.g.
|
||||
# "Developer ID Application: Name (TEAMID)", already in
|
||||
# the keychain (import-certificate.sh does that in CI)
|
||||
# WB_NOTARY_APPLE_ID, WB_NOTARY_TEAM_ID, WB_NOTARY_PASSWORD
|
||||
# for `xcrun notarytool` (an app-specific password)
|
||||
# Without WB_SIGN_IDENTITY the app is signed ad hoc ("-"): Apple silicon
|
||||
# will not start an unsigned program at all, so it runs, but Gatekeeper
|
||||
# still refuses a download of it (right-click > Open once, docs/install.md).
|
||||
# Without the notarization variables the .dmg is signed but not notarized.
|
||||
#
|
||||
# WB_NO_ICNS=1 skips the icon (no `iconutil` off a Mac): the structure
|
||||
# tests build the bundle that way on Linux; a release never does.
|
||||
# WB_BUNDLE_ONLY=1 stops after the .app (the structure tests).
|
||||
set -euo pipefail
|
||||
|
||||
here=$(CDPATH='' cd -- "$(dirname -- "$0")" && pwd)
|
||||
root=$(CDPATH='' cd -- "$here/../../.." && pwd)
|
||||
cd "$root"
|
||||
fail() { echo "build-macos: $*" >&2; exit 1; }
|
||||
notice() { echo "::notice title=$1::$2"; echo "build-macos: $2"; }
|
||||
|
||||
own=$(sh deploy/packaging/version.sh)
|
||||
version=${1:-$own}
|
||||
case "$version" in
|
||||
[0-9]*.[0-9]*.[0-9]*) ;;
|
||||
*) fail "'$version' is not an x.y.z version" ;;
|
||||
esac
|
||||
bundle_id=${WB_BUNDLE_ID:-ai.wanderbooks.app}
|
||||
out="target/packages/$version"
|
||||
stage="target/packages/.stage-macos-$version"
|
||||
app="$stage/Wanderbooks.app"
|
||||
dmg="Wanderbooks-$version-macos-universal.dmg"
|
||||
|
||||
for f in LICENSE-MIT LICENSE-APACHE THIRD-PARTY-NOTICES.txt deploy/packaging/icons/512x512.png \
|
||||
deploy/packaging/macos/Info.plist.in deploy/packaging/macos/entitlements.plist; do
|
||||
test -f "$f" || fail "$f is missing from the repository"
|
||||
done
|
||||
|
||||
# 1. The program: universal, or the one given.
|
||||
rm -rf "${stage:?}"
|
||||
mkdir -p "$stage" "$out"
|
||||
program=${WB_PROGRAM:-}
|
||||
if [ -z "$program" ]; then
|
||||
arm=target/aarch64-apple-darwin/release/wanderbooks
|
||||
intel=target/x86_64-apple-darwin/release/wanderbooks
|
||||
test -f "$arm" || fail "$arm is missing: cargo build --release -p ledger-cli --target aarch64-apple-darwin"
|
||||
test -f "$intel" || fail "$intel is missing: cargo build --release -p ledger-cli --target x86_64-apple-darwin"
|
||||
lipo -create -output "$stage/wanderbooks-universal" "$arm" "$intel"
|
||||
archs=$(lipo -archs "$stage/wanderbooks-universal")
|
||||
case "$archs" in
|
||||
*arm64*x86_64*|*x86_64*arm64*) ;;
|
||||
*) fail "the universal program holds '$archs', not both arm64 and x86_64" ;;
|
||||
esac
|
||||
program="$stage/wanderbooks-universal"
|
||||
fi
|
||||
test -f "$program" || fail "the program is not at $program"
|
||||
|
||||
# 2. The bundle. The program's path inside it,
|
||||
# /Applications/Wanderbooks.app/Contents/MacOS/wanderbooks, is the one an
|
||||
# assistant is registered with: it does not change when the app is
|
||||
# replaced by a newer one dragged over it.
|
||||
mkdir -p "$app/Contents/MacOS" "$app/Contents/Resources"
|
||||
cp "$program" "$app/Contents/MacOS/wanderbooks"
|
||||
chmod 755 "$app/Contents/MacOS/wanderbooks"
|
||||
sed -e "s/@VERSION@/$version/g" -e "s/@BUNDLE_ID@/$bundle_id/g" \
|
||||
deploy/packaging/macos/Info.plist.in > "$app/Contents/Info.plist"
|
||||
printf 'APPL????' > "$app/Contents/PkgInfo"
|
||||
cp LICENSE-MIT LICENSE-APACHE THIRD-PARTY-NOTICES.txt "$app/Contents/Resources/"
|
||||
if [ "${WB_NO_ICNS:-}" = 1 ]; then
|
||||
notice "no icon" "WB_NO_ICNS=1: the bundle has no icon (a test build, never a release)"
|
||||
else
|
||||
command -v iconutil >/dev/null || fail "iconutil is not here: build the icon on a Mac, or set WB_NO_ICNS=1 for a test bundle"
|
||||
iconset="$stage/wanderbooks.iconset"
|
||||
mkdir -p "$iconset"
|
||||
src=deploy/packaging/icons/512x512.png
|
||||
for size in 16 32 128 256 512; do
|
||||
sips -z "$size" "$size" "$src" --out "$iconset/icon_${size}x${size}.png" >/dev/null
|
||||
done
|
||||
for size in 16 32 128 256; do
|
||||
double=$((size * 2))
|
||||
sips -z "$double" "$double" "$src" --out "$iconset/icon_${size}x${size}@2x.png" >/dev/null
|
||||
done
|
||||
iconutil -c icns "$iconset" -o "$app/Contents/Resources/wanderbooks.icns"
|
||||
fi
|
||||
if [ "${WB_BUNDLE_ONLY:-}" = 1 ]; then
|
||||
echo "build-macos: bundle at $app (WB_BUNDLE_ONLY=1)"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# 3. Sign: hardened runtime, the entitlements, a secure timestamp.
|
||||
identity=${WB_SIGN_IDENTITY:-}
|
||||
if [ -z "$identity" ]; then
|
||||
notice "macOS signing skipped" "no WB_SIGN_IDENTITY: the app is signed ad hoc, so it runs here, but macOS Gatekeeper will refuse a download of it until it is signed with a Developer ID and notarized"
|
||||
identity=-
|
||||
timestamp=--timestamp=none
|
||||
else
|
||||
timestamp=--timestamp
|
||||
fi
|
||||
codesign --force --options runtime "$timestamp" \
|
||||
--entitlements deploy/packaging/macos/entitlements.plist \
|
||||
--sign "$identity" "$app"
|
||||
codesign --verify --deep --strict --verbose=2 "$app"
|
||||
|
||||
# 4. The .dmg: the app and a shortcut to Applications (drag to install).
|
||||
mkdir -p "$stage/dmg"
|
||||
cp -R "$app" "$stage/dmg/"
|
||||
ln -s /Applications "$stage/dmg/Applications"
|
||||
rm -f "${out:?}/${dmg:?}"
|
||||
hdiutil create -volname "Wanderbooks" -srcfolder "$stage/dmg" -ov -format UDZO "$out/$dmg"
|
||||
if [ "$identity" != "-" ]; then
|
||||
codesign --force --timestamp --sign "$identity" "$out/$dmg"
|
||||
fi
|
||||
|
||||
# 5. Notarize and staple (the Developer ID signature and Apple's ticket).
|
||||
if [ "$identity" != "-" ] && [ -n "${WB_NOTARY_APPLE_ID:-}" ] && [ -n "${WB_NOTARY_TEAM_ID:-}" ] && [ -n "${WB_NOTARY_PASSWORD:-}" ]; then
|
||||
xcrun notarytool submit "$out/$dmg" \
|
||||
--apple-id "$WB_NOTARY_APPLE_ID" --team-id "$WB_NOTARY_TEAM_ID" \
|
||||
--password "$WB_NOTARY_PASSWORD" --wait
|
||||
xcrun stapler staple "$out/$dmg"
|
||||
xcrun stapler validate "$out/$dmg"
|
||||
spctl --assess --type open --context context:primary-signature --verbose=2 "$out/$dmg"
|
||||
else
|
||||
notice "macOS notarization skipped" "no signing identity or no WB_NOTARY_APPLE_ID / WB_NOTARY_TEAM_ID / WB_NOTARY_PASSWORD: the .dmg is not notarized, and macOS will warn on the first open"
|
||||
fi
|
||||
rm -rf "${stage:?}"
|
||||
ls -l "$out"
|
||||
@@ -0,0 +1,29 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<!-- The hardened-runtime entitlements of Wanderbooks.app (plan P15 unit C1).
|
||||
|
||||
The app is signed with the hardened runtime (codesign --options
|
||||
runtime), which Apple's notarization requires. It is NOT sandboxed
|
||||
(the App Sandbox would forbid what the product is: it starts a copy of
|
||||
itself as the books server, runs the system's git for backups, and
|
||||
reads and writes the person's data folder and the folders they pick
|
||||
for backups). Outside the sandbox, none of that needs an entitlement:
|
||||
|
||||
* starting itself as a child process and git as another: none;
|
||||
* outgoing network connections (the relay, the update look, a git
|
||||
remote): none (com.apple.security.network.client is a SANDBOX
|
||||
entitlement);
|
||||
* reading and writing its data folder, Application Support/wanderbooks:
|
||||
none (the Documents folder is a privacy prompt, answered by
|
||||
NSDocumentsFolderUsageDescription in Info.plist, not an entitlement);
|
||||
* the window's graphics (Metal through wgpu): none;
|
||||
* no JIT, no unsigned executable memory, no DYLD variables, no
|
||||
library validation exception: the program loads only system
|
||||
frameworks and its own code.
|
||||
|
||||
So the set below is empty on purpose. If the first notarized build
|
||||
fails to start, the log names the entitlement it needs; add exactly
|
||||
that one here, with the reason, and not a broader exception. -->
|
||||
<plist version="1.0">
|
||||
<dict/>
|
||||
</plist>
|
||||
Executable
+24
@@ -0,0 +1,24 @@
|
||||
#!/usr/bin/env bash
|
||||
# Put the owner's Developer ID certificate into a temporary keychain on a CI
|
||||
# macOS runner, so `codesign` can use it (plan P15 unit C1). Run by the
|
||||
# release workflow only when the secrets exist. Takes the certificate (a .p12,
|
||||
# base64) and its password from the environment, never the command line:
|
||||
# APPLE_CERTIFICATE_P12_BASE64, APPLE_CERTIFICATE_PASSWORD
|
||||
# Prints no secret. The keychain lives in RUNNER_TEMP and goes with the
|
||||
# runner.
|
||||
set -euo pipefail
|
||||
: "${APPLE_CERTIFICATE_P12_BASE64:?the certificate secret is empty}"
|
||||
: "${APPLE_CERTIFICATE_PASSWORD:?the certificate password secret is empty}"
|
||||
: "${RUNNER_TEMP:?not on a GitHub runner}"
|
||||
keychain="$RUNNER_TEMP/wanderbooks-signing.keychain-db"
|
||||
password=$(uuidgen)
|
||||
p12="$RUNNER_TEMP/wanderbooks-signing.p12"
|
||||
printf '%s' "$APPLE_CERTIFICATE_P12_BASE64" | base64 --decode > "$p12"
|
||||
security create-keychain -p "$password" "$keychain"
|
||||
security set-keychain-settings -lut 21600 "$keychain"
|
||||
security unlock-keychain -p "$password" "$keychain"
|
||||
security import "$p12" -k "$keychain" -P "$APPLE_CERTIFICATE_PASSWORD" -T /usr/bin/codesign
|
||||
security set-key-partition-list -S apple-tool:,apple: -s -k "$password" "$keychain" >/dev/null
|
||||
security list-keychains -d user -s "$keychain" login.keychain
|
||||
rm -f "$p12"
|
||||
security find-identity -v -p codesigning "$keychain"
|
||||
@@ -1,36 +0,0 @@
|
||||
# cargo-packager's description of the macOS bundle (P11a step 6; D-24,
|
||||
# D-25): the .app and its .dmg, UNSIGNED. `deploy/packaging/build-macos.sh`
|
||||
# runs it on a Mac (CI: the `macos` job of .github/workflows/release.yml).
|
||||
# Developer ID signing and notarization are step 5 (the owner's Apple
|
||||
# certificate, Q-4): they add `signing-identity` under [macos] and the
|
||||
# certificate and notarization credentials as CI secrets.
|
||||
# Paths are relative to this file's copy that build-macos.sh writes.
|
||||
name = "wanderbooks"
|
||||
product-name = "Wanderbooks"
|
||||
version = "0.1.0"
|
||||
identifier = "ai.wanderbooks.app"
|
||||
description = "Double-entry bookkeeping your agent keeps and you can read."
|
||||
homepage = "https://wanderbooks.ai"
|
||||
authors = ["Stephen Waits"]
|
||||
license-file = "LICENSE-MIT"
|
||||
category = "Finance"
|
||||
binaries-dir = "target/release"
|
||||
out-dir = "target/packages"
|
||||
# A png is made into the .icns (cargo-packager does it); the 512 px
|
||||
# placeholder is the owner's to replace.
|
||||
icons = ["deploy/packaging/icons/512x512.png"]
|
||||
formats = ["dmg"]
|
||||
binaries = [{ path = "wanderbooks", main = true }]
|
||||
|
||||
[macos]
|
||||
# The oldest macOS Rust's tier-1 aarch64-apple-darwin and x86-64 targets
|
||||
# run on; eframe's wgpu/Metal path needs 10.15 at least.
|
||||
minimum-system-version = "11.0"
|
||||
# Keys merged into the generated Info.plist: one viewer at a time, and the
|
||||
# discrete GPU is not woken for a ledger.
|
||||
info-plist-path = "deploy/packaging/Info.plist"
|
||||
|
||||
[dmg]
|
||||
window-size = { width = 540, height = 380 }
|
||||
app-position = { x = 140, y = 180 }
|
||||
application-folder-position = { x = 400, y = 180 }
|
||||
@@ -31,6 +31,8 @@ depends = ["libc6", "libgcc-s1"]
|
||||
# The notices the third-party licences ask to travel with the program
|
||||
# (`just notices`); `wanderbooks licenses` prints the same text.
|
||||
"THIRD-PARTY-NOTICES.txt" = "usr/share/doc/wanderbooks/THIRD-PARTY-NOTICES.txt"
|
||||
"LICENSE-MIT" = "usr/share/doc/wanderbooks/LICENSE-MIT"
|
||||
"LICENSE-APACHE" = "usr/share/doc/wanderbooks/LICENSE-APACHE"
|
||||
|
||||
[pacman]
|
||||
depends = ["gcc-libs", "glibc"]
|
||||
@@ -38,3 +40,5 @@ depends = ["gcc-libs", "glibc"]
|
||||
[pacman.files]
|
||||
"deploy/packaging/install-method-aur" = "usr/share/wanderbooks/install-method"
|
||||
"THIRD-PARTY-NOTICES.txt" = "usr/share/doc/wanderbooks/THIRD-PARTY-NOTICES.txt"
|
||||
"LICENSE-MIT" = "usr/share/doc/wanderbooks/LICENSE-MIT"
|
||||
"LICENSE-APACHE" = "usr/share/doc/wanderbooks/LICENSE-APACHE"
|
||||
Executable
+21
@@ -0,0 +1,21 @@
|
||||
#!/bin/sh
|
||||
# The program's version: the one place it is written is `version = "..."`
|
||||
# in crates/ledger-cli/Cargo.toml (plan P15 C1, WB-pkg-6). Every package, the
|
||||
# release workflow and the installer take it from here; the program itself
|
||||
# reports the same file's version through `CARGO_PKG_VERSION`.
|
||||
#
|
||||
# deploy/packaging/version.sh prints 0.1.0
|
||||
#
|
||||
# A version that is not three plain numbers is refused: the Windows
|
||||
# installer's file-version fields and the macOS bundle's both need them.
|
||||
set -eu
|
||||
here=$(CDPATH='' cd -- "$(dirname -- "$0")" && pwd)
|
||||
version=$(sed -n 's/^version = "\(.*\)"/\1/p' "$here/../../crates/ledger-cli/Cargo.toml" | head -n1)
|
||||
case "$version" in
|
||||
[0-9]*.[0-9]*.[0-9]*) ;;
|
||||
*) echo "version.sh: no x.y.z version in crates/ledger-cli/Cargo.toml (found: '$version')" >&2; exit 1 ;;
|
||||
esac
|
||||
case "$version" in
|
||||
*[!0-9.]*) echo "version.sh: '$version' is not three plain numbers" >&2; exit 1 ;;
|
||||
esac
|
||||
printf '%s\n' "$version"
|
||||
@@ -1,7 +1,9 @@
|
||||
[Desktop Entry]
|
||||
Categories=Office;Finance;
|
||||
Type=Application
|
||||
Name=Wanderbooks
|
||||
Comment=Double-entry bookkeeping your agent keeps and you can read.
|
||||
Exec=wanderbooks
|
||||
Name=Wanderbooks
|
||||
Icon=wanderbooks
|
||||
Terminal=false
|
||||
Type=Application
|
||||
Categories=Office;Finance;
|
||||
StartupWMClass=wanderbooks
|
||||
@@ -8,3 +8,4 @@ Icon={{icon}}
|
||||
Name={{name}}
|
||||
Terminal=false
|
||||
Type=Application
|
||||
StartupWMClass=wanderbooks
|
||||
Executable
+63
@@ -0,0 +1,63 @@
|
||||
#!/usr/bin/env bash
|
||||
# The Windows installer (plan P15 unit C1), from the release program already
|
||||
# built at target/release/wanderbooks.exe (`cargo build --release -p
|
||||
# ledger-cli`). Run from the repository root, in Git Bash on Windows (CI:
|
||||
# the `windows` job of .github/workflows/release.yml) or anywhere makensis
|
||||
# is:
|
||||
#
|
||||
# build-windows.sh [VERSION]
|
||||
#
|
||||
# Puts Wanderbooks-VERSION-windows-x64-setup.exe into target/packages/VERSION/.
|
||||
# VERSION defaults to the program's own (deploy/packaging/version.sh).
|
||||
# WB_PROGRAM names another program file; WB_MAKENSIS another makensis.
|
||||
#
|
||||
# Unsigned: signing is a separate, optional step (sign-windows.ps1) that
|
||||
# runs when the release workflow has the certificate's secrets.
|
||||
set -euo pipefail
|
||||
|
||||
here=$(CDPATH='' cd -- "$(dirname -- "$0")" && pwd)
|
||||
root=$(CDPATH='' cd -- "$here/../../.." && pwd)
|
||||
cd "$root"
|
||||
own=$(sh deploy/packaging/version.sh)
|
||||
version=${1:-$own}
|
||||
case "$version" in
|
||||
[0-9]*.[0-9]*.[0-9]*) ;;
|
||||
*) echo "build-windows: '$version' is not an x.y.z version" >&2; exit 1 ;;
|
||||
esac
|
||||
program=${WB_PROGRAM:-target/release/wanderbooks.exe}
|
||||
out="target/packages/$version"
|
||||
installer="Wanderbooks-$version-windows-x64-setup.exe"
|
||||
|
||||
fail() { echo "build-windows: $*" >&2; exit 1; }
|
||||
test -f "$program" || fail "the release program is not at $program: run cargo build --release -p ledger-cli first"
|
||||
for f in LICENSE-MIT LICENSE-APACHE THIRD-PARTY-NOTICES.txt deploy/packaging/icons/wanderbooks.ico deploy/packaging/windows/wanderbooks.nsi; do
|
||||
test -f "$f" || fail "$f is missing from the repository"
|
||||
done
|
||||
|
||||
makensis=${WB_MAKENSIS:-}
|
||||
if [ -z "$makensis" ]; then
|
||||
if command -v makensis >/dev/null 2>&1; then
|
||||
makensis=makensis
|
||||
elif [ -x "/c/Program Files (x86)/NSIS/makensis.exe" ]; then
|
||||
makensis="/c/Program Files (x86)/NSIS/makensis.exe"
|
||||
else
|
||||
fail "makensis (NSIS) is not installed: choco install nsis, or apt install nsis"
|
||||
fi
|
||||
fi
|
||||
|
||||
# NSIS is a Windows program; Git Bash must neither rewrite its options
|
||||
# (-D...) nor hand it a Unix path, so paths are made native here.
|
||||
export MSYS2_ARG_CONV_EXCL='*'
|
||||
native() { if command -v cygpath >/dev/null 2>&1; then cygpath -w "$1"; else printf '%s\n' "$1"; fi; }
|
||||
|
||||
rm -rf "${out:?}"
|
||||
mkdir -p "$out"
|
||||
"$makensis" -V2 \
|
||||
"-DVERSION=$version" \
|
||||
"-DPROGRAM=$(native "$program")" \
|
||||
"-DICON=$(native deploy/packaging/icons/wanderbooks.ico)" \
|
||||
"-DLICENSES=$(native "$root")" \
|
||||
"-DOUTFILE=$(native "$out/$installer")" \
|
||||
"$(native deploy/packaging/windows/wanderbooks.nsi)"
|
||||
test -s "$out/$installer" || fail "makensis finished but $out/$installer is missing or empty"
|
||||
ls -l "$out"
|
||||
@@ -0,0 +1,36 @@
|
||||
# Sign Windows files with an Authenticode code-signing certificate (plan P15
|
||||
# unit C1). The release workflow runs this only when its secrets exist
|
||||
# (WINDOWS_CERTIFICATE_PFX_BASE64 and WINDOWS_CERTIFICATE_PASSWORD); with none
|
||||
# it prints a notice and the installer stays unsigned (SmartScreen warns).
|
||||
#
|
||||
# sign-windows.ps1 FILE [FILE...]
|
||||
#
|
||||
# The certificate is written to a temporary file for the signing and
|
||||
# removed. Nothing here prints a secret. A failure is loud: a signature that
|
||||
# was asked for and did not happen stops the release.
|
||||
param([Parameter(Mandatory = $true, ValueFromRemainingArguments = $true)][string[]]$Files)
|
||||
$ErrorActionPreference = 'Stop'
|
||||
|
||||
if (-not $env:WINDOWS_CERTIFICATE_PFX_BASE64 -or -not $env:WINDOWS_CERTIFICATE_PASSWORD) {
|
||||
Write-Host "::notice title=Windows signing skipped::no WINDOWS_CERTIFICATE_PFX_BASE64 / WINDOWS_CERTIFICATE_PASSWORD secret: the installer is unsigned and Windows SmartScreen will warn on the first run."
|
||||
exit 0
|
||||
}
|
||||
|
||||
$signtool = Get-ChildItem "${env:ProgramFiles(x86)}\Windows Kits\10\bin" -Recurse -Filter signtool.exe -ErrorAction SilentlyContinue |
|
||||
Where-Object { $_.FullName -match '\\x64\\' } |
|
||||
Sort-Object FullName -Descending | Select-Object -First 1
|
||||
if (-not $signtool) { throw "signtool.exe was not found in the Windows SDK on this runner" }
|
||||
|
||||
$pfx = Join-Path $env:RUNNER_TEMP 'wanderbooks-codesign.pfx'
|
||||
[IO.File]::WriteAllBytes($pfx, [Convert]::FromBase64String($env:WINDOWS_CERTIFICATE_PFX_BASE64))
|
||||
try {
|
||||
foreach ($file in $Files) {
|
||||
& $signtool.FullName sign /fd sha256 /f $pfx /p $env:WINDOWS_CERTIFICATE_PASSWORD /tr http://timestamp.digicert.com /td sha256 $file
|
||||
if ($LASTEXITCODE -ne 0) { throw "signtool failed on $file" }
|
||||
& $signtool.FullName verify /pa $file
|
||||
if ($LASTEXITCODE -ne 0) { throw "the signature on $file does not verify" }
|
||||
Write-Host "signed $file"
|
||||
}
|
||||
} finally {
|
||||
Remove-Item $pfx -Force -ErrorAction SilentlyContinue
|
||||
}
|
||||
@@ -0,0 +1,144 @@
|
||||
; The Wanderbooks installer for Windows (plan P15 unit C1; WB-pkg-1, WB-pkg-2,
|
||||
; WB-pkg-7). Built by deploy/packaging/windows/build-windows.sh with NSIS
|
||||
; (https://nsis.sourceforge.io, free software, zlib licence).
|
||||
;
|
||||
; makensis -DVERSION=0.1.0 -DPROGRAM=...\wanderbooks.exe -DICON=...\wanderbooks.ico ^
|
||||
; -DLICENSES=<folder> -DOUTFILE=...\Wanderbooks-0.1.0-windows-x64-setup.exe wanderbooks.nsi
|
||||
;
|
||||
; What it does, and the rules it keeps:
|
||||
; * Per user: RequestExecutionLevel user, so double-clicking it shows no
|
||||
; administrator prompt. Everything goes under the person's own profile
|
||||
; and HKEY_CURRENT_USER.
|
||||
; * One program file, wanderbooks.exe. It is the window, the books
|
||||
; server's child and the assistants' bridge; an assistant is registered
|
||||
; with this installed path, which an update keeps (the same folder, the
|
||||
; same file name, replaced in place).
|
||||
; * A Start Menu entry named Wanderbooks, with the icon, and an entry in
|
||||
; Settings > Apps (the uninstaller).
|
||||
; * The uninstaller removes the files this installer put in the install
|
||||
; folder, the Start Menu entry and its two registry keys. It NEVER
|
||||
; removes the person's books, keys, backups or settings: they live in
|
||||
; the data folder (%LOCALAPPDATA%\wanderbooks), which this script
|
||||
; names nowhere, and no command below deletes a folder's contents or
|
||||
; uses a wildcard (a test, crates/ledger-cli/tests/packaging.rs, reads
|
||||
; this file and fails if one appears).
|
||||
; * It asks the person to quit Wanderbooks fully before it replaces or
|
||||
; removes the program (a running program cannot be replaced).
|
||||
; * Unsigned until the owner has a code-signing certificate: Windows
|
||||
; SmartScreen says so on the first run (docs/install.md).
|
||||
|
||||
Unicode true
|
||||
SetCompressor /SOLID lzma
|
||||
!include "MUI2.nsh"
|
||||
!include "LogicLib.nsh"
|
||||
|
||||
!ifndef VERSION
|
||||
!error "pass -DVERSION=x.y.z (deploy/packaging/version.sh)"
|
||||
!endif
|
||||
!ifndef PROGRAM
|
||||
!error "pass -DPROGRAM=<path to wanderbooks.exe>"
|
||||
!endif
|
||||
!ifndef ICON
|
||||
!error "pass -DICON=<path to wanderbooks.ico>"
|
||||
!endif
|
||||
!ifndef LICENSES
|
||||
!error "pass -DLICENSES=<folder with LICENSE-MIT, LICENSE-APACHE and THIRD-PARTY-NOTICES.txt>"
|
||||
!endif
|
||||
!ifndef OUTFILE
|
||||
!error "pass -DOUTFILE=<the installer to write>"
|
||||
!endif
|
||||
|
||||
!define NAME "Wanderbooks"
|
||||
!define PUBLISHER "Wanderbooks"
|
||||
!define UNINSTALL_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\Wanderbooks"
|
||||
!define APP_KEY "Software\Wanderbooks"
|
||||
|
||||
Name "${NAME}"
|
||||
OutFile "${OUTFILE}"
|
||||
RequestExecutionLevel user
|
||||
InstallDir "$LOCALAPPDATA\Programs\Wanderbooks"
|
||||
InstallDirRegKey HKCU "${APP_KEY}" "InstallDir"
|
||||
BrandingText "${NAME} ${VERSION}"
|
||||
ShowInstDetails nevershow
|
||||
ShowUninstDetails nevershow
|
||||
|
||||
VIProductVersion "${VERSION}.0"
|
||||
VIAddVersionKey "ProductName" "${NAME}"
|
||||
VIAddVersionKey "FileDescription" "${NAME} installer"
|
||||
VIAddVersionKey "FileVersion" "${VERSION}"
|
||||
VIAddVersionKey "ProductVersion" "${VERSION}"
|
||||
VIAddVersionKey "LegalCopyright" "MIT OR Apache-2.0"
|
||||
|
||||
!define MUI_ICON "${ICON}"
|
||||
!define MUI_UNICON "${ICON}"
|
||||
!define MUI_ABORTWARNING
|
||||
!define MUI_FINISHPAGE_RUN "$INSTDIR\wanderbooks.exe"
|
||||
!define MUI_FINISHPAGE_RUN_TEXT "Start ${NAME}"
|
||||
|
||||
!insertmacro MUI_PAGE_INSTFILES
|
||||
!insertmacro MUI_PAGE_FINISH
|
||||
!insertmacro MUI_UNPAGE_CONFIRM
|
||||
!insertmacro MUI_UNPAGE_INSTFILES
|
||||
!insertmacro MUI_LANGUAGE "English"
|
||||
|
||||
; A program that is running cannot be replaced or removed. Try to open the
|
||||
; installed file for writing; if it is in use, ask the person to quit
|
||||
; Wanderbooks (its window, which closes the books and the server) and retry.
|
||||
!macro WaitUntilNotRunning
|
||||
${Do}
|
||||
ClearErrors
|
||||
${If} ${FileExists} "$INSTDIR\wanderbooks.exe"
|
||||
FileOpen $0 "$INSTDIR\wanderbooks.exe" a
|
||||
${IfNot} ${Errors}
|
||||
FileClose $0
|
||||
${Break}
|
||||
${EndIf}
|
||||
MessageBox MB_RETRYCANCEL|MB_ICONEXCLAMATION "${NAME} is open. Quit it fully (close its window), then choose Retry." IDRETRY +2
|
||||
Abort "${NAME} is still open."
|
||||
${Else}
|
||||
${Break}
|
||||
${EndIf}
|
||||
${Loop}
|
||||
!macroend
|
||||
|
||||
Section "Install"
|
||||
SetOutPath "$INSTDIR"
|
||||
!insertmacro WaitUntilNotRunning
|
||||
File "/oname=wanderbooks.exe" "${PROGRAM}"
|
||||
File "/oname=wanderbooks.ico" "${ICON}"
|
||||
File "/oname=LICENSE-MIT" "${LICENSES}\LICENSE-MIT"
|
||||
File "/oname=LICENSE-APACHE" "${LICENSES}\LICENSE-APACHE"
|
||||
File "/oname=THIRD-PARTY-NOTICES.txt" "${LICENSES}\THIRD-PARTY-NOTICES.txt"
|
||||
WriteUninstaller "$INSTDIR\Uninstall Wanderbooks.exe"
|
||||
|
||||
CreateShortCut "$SMPROGRAMS\${NAME}.lnk" "$INSTDIR\wanderbooks.exe" "" "$INSTDIR\wanderbooks.ico" 0
|
||||
|
||||
WriteRegStr HKCU "${APP_KEY}" "InstallDir" "$INSTDIR"
|
||||
WriteRegStr HKCU "${UNINSTALL_KEY}" "DisplayName" "${NAME}"
|
||||
WriteRegStr HKCU "${UNINSTALL_KEY}" "DisplayVersion" "${VERSION}"
|
||||
WriteRegStr HKCU "${UNINSTALL_KEY}" "Publisher" "${PUBLISHER}"
|
||||
WriteRegStr HKCU "${UNINSTALL_KEY}" "DisplayIcon" "$INSTDIR\wanderbooks.ico"
|
||||
WriteRegStr HKCU "${UNINSTALL_KEY}" "InstallLocation" "$INSTDIR"
|
||||
WriteRegStr HKCU "${UNINSTALL_KEY}" "URLInfoAbout" "https://wanderbooks.ai"
|
||||
WriteRegStr HKCU "${UNINSTALL_KEY}" "UninstallString" '"$INSTDIR\Uninstall Wanderbooks.exe"'
|
||||
WriteRegStr HKCU "${UNINSTALL_KEY}" "QuietUninstallString" '"$INSTDIR\Uninstall Wanderbooks.exe" /S'
|
||||
WriteRegDWORD HKCU "${UNINSTALL_KEY}" "NoModify" 1
|
||||
WriteRegDWORD HKCU "${UNINSTALL_KEY}" "NoRepair" 1
|
||||
SectionEnd
|
||||
|
||||
Section "Uninstall"
|
||||
!insertmacro WaitUntilNotRunning
|
||||
Delete "$INSTDIR\wanderbooks.exe"
|
||||
Delete "$INSTDIR\wanderbooks.ico"
|
||||
Delete "$INSTDIR\LICENSE-MIT"
|
||||
Delete "$INSTDIR\LICENSE-APACHE"
|
||||
Delete "$INSTDIR\THIRD-PARTY-NOTICES.txt"
|
||||
Delete "$INSTDIR\Uninstall Wanderbooks.exe"
|
||||
; Only if empty: a folder the person put something in stays.
|
||||
RMDir "$INSTDIR"
|
||||
Delete "$SMPROGRAMS\${NAME}.lnk"
|
||||
DeleteRegKey HKCU "${UNINSTALL_KEY}"
|
||||
DeleteRegKey HKCU "${APP_KEY}"
|
||||
; The person's books, keys, backups and settings are not here: they are
|
||||
; in the data folder, which an uninstall leaves exactly as it is.
|
||||
SectionEnd
|
||||
@@ -591,10 +591,23 @@ package-linux version="" formats="deb,appimage,pacman":
|
||||
cargo build --release -p ledger-cli
|
||||
deploy/packaging/build-linux.sh {{version}} {{formats}}
|
||||
|
||||
# Build the unsigned macOS .dmg (on a Mac; CI does it on a tag or dispatch)
|
||||
# The macOS app and its universal .dmg (on a Mac; CI does it on a tag or
|
||||
# dispatch). Signs and notarizes only with WB_SIGN_IDENTITY and WB_NOTARY_*
|
||||
# in the environment (deploy/packaging/macos/build-macos.sh says which).
|
||||
# Build the universal macOS .dmg
|
||||
package-macos version="":
|
||||
rustup target add aarch64-apple-darwin x86_64-apple-darwin
|
||||
cargo build --release -p ledger-cli --target aarch64-apple-darwin
|
||||
cargo build --release -p ledger-cli --target x86_64-apple-darwin
|
||||
deploy/packaging/macos/build-macos.sh {{version}}
|
||||
|
||||
# The per-user Windows installer (in Git Bash on Windows, with NSIS: choco
|
||||
# install nsis; CI does it on a tag or dispatch). Unsigned unless the
|
||||
# release workflow signs it.
|
||||
# Build the Windows installer
|
||||
package-windows version="":
|
||||
cargo build --release -p ledger-cli
|
||||
deploy/packaging/build-macos.sh {{version}}
|
||||
deploy/packaging/windows/build-windows.sh {{version}}
|
||||
|
||||
# A release folder on this machine signed with a throwaway key; then
|
||||
# `wanderbooks update --feed file://DIR/manifest.json --trusted-key DIR/release.pub`
|
||||
|
||||
Reference in new issue
Block a user