From ab0b943ba09693814fc52a4dd23a9d355c8f1ae1 Mon Sep 17 00:00:00 2001 From: LGUG2Z Date: Tue, 27 Oct 2026 06:14:04 -0700 Subject: [PATCH] build(wix): an installer for Windows An MSI for Windows built with WiX and `cargo wix`, for x86_64 and aarch64, attached to every release and, on tags, offered to winget. It is its own product: its upgrade code and the GUID of its PATH component are new, since reusing komorebi's would make the two installers upgrade and uninstall each other. WiX only runs on Windows, so `tests/packaging.rs` checks what a Mac can: every binary the crate builds is in the installer, and the installer is not komorebi's. --- .github/workflows/ci.yaml | 17 ++++ README.md | 13 ++- flake.nix | 4 +- komorebi-recorder/tests/packaging.rs | 140 +++++++++++++++++++++++++++ wix/License.rtf | Bin 0 -> 4525 bytes wix/main.wxs | 118 ++++++++++++++++++++++ 6 files changed, 290 insertions(+), 2 deletions(-) create mode 100644 komorebi-recorder/tests/packaging.rs create mode 100644 wix/License.rtf create mode 100644 wix/main.wxs diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 5f5b5249..d16d99ea 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -108,12 +108,17 @@ jobs: command: "build" target: ${{ matrix.platform.target }} args: "--locked --release" + - shell: pwsh + run: | + cargo install cargo-wix + cargo wix --no-build -p komorebi-recorder --nocapture -I .\wix\main.wxs --target ${{ matrix.platform.target }} - uses: actions/upload-artifact@v7 with: name: komorebi-recorder-${{ matrix.platform.target }}-${{ github.sha }} path: | target/${{ matrix.platform.target }}/release/*.exe target/${{ matrix.platform.target }}/release/*.pdb + target/wix/komorebi-recorder-*.msi retention-days: 14 # Packages what the two builds made and publishes it. What kind of publication depends on the @@ -153,8 +158,11 @@ jobs: zip -j "dist/komorebi-recorder-${VERSION}-aarch64-apple-darwin.zip" \ "komorebi-recorder-aarch64-apple-darwin-${GITHUB_SHA}/komorebi-recorder" for triple in x86_64-pc-windows-msvc aarch64-pc-windows-msvc; do + arch="${triple%%-*}" zip -j "dist/komorebi-recorder-${VERSION}-${triple}.zip" \ "komorebi-recorder-${triple}-${GITHUB_SHA}/${triple}/release/"*.exe + cp "komorebi-recorder-${triple}-${GITHUB_SHA}/wix/"*"-${arch}.msi" \ + "dist/komorebi-recorder-${VERSION}-${arch}.msi" done (cd dist && shasum -a 256 -- * > checksums.txt) - name: Write the release notes @@ -202,3 +210,12 @@ jobs: dist/* ;; esac + winget: + if: github.repository == 'LGUG2Z/komorebi-recorder' && startsWith(github.ref, 'refs/tags/v') + needs: publish + runs-on: ubuntu-latest + steps: + - uses: vedantmgoyal2009/winget-releaser@main + with: + identifier: LGUG2Z.komorebi-recorder + token: ${{ secrets.WINGET_TOKEN }} diff --git a/README.md b/README.md index 3fb80ff6..1d842d83 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,18 @@ and for an agent, with commands that print JSON. ## Install -There are no releases yet: build it from source, below. +Every release has, for macOS and for both architectures of Windows, a zip of the executables and, for Windows, an MSI +installer that puts them in `Program Files\komorebi-recorder\bin` and optionally on the `PATH`. The nightly release +is rebuilt every week from `master`. + +| | file | +|---|---| +| macOS (Apple silicon) | `komorebi-recorder--aarch64-apple-darwin.zip` | +| Windows x86_64 | `komorebi-recorder--x86_64.msi` or `komorebi-recorder--x86_64-pc-windows-msvc.zip` | +| Windows ARM64 | `komorebi-recorder--aarch64.msi` or `komorebi-recorder--aarch64-pc-windows-msvc.zip` | + +`checksums.txt` lists the SHA-256 of every file. The installers and executables are not signed, so Windows +SmartScreen and Defender may warn about them. ### From source diff --git a/flake.nix b/flake.nix index b677d619..131667b6 100644 --- a/flake.nix +++ b/flake.nix @@ -56,7 +56,9 @@ path: type: (craneLib.filterCargoSources path type) || (pkgs.lib.hasSuffix "/komorebi-recorder/src/guide.md" path) - || (pkgs.lib.hasInfix "/komorebi-recorder/tests/fixtures/" path); + || (pkgs.lib.hasInfix "/komorebi-recorder/tests/fixtures/" path) + # the installer, which `tests/packaging.rs` checks + || (pkgs.lib.hasInfix "/wix/" path); }; mkPackages = diff --git a/komorebi-recorder/tests/packaging.rs b/komorebi-recorder/tests/packaging.rs new file mode 100644 index 00000000..92c62c0c --- /dev/null +++ b/komorebi-recorder/tests/packaging.rs @@ -0,0 +1,140 @@ +//! The Windows installer (`wix/main.wxs`) has to ship every binary the crate builds and has to be +//! its own product: `WiX` itself only runs on Windows, so these checks are what a Mac or Linux +//! machine can say about the installer. + +use std::path::Path; +use std::path::PathBuf; + +/// komorebi's own installer: reusing its `UpgradeCode` would make the two products upgrade and +/// uninstall each other. +const KOMOREBI_UPGRADE_CODE: &str = "F8B967B5-7E7B-4E3A-895B-B789EC898B54"; + +/// komorebi's `PATH` component, which the installer tracks the `PATH` entry by. +const KOMOREBI_PATH_COMPONENT: &str = "6C6DF276-06C4-4675-BDED-48C5C2BC9BC5"; + +fn repository() -> PathBuf { + Path::new(env!("CARGO_MANIFEST_DIR")) + .parent() + .expect("the crate is a member of the workspace") + .to_path_buf() +} + +fn installer() -> String { + std::fs::read_to_string(repository().join("wix/main.wxs")).expect("wix/main.wxs") +} + +/// The value of attribute `name` on the first element of `tag` in the installer. +fn attribute(text: &str, tag: &str, name: &str) -> String { + let start = text + .find(&format!("<{tag} ")) + .unwrap_or_else(|| panic!("no <{tag}> in the installer")); + let element = &text[start..start + text[start..].find('>').expect("a closed tag")]; + let key = format!("{name}='"); + let value = element + .find(&key) + .unwrap_or_else(|| panic!("<{tag}> has no {name}")) + + key.len(); + element[value..][..element[value..].find('\'').expect("a closed value")].to_string() +} + +fn is_guid(text: &str) -> bool { + let parts: Vec<&str> = text.split('-').collect(); + parts.iter().map(|part| part.len()).collect::>() == [8, 4, 4, 4, 12] + && parts + .iter() + .all(|part| part.chars().all(|c| c.is_ascii_hexdigit())) +} + +/// The binaries cargo builds for this crate: the package's own (`src/main.rs`) and one for each +/// file in `src/bin`. +fn binaries() -> Vec { + let mut names = vec![env!("CARGO_PKG_NAME").to_string()]; + let bin = Path::new(env!("CARGO_MANIFEST_DIR")).join("src/bin"); + if let Ok(entries) = std::fs::read_dir(bin) { + for entry in entries { + let path = entry.expect("a directory entry").path(); + if path.extension().is_some_and(|extension| extension == "rs") { + names.push( + path.file_stem() + .expect("a file name") + .to_string_lossy() + .into_owned(), + ); + } + } + } + names.sort(); + names +} + +#[test] +fn every_binary_the_crate_builds_is_in_the_installer() { + let text = installer(); + for name in binaries() { + assert!( + text.contains(&format!("Name='{name}.exe'")), + "wix/main.wxs does not install {name}.exe" + ); + assert!( + text.contains(&format!("\\{name}.exe'")), + "wix/main.wxs does not take {name}.exe from the build directory" + ); + } +} + +#[test] +fn the_installer_installs_nothing_the_crate_does_not_build() { + let text = installer(); + let built = binaries(); + for piece in text.split("Name='").skip(1) { + let name = &piece[..piece.find('\'').expect("a closed value")]; + if let Some(binary) = name.strip_suffix(".exe") { + assert!( + built.iter().any(|built| built == binary), + "wix/main.wxs installs {name}, which this crate does not build" + ); + } + } +} + +#[test] +fn the_installer_is_its_own_product() { + let text = installer(); + + let upgrade_code = attribute(&text, "Product", "UpgradeCode"); + assert!( + is_guid(&upgrade_code), + "UpgradeCode is not a GUID: {upgrade_code}" + ); + assert!( + !upgrade_code.eq_ignore_ascii_case(KOMOREBI_UPGRADE_CODE), + "UpgradeCode is komorebi's: the two products would replace each other" + ); + assert_eq!(attribute(&text, "Product", "Name"), env!("CARGO_PKG_NAME")); + + assert!( + !text + .to_uppercase() + .contains(&KOMOREBI_PATH_COMPONENT.to_uppercase()), + "the PATH component has komorebi's GUID" + ); + let path_guid = attribute(&text, "Component Id='Path'", "Guid"); + assert!( + is_guid(&path_guid), + "the PATH component's Guid: {path_guid}" + ); +} + +#[test] +fn the_license_the_installer_shows_is_there_and_is_the_projects() { + let rtf = std::fs::read_to_string(repository().join("wix/License.rtf")).expect("License.rtf"); + assert!( + rtf.contains("Komorebi License"), + "not the project's license" + ); + assert!(rtf.contains("Version 2.0.0"), "not the project's license"); + assert!( + installer().contains("wix\\License.rtf"), + "main.wxs does not refer to wix\\License.rtf" + ); +} diff --git a/wix/License.rtf b/wix/License.rtf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