From ed712acdabf7aa2db28b5e7de2fc30e4995488ef Mon Sep 17 00:00:00 2001 From: skylartaylor Date: Wed, 25 Nov 2026 00:03:03 +0100 Subject: [PATCH] fix(nightly): one Linux launcher, a working tar step and persistent Flatpak state Batch 2A review fixes on top of 4279762e: - One launcher (packaging/linux/nightly-launcher.sh) serves the app-owned nightly tar, the deb/rpm wrapper, the AppImage AppRun, the Arch handoff and the Flatpak bundle. It passes an already-supplied --launch-profile (and --version/-V) straight through, so the ArtCraft Launcher's own profile root is honoured instead of being wrapped into file names, and it resolves its own folder (also when a shell finds it through PATH) rather than a relative path. - The profile moves to ${XDG_DATA_HOME:-$HOME/.local/share}/wordcraft-nightly, which persists inside the Flatpak sandbox; the sandbox home does not, so preferences, recovery and autosaves were lost on every exit. - package.sh's nightly tar step uses the tar's real member paths (no usr/), so the tar format no longer aborts and the Flatpak bundle can be built from it. - The app-owned tar uses the standard layout: `wordcraft` is the launcher and `wordcraft-bin` the GUI (was wordcraft.real). The archive allowlist and its tests follow, and nightly-build.yml's exact member check accepts the OFL-*.txt licences CRAFT_FONTS_DIR adds. - Windows: the print helper runs before prepare_launch(), so File > Print works in a Nightly build instead of hitting the launch-profile refusal. - sign.ps1 keeps the stable signing step's random create-new temp folder; only the Nightly additions remain. - Drop our dormant nightly-dispatch.yml, as in the other apps. - profile_root: a test pins the Flatpak's own data folder as an accepted profile. Tests: new packaging/linux/nightly-package-test.sh renders package.sh's nightly tar with stub binaries and runs the extracted launcher (plain, the Launcher form, --version, XDG_DATA_HOME, a PATH lookup from another directory, and the AppImage and flat layouts); nightly-arch-tar-test.sh covers the Launcher form and the data-home profile. - Fix a compile error in the flavour's own window body: the unclean-session notice flag (an Arc) was moved into the window closure and then read after run_native, so cargo check failed with E0382. The window body now takes its own clone, as the exit hook already did; found by the first capped cargo check in this pass. --- .github/workflows/nightly-build.yml | 10 ++- .github/workflows/nightly-dispatch.yml | 72 ----------------- .github/workflows/packaging-lint.yml | 2 + apps/wordcraft/src/main.rs | 10 ++- apps/wordcraft/src/profile_root.rs | 4 + docs/releasing.md | 23 ++++-- packaging/linux/flatpak-bundle.sh | 11 ++- packaging/linux/nightly-arch-launch.sh | 13 ---- packaging/linux/nightly-arch-tar-test.sh | 14 +++- packaging/linux/nightly-arch-tar.sh | 2 +- packaging/linux/nightly-launcher.sh | 53 +++++++++++++ packaging/linux/nightly-package-test.sh | 99 ++++++++++++++++++++++++ packaging/linux/nightly.sh | 21 ++--- packaging/linux/package.sh | 52 ++++--------- packaging/nightly-archive-tests.py | 2 +- packaging/nightly-archive.py | 6 +- packaging/windows/sign.ps1 | 4 +- 17 files changed, 237 insertions(+), 161 deletions(-) delete mode 100644 .github/workflows/nightly-dispatch.yml delete mode 100755 packaging/linux/nightly-arch-launch.sh create mode 100755 packaging/linux/nightly-launcher.sh create mode 100755 packaging/linux/nightly-package-test.sh diff --git a/.github/workflows/nightly-build.yml b/.github/workflows/nightly-build.yml index 9d92af6b59..ddfcd0f528 100644 --- a/.github/workflows/nightly-build.yml +++ b/.github/workflows/nightly-build.yml @@ -77,12 +77,15 @@ jobs: work="$RUNNER_TEMP/nightly-check" mkdir -p "$work" archive="$DIST/wordcraft-$WORDCRAFT_VERSION-linux-x86_64-nightly.tar.gz" - members="$(tar -tzf "$archive" | sort | tr '\n' ' ')" - [ "$members" = "ATTRIBUTION.md LICENSE-APACHE LICENSE-MIT NOTICE README.md wordcraft wordcraft-nightly.png " ] \ - || { echo "unexpected members: $members"; exit 1; } + # The launcher and the GUI it starts, the icon and the notices; the embedded fonts' + # OFL-*.txt licences appear when the build has CRAFT_FONTS_DIR. + core="$(tar -tzf "$archive" | sort | grep -Ev '^OFL-[A-Za-z0-9_.-]+\.txt$' | tr '\n' ' ')" + [ "$core" = "ATTRIBUTION.md LICENSE-APACHE LICENSE-MIT NOTICE README.md wordcraft wordcraft-bin wordcraft-nightly.png " ] \ + || { echo "unexpected members: $core"; exit 1; } tar -xzf "$archive" -C "$work" [ -x "$work/wordcraft" ] && [ ! -L "$work/wordcraft" ] [ "$(stat -c %a "$work/wordcraft")" = 755 ] + [ -x "$work/wordcraft-bin" ] && [ ! -L "$work/wordcraft-bin" ] mkdir -m 700 -p "$work/home" "$work/profile" out="$(env -i HOME="$work/home" PATH=/usr/bin:/bin "$work/wordcraft" --version 2>"$work/stderr")" \ || { cat "$work/stderr"; exit 1; } @@ -90,6 +93,7 @@ jobs: [ "$out" = "WordCraft $WORDCRAFT_VERSION (nightly-v1)" ] out="$(env -i HOME="$work/home" PATH=/usr/bin:/bin "$work/wordcraft" --launch-profile nightly-v1 --profile-root "$work/profile" --version)" [ "$out" = "WordCraft $WORDCRAFT_VERSION (nightly-v1)" ] + [ "$(head -c 2 "$work/wordcraft")" = '#!' ] echo "==> verified (unsigned): $out" - name: Keep the unsigned archive uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 diff --git a/.github/workflows/nightly-dispatch.yml b/.github/workflows/nightly-dispatch.yml deleted file mode 100644 index 6c3958db2a..0000000000 --- a/.github/workflows/nightly-dispatch.yml +++ /dev/null @@ -1,72 +0,0 @@ -name: Dispatch release-ref nightly - -# Transport only, never authorization. No checkout, payload parsing or release environment. -on: - workflow_run: - workflows: [WordCraft unsigned nightly] - types: [completed] - branches: [main] - -permissions: {} - -jobs: - dispatch: - # SOURCE PREPARATION: literal off until immutable shared tooling and policy qualification. - if: >- - false && github.repository == 'storytold/wordcraft' && - github.event_name == 'workflow_run' - runs-on: ubuntu-latest - timeout-minutes: 5 - permissions: - actions: write - steps: - - name: Dispatch only the exact completed producer run and attempt - shell: python - env: - GH_TOKEN: ${{ github.token }} - run: | - import json - import os - import urllib.request - - def require(value, message): - if not value: - raise RuntimeError(message) - - # These filters reduce noise; the protected release validator repeats admission - # against authenticated API metadata and required attestation/quality evidence. - require(os.environ.get('GITHUB_REPOSITORY') == 'storytold/wordcraft', 'wrong repository') - require(os.environ.get('GITHUB_EVENT_NAME') == 'workflow_run', 'wrong event') - with open(os.environ['GITHUB_EVENT_PATH'], encoding='utf-8') as stream: - event = json.load(stream) - require(event.get('action') == 'completed', 'producer is not complete') - require(event.get('repository', {}).get('full_name') == 'storytold/wordcraft', 'wrong event repository') - producer = event.get('workflow_run', {}) - require(producer.get('head_repository', {}).get('full_name') == 'storytold/wordcraft', 'foreign producer') - require(producer.get('path') == '.github/workflows/nightly.yml', 'wrong producer path') - require(producer.get('head_branch') == 'main', 'wrong producer branch') - require(producer.get('status') == 'completed' and producer.get('conclusion') == 'success', 'producer did not succeed') - # First scheduled attempt only; reviewed manual/re-run authority belongs to release policy. - require(producer.get('event') == 'schedule', 'not an automatic scheduled producer') - run_id, attempt = producer.get('id'), producer.get('run_attempt') - require(type(run_id) is int and run_id > 0, 'invalid producer run id') - require(type(attempt) is int and attempt == 1, 'invalid automatic producer attempt') - body = json.dumps({'ref': 'release', 'inputs': { - 'producer_run_id': str(run_id), 'producer_run_attempt': str(attempt) - }}).encode('utf-8') - request = urllib.request.Request( - 'https://api.github.com/repos/storytold/wordcraft/actions/workflows/nightly-sign.yml/dispatches', - data=body, method='POST', headers={ - 'Authorization': 'Bearer ' + os.environ['GH_TOKEN'], - 'Accept': 'application/vnd.github+json', - 'Content-Type': 'application/json', - 'X-GitHub-Api-Version': '2022-11-28', - 'User-Agent': 'wordcraft-nightly-dispatch' - }) - class NoRedirect(urllib.request.HTTPRedirectHandler): - def redirect_request(self, req, fp, code, msg, headers, newurl): - raise RuntimeError('dispatch redirects are forbidden') - # One bounded request, no retry: duplicate transport is not publication authority. - with urllib.request.build_opener(NoRedirect()).open(request, timeout=20) as response: - require(response.status == 204, 'dispatch was not accepted') - print('Dispatched producer run/attempt to the release-ref validator; not a signing result.') diff --git a/.github/workflows/packaging-lint.yml b/.github/workflows/packaging-lint.yml index 0b1423db63..58cbeeb454 100644 --- a/.github/workflows/packaging-lint.yml +++ b/.github/workflows/packaging-lint.yml @@ -68,3 +68,5 @@ jobs: run: python3 packaging/nightly-tests.py - name: Check the Arch Nightly handoff launcher (no build) run: bash packaging/linux/nightly-arch-tar-test.sh + - name: Render and run the Nightly tar launcher (no build) + run: bash packaging/linux/nightly-package-test.sh diff --git a/apps/wordcraft/src/main.rs b/apps/wordcraft/src/main.rs index d8e8edda74..890f855970 100644 --- a/apps/wordcraft/src/main.rs +++ b/apps/wordcraft/src/main.rs @@ -411,12 +411,14 @@ fn prepare_launch() -> Option> { /// geometry, opens requested documents or the Start screen, starts the control server when /// asked, and runs the eframe event loop. fn main() -> eframe::Result { - let Some(arguments) = prepare_launch() else { return Ok(()) }; // Windows: the print helper is a copy of this program that runs one job in its own process. + // It reads only its own job folder, so it runs before the launch profile is parsed: a Nightly + // wants a profile on every start, and the helper must print without one. #[cfg(windows)] if let Some(code) = craft::print::spool::isolated::helper_main() { std::process::exit(code); } + let Some(arguments) = prepare_launch() else { return Ok(()) }; // Windows: the update helper is a copy of this program started with `--finish-update`. // A Nightly never updates itself: the Launcher owns its updates. #[cfg(windows)] @@ -630,9 +632,11 @@ fn main() -> eframe::Result { let previous_nightly_unclean = nightly_record.as_ref().is_some_and(nightly_session::Session::previous_unclean); let nightly_watch: nightly_session::Shared = Arc::new(Mutex::new(nightly_record)); let unclean_notice_shown = Arc::new(std::sync::atomic::AtomicBool::new(false)); - // The window's exit hook takes one clone of each; the return path keeps the other. + // The window body and its exit hook each take a clone of the flag; the return path keeps the + // other, so a start that created no window can still finish the record. let session_for_exit = nightly_watch.clone(); let noticed_for_exit = unclean_notice_shown.clone(); + let noticed_in_window = unclean_notice_shown.clone(); let exit_settings = settings.clone(); let result = eframe::run_native( wordcraft_ui_egui::os_window::name_for(wordcraft_ui_egui::os_window::identity()), @@ -749,7 +753,7 @@ fn main() -> eframe::Result { app.status_long( "The previous WordCraft Nightly session did not finish normally. You can report a problem from Help › About. No diagnostics have been sent.", ); - unclean_notice_shown.store(true, std::sync::atomic::Ordering::Relaxed); + noticed_in_window.store(true, std::sync::atomic::Ordering::Relaxed); } Ok(Box::new(App { app, diff --git a/apps/wordcraft/src/profile_root.rs b/apps/wordcraft/src/profile_root.rs index 3118fba4e9..6cff911e78 100644 --- a/apps/wordcraft/src/profile_root.rs +++ b/apps/wordcraft/src/profile_root.rs @@ -350,6 +350,10 @@ mod tests { } assert!(!flatpak.exists()); assert!(fixture.check(Platform::Linux, &fixture.home().join(".var/app/ai.storyteller.launcher/nightly")).is_ok()); + // Inside the Nightly Flatpak, XDG_DATA_HOME is this app's own persistent data folder, so + // the launcher's profile lands there rather than on the discarded sandbox home. + let nightly = fixture.home().join(".var/app/ai.storyteller.wordcraft.nightly/data/wordcraft-nightly"); + assert_eq!(fixture.check(Platform::Linux, &nightly).unwrap(), nightly); } #[test] diff --git a/docs/releasing.md b/docs/releasing.md index cb4bf4963b..0acb6ae44f 100644 --- a/docs/releasing.md +++ b/docs/releasing.md @@ -54,12 +54,19 @@ What the channel is: archives on the `full-ci` label or on dispatch, with no secrets; `packaging/nightly-tests.py` runs the synthetic suites in Packaging lint. -Every Linux format ships a launcher that starts the binary the channel's way, because a Nightly -build refuses to run without a profile: -`wordcraft --launch-profile nightly-v1 --profile-root "$HOME/.local/share/wordcraft-nightly" -- "$@"`. +Every Linux format ships one launcher (`packaging/linux/nightly-launcher.sh`) that starts the +binary the channel's way, because a Nightly build refuses to run without a profile: +`wordcraft --launch-profile nightly-v1 --profile-root "${XDG_DATA_HOME:-$HOME/.local/share}/wordcraft-nightly" -- "$@"`. That launcher is the deb/rpm `/usr/bin/wordcraft-nightly` wrapper (real binary in -`/usr/lib/wordcraft-nightly/`), the AppImage `AppRun` (a script, not a symlink), the Arch -`bin/wordcraft` launcher, the plain tar's `bin/wordcraft` (real binary in `lib/wordcraft-nightly/`) -and the Flatpak bundle built from that tar. Redirecting `XDG_*` alone is refused: the build's root -validator derives the stable boundary from it, so the profile would sit inside it. The remaining -activation steps are described in [nightly-release-preparation.md](nightly-release-preparation.md). +`/usr/lib/wordcraft-nightly/`), the AppImage `AppRun` (a script, not a symlink, calling +`usr/bin/wordcraft`), the Arch `bin/wordcraft-nightly` launcher (real binary in +`bin/.wordcraft-nightly/`), the app-owned Nightly tar's `wordcraft` (real binary `wordcraft-bin`) +and the plain tar's `bin/wordcraft` (real binary in `lib/wordcraft-nightly/`), which the Flatpak +bundle also installs. `XDG_DATA_HOME` keeps the profile on the app's own data directory inside the +Flatpak sandbox (`~/.var/app/ai.storyteller.wordcraft.nightly/data/wordcraft-nightly`), which +persists; the sandbox's home is discarded. Redirecting `XDG_*` alone is refused: the build's root +validator derives the stable boundary from it, so the profile would sit inside it. The launcher +passes an already-supplied Launcher form (`--launch-profile`, and `--version`/`-V`) straight +through, so the ArtCraft Launcher's own root is used and its version check opens no window. The +remaining activation steps are described in +[nightly-release-preparation.md](nightly-release-preparation.md). diff --git a/packaging/linux/flatpak-bundle.sh b/packaging/linux/flatpak-bundle.sh index ea3e738e2d..d87639c288 100755 --- a/packaging/linux/flatpak-bundle.sh +++ b/packaging/linux/flatpak-bundle.sh @@ -82,9 +82,10 @@ if [[ "$FLATPAK_ID" != "$APP_ID" ]]; then [[ -f "$NIGHTLY_ICON" ]] || NIGHTLY_ICON="$ROOT/assets/app-icon/hicolor/256x256/apps/$APP_ID.png" install -Dm644 "$NIGHTLY_ICON" \ "$WORK/stage/share/icons/hicolor/256x256/apps/$FLATPAK_ID.png" - # The nightly tar carries a launcher in bin/wordcraft and the real binary beside it in - # lib/wordcraft-nightly/; the bundle must install both. The launcher is the Flatpak's wrapper: - # inside the sandbox HOME is the app's own directory, so the profile stays private. + # The nightly tar carries the launcher in bin/wordcraft and the GUI in lib/wordcraft-nightly/; + # the bundle must install both. The launcher keeps the profile under XDG_DATA_HOME, which inside + # the sandbox is this app's own persistent data directory + # (~/.var/app/ai.storyteller.wordcraft.nightly/data), not the throwaway sandbox home. sed -e "s|ai\.storyteller\.wordcraft|$FLATPAK_ID|g" \ -e 's|^\( - install -Dm755 bin/wordcraft /app/bin/wordcraft\)$|\1\n - install -Dm755 lib/wordcraft-nightly/wordcraft /app/lib/wordcraft-nightly/wordcraft|' \ "$HERE/flatpak/$APP_ID.bundle.yml" >"$WORK/$FLATPAK_ID.yml" @@ -114,6 +115,10 @@ if [[ "$TEST" = 1 ]]; then flatpak install --user -y --noninteractive --reinstall "$OUT" flatpak info --user "$FLATPAK_ID" flatpak run --command=wordcraft-cli "$FLATPAK_ID" --version + if [[ "$FLATPAK_ID" != "$APP_ID" ]]; then + # The launcher and the GUI it starts are both installed, and the version query answers. + flatpak run --command=wordcraft "$FLATPAK_ID" --version + fi flatpak run --command=sh "$FLATPAK_ID" -c 'ls /app/share/applications /app/share/metainfo /app/share/mime/packages /app/share/icons/hicolor/*/apps' fi echo "==> done" diff --git a/packaging/linux/nightly-arch-launch.sh b/packaging/linux/nightly-arch-launch.sh deleted file mode 100755 index cb7df96e9a..0000000000 --- a/packaging/linux/nightly-arch-launch.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/sh -set -eu - -# The Nightly channel's own launch profile holds every piece of user state (preferences, window -# place, logs, recovery, fonts, templates, the dictionary and the suite font store). Redirecting -# XDG_* instead is refused by the build's root validator, which derives the stable boundary from -# the environment, so the profile would sit inside it. -real_bin="$(dirname "$0")/.wordcraft-nightly/wordcraft" -if [ "${1:-}" = "--version" ] || [ "${1:-}" = "-V" ]; then - exec "$real_bin" "$@" -fi -exec "$real_bin" --launch-profile nightly-v1 \ - --profile-root "${HOME:?HOME is required}/.local/share/wordcraft-nightly" -- "$@" diff --git a/packaging/linux/nightly-arch-tar-test.sh b/packaging/linux/nightly-arch-tar-test.sh index 1fa034e5aa..17e4e1398b 100755 --- a/packaging/linux/nightly-arch-tar-test.sh +++ b/packaging/linux/nightly-arch-tar-test.sh @@ -47,8 +47,11 @@ expect() { exit 1 fi } -profile="$HOME/.local/share/wordcraft-nightly" +profile="$XDG_DATA_HOME/wordcraft-nightly" prefix="$(printf 'XDG_CONFIG_HOME=%s\nXDG_DATA_HOME=%s' "$XDG_CONFIG_HOME" "$XDG_DATA_HOME")" +# Run from a directory that holds no .wordcraft-nightly: a launcher found through PATH must +# resolve its own folder, and must never follow XDG_* to the profile. +cd "$work" expect "$(printf '%s\n<%s>\n<%s>\n<%s>\n<%s>\n<%s>' "$prefix" \ --launch-profile nightly-v1 --profile-root "$profile" --)" expect "$(printf '%s\n<%s>\n<%s>\n<%s>\n<%s>\n<%s>\n<%s>\n<%s>' "$prefix" \ @@ -56,5 +59,14 @@ expect "$(printf '%s\n<%s>\n<%s>\n<%s>\n<%s>\n<%s>\n<%s>\n<%s>' "$prefix" \ 'doc with spaces.docx' '--other-name.docx' expect "$(printf '%s\n<%s>' "$prefix" --version)" --version expect "$(printf '%s\n<%s>' "$prefix" -V)" -V +# The ArtCraft Launcher's form passes through untouched: wrapping it again would make its tokens +# file names and ignore the root it chose. +root="$work/launcher profile with space" +expect "$(printf '%s\n<%s>\n<%s>\n<%s>\n<%s>\n<%s>\n<%s>' "$prefix" \ + --launch-profile nightly-v1 --profile-root "$root" -- 'a.docx')" \ + --launch-profile nightly-v1 --profile-root "$root" -- 'a.docx' +expect "$(printf '%s\n<%s>\n<%s>\n<%s>\n<%s>\n<%s>' "$prefix" \ + --launch-profile nightly-v1 --profile-root "$root" --version)" \ + --launch-profile nightly-v1 --profile-root "$root" --version echo "PASS: Arch Nightly handoff isolates the profile and preserves launch arguments" diff --git a/packaging/linux/nightly-arch-tar.sh b/packaging/linux/nightly-arch-tar.sh index 0298e3ac69..d811a9dd65 100755 --- a/packaging/linux/nightly-arch-tar.sh +++ b/packaging/linux/nightly-arch-tar.sh @@ -13,7 +13,7 @@ mkdir -p "$work" cp -R "$source_tree" "$stage" mkdir "$stage/bin/.wordcraft-nightly" mv "$stage/bin/wordcraft" "$stage/bin/.wordcraft-nightly/wordcraft" -cp "$here/nightly-arch-launch.sh" "$stage/bin/wordcraft" +cp "$here/nightly-launcher.sh" "$stage/bin/wordcraft" chmod 755 "$stage/bin/wordcraft" tar -C "$work" -czf "$destination/$basename.tar.gz" "$basename" echo "wrote $destination/$basename.tar.gz" diff --git a/packaging/linux/nightly-launcher.sh b/packaging/linux/nightly-launcher.sh new file mode 100755 index 0000000000..a72d8f425f --- /dev/null +++ b/packaging/linux/nightly-launcher.sh @@ -0,0 +1,53 @@ +#!/bin/sh +# The Nightly channel's launcher, installed by every Linux format in place of the GUI binary. +# +# A Nightly keeps all of its user state in its own launch profile, so the launcher adds +# `--launch-profile nightly-v1 --profile-root ...` and passes the user's arguments after `--`. +# Redirecting XDG_* instead is refused by the build's profile validator, which derives the stable +# boundary from the environment, so the chosen profile would sit inside that boundary. +# +# The GUI sits beside the launcher in one of these layouts: +# wordcraft-bin an unpacked app-owned nightly tar (nightly.sh) +# .wordcraft-nightly/wordcraft the Arch handoff (nightly-arch-tar.sh) +# ../lib/wordcraft-nightly/wordcraft deb/rpm and the plain FHS tar (package.sh) +# usr/bin/wordcraft an AppImage, whose AppRun is this launcher +# The path is resolved from this script, never from the working directory, and only a regular +# executable is used. +# +# The ArtCraft Launcher starts the tar's `wordcraft` with the profile form already supplied +# (`--launch-profile nightly-v1 --profile-root -- files`, or `--version` for its check). +# That form passes straight through: wrapping it again would turn its tokens into file names and +# ignore the root the Launcher chose. `--version`/`-V` do too, so a version check opens no window +# and creates no profile. +set -eu + +case $0 in + */*) self=$0 ;; + *) self=$(command -v -- "$0") || { echo "wordcraft: cannot locate this launcher" >&2; exit 2; } ;; +esac +here=$(CDPATH='' cd -- "$(dirname -- "$self")" && pwd -P) \ + || { echo "wordcraft: cannot resolve this launcher's folder" >&2; exit 2; } + +real_bin= +for candidate in \ + "$here/wordcraft-bin" \ + "$here/.wordcraft-nightly/wordcraft" \ + "$here/../lib/wordcraft-nightly/wordcraft" \ + "$here/usr/bin/wordcraft" +do + if [ -f "$candidate" ] && [ -x "$candidate" ]; then + real_bin=$candidate + break + fi +done +[ -n "$real_bin" ] || { echo "wordcraft: cannot find the Nightly GUI next to $here" >&2; exit 2; } + +case ${1:-} in + --launch-profile | --version | -V) exec "$real_bin" "$@" ;; +esac + +data_home=${XDG_DATA_HOME:-} +if [ -z "$data_home" ]; then + data_home=${HOME:?HOME is required}/.local/share +fi +exec "$real_bin" --launch-profile nightly-v1 --profile-root "$data_home/wordcraft-nightly" -- "$@" diff --git a/packaging/linux/nightly-package-test.sh b/packaging/linux/nightly-package-test.sh new file mode 100755 index 0000000000..b44df13f6d --- /dev/null +++ b/packaging/linux/nightly-package-test.sh @@ -0,0 +1,99 @@ +#!/usr/bin/env bash +# Render the Nightly Linux tar exactly as package.sh does, without building or opening WordCraft, +# and run the launcher it installs. Guards the tar step's paths and the launcher's argument rules. +set -euo pipefail + +HERE="$(cd "$(dirname "$0")" && pwd)" +ROOT="$(cd "$HERE/../.." && pwd)" +work="$(mktemp -d)" +trap 'rm -rf "$work"' EXIT + +export CARGO_TARGET_DIR="$work/target" +export DIST="$work/dist" +export WORDCRAFT_BUILD_CHANNEL=nightly-v1 +export WORDCRAFT_VERSION="0.0.0-nightly.20260101.1.1.g0123456789ab" +export WORDCRAFT_BUILD_DATE="2026-01-01" +mkdir -p "$CARGO_TARGET_DIR/release" "$DIST" + +# A local argv recorder stands in for the compiled binaries. It never opens a UI. +cat >"$CARGO_TARGET_DIR/release/wordcraft" <<'RECORDER' +#!/bin/sh +printf '<%s>\n' "$@" +RECORDER +cp "$CARGO_TARGET_DIR/release/wordcraft" "$CARGO_TARGET_DIR/release/wordcraft-cli" +chmod 755 "$CARGO_TARGET_DIR/release/wordcraft" "$CARGO_TARGET_DIR/release/wordcraft-cli" + +# The tar format is first in package.sh's default set; a broken nightly tar aborted every run here. +(cd "$ROOT" && bash packaging/linux/package.sh --skip-build --formats tar) + +base="wordcraft-$WORDCRAFT_VERSION-linux-$(uname -m)" +archive="$DIST/$base.tar.gz" +[ -f "$archive" ] || { echo "error: package.sh wrote no $archive" >&2; exit 1; } +tar -xzf "$archive" -C "$work" +tree="$work/$base" + +# The FHS tree the desktop file and the Flatpak bundle expect: the launcher in bin/, the GUI in +# lib/wordcraft-nightly/. +[ -x "$tree/bin/wordcraft" ] && [ ! -L "$tree/bin/wordcraft" ] || { echo 'error: bin/wordcraft is not the launcher' >&2; exit 1; } +[ -x "$tree/lib/wordcraft-nightly/wordcraft" ] || { echo 'error: no GUI in lib/wordcraft-nightly' >&2; exit 1; } +cmp "$tree/lib/wordcraft-nightly/wordcraft" "$CARGO_TARGET_DIR/release/wordcraft" +cmp "$tree/bin/wordcraft" "$HERE/nightly-launcher.sh" + +home="$work/home with space" +mkdir -p "$home" +expect() { + expected="$1" + shift + actual=$(env -i HOME="$home" PATH="/usr/bin:/bin" "$tree/bin/wordcraft" "$@") + if [ "$actual" != "$expected" ]; then + printf 'expected:\n%s\nactual:\n%s\n' "$expected" "$actual" >&2 + exit 1 + fi +} +profile="$home/.local/share/wordcraft-nightly" +expect "$(printf '<%s>\n<%s>\n<%s>\n<%s>\n<%s>' \ + --launch-profile nightly-v1 --profile-root "$profile" --)" +expect "$(printf '<%s>\n<%s>\n<%s>\n<%s>\n<%s>\n<%s>\n<%s>' \ + --launch-profile nightly-v1 --profile-root "$profile" -- 'doc with spaces.docx' '--other-name.docx')" \ + 'doc with spaces.docx' '--other-name.docx' +expect "$(printf '<%s>' --version)" --version +expect "$(printf '<%s>' -V)" -V +# The ArtCraft Launcher's own form passes through untouched, including the root it chose. +root="$work/launcher profile with space" +expect "$(printf '<%s>\n<%s>\n<%s>\n<%s>\n<%s>\n<%s>' \ + --launch-profile nightly-v1 --profile-root "$root" -- 'a.docx')" \ + --launch-profile nightly-v1 --profile-root "$root" -- 'a.docx' +expect "$(printf '<%s>\n<%s>\n<%s>\n<%s>\n<%s>' \ + --launch-profile nightly-v1 --profile-root "$root" --version)" \ + --launch-profile nightly-v1 --profile-root "$root" --version + +# A data directory the person set themselves (and the Flatpak sandbox's own) keeps the profile +# beside the stable folder rather than on the throwaway home. +data="$work/xdg data with space" +mkdir -p "$data" +actual=$(env -i HOME="$home" XDG_DATA_HOME="$data" PATH="/usr/bin:/bin" "$tree/bin/wordcraft" --version) +[ "$actual" = '<--version>' ] +actual=$(env -i HOME="$home" XDG_DATA_HOME="$data" PATH="/usr/bin:/bin" "$tree/bin/wordcraft" 'x.docx') +[ "$actual" = "$(printf '<%s>\n<%s>\n<%s>\n<%s>\n<%s>\n<%s>' --launch-profile nightly-v1 --profile-root "$data/wordcraft-nightly" -- x.docx)" ] + +# A launcher found through PATH still resolves its own folder, never the working directory. +mkdir -p "$work/elsewhere" +actual=$(cd "$work/elsewhere" && env -i HOME="$home" PATH="$tree/bin:/usr/bin:/bin" wordcraft --version) +[ "$actual" = '<--version>' ] + +# The other two layouts the same file is installed in: the AppImage (AppRun beside usr/bin) and +# the app-owned nightly tar (wordcraft-bin beside the launcher). +mkdir -p "$work/AppDir/usr/bin" "$work/flat" +install -m 755 "$HERE/nightly-launcher.sh" "$work/AppDir/AppRun" +cp "$CARGO_TARGET_DIR/release/wordcraft" "$work/AppDir/usr/bin/wordcraft" +install -m 755 "$HERE/nightly-launcher.sh" "$work/flat/wordcraft" +cp "$CARGO_TARGET_DIR/release/wordcraft" "$work/flat/wordcraft-bin" +for layout in "$work/AppDir/AppRun" "$work/flat/wordcraft"; do + actual=$(env -i HOME="$home" PATH="/usr/bin:/bin" "$layout" 'x.docx') + [ "$actual" = "$(printf '<%s>\n<%s>\n<%s>\n<%s>\n<%s>\n<%s>' --launch-profile nightly-v1 --profile-root "$home/.local/share/wordcraft-nightly" -- x.docx)" ] \ + || { echo "error: $layout did not wrap: $actual" >&2; exit 1; } + actual=$(env -i HOME="$home" PATH="/usr/bin:/bin" "$layout" --version) + [ "$actual" = '<--version>' ] || { echo "error: $layout did not pass --version: $actual" >&2; exit 1; } +done + +echo "PASS: the Nightly tar starts the GUI through its launcher and keeps the profile it is given" diff --git a/packaging/linux/nightly.sh b/packaging/linux/nightly.sh index c33950729d..6ce5a7f8ab 100755 --- a/packaging/linux/nightly.sh +++ b/packaging/linux/nightly.sh @@ -18,21 +18,12 @@ OUTPUT="$DIST/wordcraft-$VERSION-linux-x86_64-nightly.tar.gz" nightly_build_gui STAGE="$NIGHTLY_WORK/stage" mkdir -p "$STAGE" -# An unpacked GUI tar is isolated too: bin/wordcraft is a launcher that passes the Nightly -# channel's launch profile (the one place its user state lives) and the real binary sits beside -# it. Redirecting XDG_* instead is refused by the build's root validator. -cp "$NIGHTLY_GUI" "$STAGE/wordcraft.real" -chmod 755 "$STAGE/wordcraft.real" -cat >"$STAGE/wordcraft" <<'LAUNCHER' -#!/bin/sh -set -eu -real_bin="$(dirname "$0")/wordcraft.real" -if [ "${1:-}" = "--version" ] || [ "${1:-}" = "-V" ]; then - exec "$real_bin" "$@" -fi -exec "$real_bin" --launch-profile nightly-v1 --profile-root "${HOME:?HOME is required}/.local/share/wordcraft-nightly" -- "$@" -LAUNCHER -chmod 755 "$STAGE/wordcraft" +# An unpacked GUI tar is isolated too: `wordcraft` is the channel's launcher and `wordcraft-bin` +# is the GUI it starts beside it. Redirecting XDG_* instead is refused by the build's root +# validator. +cp "$NIGHTLY_GUI" "$STAGE/wordcraft-bin" +chmod 755 "$STAGE/wordcraft-bin" +install -m 755 "$ROOT/packaging/linux/nightly-launcher.sh" "$STAGE/wordcraft" NIGHTLY_ICON="$ROOT/assets/app-icon/wordcraft-nightly.png" [[ -f "$NIGHTLY_ICON" ]] || NIGHTLY_ICON="$ROOT/assets/app-icon/wordcraft-1024.png" cp "$NIGHTLY_ICON" "$STAGE/wordcraft-nightly.png" diff --git a/packaging/linux/package.sh b/packaging/linux/package.sh index 9b0dd8f7c5..b677a7164a 100755 --- a/packaging/linux/package.sh +++ b/packaging/linux/package.sh @@ -48,7 +48,6 @@ IS_NIGHTLY=0 if [[ "${WORDCRAFT_BUILD_CHANNEL:-}" == nightly-v1 || "$VERSION" == *-nightly* ]]; then IS_NIGHTLY=1 export WORDCRAFT_BUILD_CHANNEL=nightly-v1 - export WORDCRAFT_OVERRIDE_VERSION="$VERSION" fi BASENAME_VERSION="$VERSION" if [[ "$IS_NIGHTLY" = 1 && "$BASENAME_VERSION" != *-nightly* ]]; then @@ -106,19 +105,11 @@ has() { local item="$1"; case " $FORMATS " in *" $item "*) return 0 ;; *) return # The Nightly channel starts only through its own launch profile, which holds every piece of user # state (preferences, window place, logs, recovery, fonts, templates, the dictionary and the suite # font store). Redirecting XDG_* instead is refused: the build's root validator derives the stable -# boundary from it, so the chosen profile would sit inside it. The real binary is always -# ../lib/wordcraft-nightly/wordcraft beside the launcher, in the packages, the plain tar and the -# Flatpak bundle built from that tar. +# boundary from it, so the chosen profile would sit inside it. One launcher serves every format +# (packaging/linux/nightly-launcher.sh); it finds the GUI in ../lib/wordcraft-nightly/wordcraft, +# the layout the packages, the plain tar and the Flatpak bundle built from that tar install. nightly_launcher() { - cat <<'WRAPPER' -#!/bin/sh -set -eu -real_bin="$(dirname "$0")/../lib/wordcraft-nightly/wordcraft" -if [ "${1:-}" = "--version" ] || [ "${1:-}" = "-V" ]; then - exec "$real_bin" "$@" -fi -exec "$real_bin" --launch-profile nightly-v1 --profile-root "${HOME:?HOME is required}/.local/share/wordcraft-nightly" -- "$@" -WRAPPER + install -Dm755 "$HERE/nightly-launcher.sh" "$1" } # ---- .tar.gz ------------------------------------------------------------------------------------ @@ -128,18 +119,18 @@ if has tar; then if [[ "$IS_NIGHTLY" = 1 ]]; then # An unpacked nightly tar is isolated too: the launcher keeps the desktop file's Exec # (bin/wordcraft) and the real binary moves to lib/wordcraft-nightly/, the layout the - # deb/rpm wrapper and the Flatpak bundle built from this tar use as well. - install -d "$WORK/tar/$BASENAME/usr/lib/wordcraft-nightly" - mv "$WORK/tar/$BASENAME/usr/bin/wordcraft" "$WORK/tar/$BASENAME/usr/lib/wordcraft-nightly/wordcraft" - nightly_launcher >"$WORK/tar/$BASENAME/usr/bin/wordcraft" - chmod 755 "$WORK/tar/$BASENAME/usr/bin/wordcraft" + # deb/rpm wrapper and the Flatpak bundle built from this tar use as well. The tar holds the + # contents of usr/, so these paths have no usr/ component. + install -d "$WORK/tar/$BASENAME/lib/wordcraft-nightly" + mv "$WORK/tar/$BASENAME/bin/wordcraft" "$WORK/tar/$BASENAME/lib/wordcraft-nightly/wordcraft" + nightly_launcher "$WORK/tar/$BASENAME/bin/wordcraft" fi tar -C "$WORK/tar" -czf "$DIST/$BASENAME.tar.gz" "$BASENAME" echo "wrote $DIST/$BASENAME.tar.gz" fi -# The Arch handoff keeps the same basename as the plain tarball in a separate directory. -# Flatpak, OCI and direct tar consumers still get the original binary, not this launcher. +# The Arch handoff keeps the same basename as the plain tarball in a separate directory. It +# stages the plain usr/ tree (GUI in bin/, no launcher), then installs its own launcher there. if [[ -n "$ARCH_TAR_DIR" ]]; then mkdir -p "$ARCH_TAR_DIR" if [[ "$(cd "$ARCH_TAR_DIR" && pwd -P)" == "$(cd "$DIST" && pwd -P)" ]]; then @@ -169,8 +160,7 @@ if has deb || has rpm; then rm -rf "$NFPM_STAGE" cp -R "$STAGE" "$NFPM_STAGE" install -Dm755 "$NFPM_STAGE/usr/bin/wordcraft" "$NFPM_STAGE/usr/lib/wordcraft-nightly/wordcraft" - nightly_launcher >"$NFPM_STAGE/usr/bin/$NFPM_BIN" - chmod 755 "$NFPM_STAGE/usr/bin/$NFPM_BIN" + nightly_launcher "$NFPM_STAGE/usr/bin/$NFPM_BIN" rm -f "$NFPM_STAGE/usr/bin/wordcraft" mv "$NFPM_STAGE/usr/bin/wordcraft-cli" "$NFPM_STAGE/usr/bin/$NFPM_CLI" mv "$NFPM_STAGE/usr/share/doc/wordcraft" "$NFPM_STAGE/usr/share/doc/$NFPM_NAME" @@ -246,20 +236,10 @@ if has appimage; then cp -R "$STAGE" "$APPDIR" if [[ "$IS_NIGHTLY" = 1 ]]; then APPIMAGE_ID="$APP_ID.nightly-v1" - cat >"$APPDIR/AppRun" <<'WRAPPER' -#!/bin/sh -set -eu -# A real file, not a symlink to the binary: the Nightly build starts only through its own launch -# profile, which holds every piece of user state. -HERE="$(dirname "$(readlink -f "$0")")" -real_bin="$HERE/usr/bin/wordcraft" -if [ "${1:-}" = "--version" ] || [ "${1:-}" = "-V" ]; then - exec "$real_bin" "$@" -fi -exec "$real_bin" --launch-profile nightly-v1 \ - --profile-root "${HOME:?HOME is required}/.local/share/wordcraft-nightly" -- "$@" -WRAPPER - chmod 755 "$APPDIR/AppRun" + # A real file, not a symlink to the binary: the Nightly build starts only through its own + # launch profile, which holds every piece of user state. The launcher finds the GUI in + # usr/bin/wordcraft inside this AppDir. + nightly_launcher "$APPDIR/AppRun" sed -e "s|^Icon=$APP_ID$|Icon=$APPIMAGE_ID|" \ -e "s|^Name=WordCraft$|Name=WordCraft Nightly|" \ -e '/^MimeType=/d' \ diff --git a/packaging/nightly-archive-tests.py b/packaging/nightly-archive-tests.py index 2a433030e1..2e5b56cbe4 100755 --- a/packaging/nightly-archive-tests.py +++ b/packaging/nightly-archive-tests.py @@ -31,7 +31,7 @@ class ArchivePolicy(unittest.TestCase): self.output = self.root / "nightly.tar.gz" self.required = { "wordcraft", - "wordcraft.real", + "wordcraft-bin", "wordcraft-nightly.png", "README.md", "LICENSE-MIT", diff --git a/packaging/nightly-archive.py b/packaging/nightly-archive.py index 0f2f74413f..9b93671919 100644 --- a/packaging/nightly-archive.py +++ b/packaging/nightly-archive.py @@ -33,8 +33,8 @@ def checked_entries(root, stage): total = 0 for entry in entries: name = entry.name - # wordcraft is the launcher and wordcraft.real the binary it starts (nightly.sh). - if name not in {"wordcraft", "wordcraft.real", "wordcraft-nightly.png"} and not notice(name): + # wordcraft is the launcher and wordcraft-bin the GUI it starts (nightly.sh). + if name not in {"wordcraft", "wordcraft-bin", "wordcraft-nightly.png"} and not notice(name): raise ValueError(f"unexpected nightly member: {name}") if len(name.encode("utf-8")) > 100: raise ValueError(f"nightly member must be a short regular file: {name}") @@ -47,7 +47,7 @@ def checked_entries(root, stage): folded.add(name.casefold()) required = { "wordcraft", - "wordcraft.real", + "wordcraft-bin", "wordcraft-nightly.png", "README.md", "LICENSE-MIT", diff --git a/packaging/windows/sign.ps1 b/packaging/windows/sign.ps1 index eee1b8f1b3..3b87e9e2fa 100644 --- a/packaging/windows/sign.ps1 +++ b/packaging/windows/sign.ps1 @@ -85,8 +85,8 @@ if (-not $haveCert -and -not $haveAzure) { $script:SignTool = Find-SignTool $common = @('sign', '/v', '/fd', 'SHA256', '/td', 'SHA256', '/d', 'WordCraft', '/du', 'https://github.com/storytold/wordcraft') -$tmp = Join-Path ([IO.Path]::GetTempPath()) "wordcraft-sign-$PID" -New-Item -ItemType Directory -Force -Path $tmp | Out-Null +$tmp = Join-Path ([IO.Path]::GetTempPath()) "wordcraft-sign-$([IO.Path]::GetRandomFileName())" +New-Item -ItemType Directory -Path $tmp | Out-Null try { if ($haveCert) {