From da74d24392057a41a8569e1e7f3b862171c4aebb Mon Sep 17 00:00:00 2001 From: tinygusie2 Date: Fri, 2 Oct 2026 11:47:52 +0200 Subject: [PATCH] Mac builds: universal Motion Studio and Motion Launcher, built on a Mac by the Mac build workflow - Launcher 1.2.0 knows the Mac: an app's `mac` block (asset, .app) replaces the Windows download, ditto unpacks it, open starts it, and copies in /Applications are adopted; apps without a Mac build are left out there - pack:mac / pack:launcher:mac make universal .app bundles; .github/workflows/mac.yml builds them, smoke-tests them and adds them with their checksums to a release Co-Authored-By: Claude Opus 5.5 --- .github/workflows/mac.yml | 93 +++++++++++++++++++++++++++++++++++++++ .gitignore | 1 + launcher/apps.json | 3 +- launcher/main.mjs | 7 ++- launcher/package.json | 2 +- launcher/updater.mjs | 20 +++++++-- package.json | 2 + scripts/pack-launcher.mjs | 9 ++-- scripts/pack.mjs | 9 ++-- scripts/smoke-project.mjs | 14 ++++++ test/launcher.test.mjs | 23 +++++++++- 11 files changed, 168 insertions(+), 15 deletions(-) create mode 100644 .github/workflows/mac.yml create mode 100644 scripts/smoke-project.mjs diff --git a/.github/workflows/mac.yml b/.github/workflows/mac.yml new file mode 100644 index 0000000..a97b968 --- /dev/null +++ b/.github/workflows/mac.yml @@ -0,0 +1,93 @@ +name: Mac build + +# Builds the universal (Intel + Apple Silicon) Mac apps, checks that they start, and adds them to existing releases +# together with their line in SHA256SUMS.txt. A Mac build has to be made on a Mac: the Electron framework inside an +# .app needs symlinks and permissions that a zip made on Windows loses. +on: + workflow_dispatch: + inputs: + studio_tag: + description: Motion Studio release to add the Mac build to (e.g. v1.3.0), empty to skip + required: false + launcher_tag: + description: Motion Launcher release to add the Mac build to (e.g. launcher-v1.2.0), empty to skip + required: false + +permissions: + contents: write + +jobs: + mac: + runs-on: macos-latest + env: + GH_TOKEN: ${{ github.token }} + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: 22 + cache: npm + - run: npm ci + + # .icns icons from the 256 px PNGs. + - name: Icons + run: | + icns() { + set=$(mktemp -d)/icon.iconset; mkdir -p "$set" + for s in 16 32 64 128 256; do sips -z $s $s "$1" --out "$set/icon_${s}x${s}.png" >/dev/null; done + for s in 16 32 64 128; do cp "$set/icon_$((s*2))x$((s*2)).png" "$set/icon_${s}x${s}@2x.png"; done + iconutil -c icns "$set" -o "$2" + } + icns resources/icon.png resources/icon.icns + icns launcher/icons/launcher.png launcher/icons/launcher.icns + + # Not notarized: the apps are signed ad hoc (Apple Silicon refuses to run unsigned code), so macOS asks once + # whether to open an app downloaded in a browser. + - name: Motion Studio + if: inputs.studio_tag != '' + run: | + npm run pack:mac + app="dist/Motion Studio-darwin-universal/Motion Studio.app" + codesign --force --deep --sign - "$app" + home=$(mktemp -d) + HOME="$home" node scripts/smoke-project.mjs "$home/project" + HOME="$home" "$app/Contents/MacOS/Motion Studio" --smoke-test studio.png + version=$(node -p "require('./package.json').version") + test "v$version" = "${{ inputs.studio_tag }}" || { echo "package.json is $version, the tag is ${{ inputs.studio_tag }}"; exit 1; } + zip="Motion-Studio-$version-mac-universal.zip" + ditto -c -k --keepParent "$app" "$zip" + echo "STUDIO_ZIP=$zip" >> "$GITHUB_ENV" + + - name: Motion Launcher + if: inputs.launcher_tag != '' + run: | + npm run pack:launcher:mac + app="dist/Motion Launcher-darwin-universal/Motion Launcher.app" + codesign --force --deep --sign - "$app" + MOTION_LAUNCHER_HOME=$(mktemp -d) "$app/Contents/MacOS/Motion Launcher" --smoke-test launcher.png + version=$(node -p "require('./launcher/package.json').version") + test "launcher-v$version" = "${{ inputs.launcher_tag }}" || { echo "launcher is $version, the tag is ${{ inputs.launcher_tag }}"; exit 1; } + zip="Motion-Launcher-$version-mac-universal.zip" + ditto -c -k --keepParent "$app" "$zip" + echo "LAUNCHER_ZIP=$zip" >> "$GITHUB_ENV" + + - uses: actions/upload-artifact@v4 + with: + name: screenshots + path: '*.png' + + # Adds the zip and its checksum line (replacing an older line for the same file) to the release. + - name: Publish + run: | + publish() { + tag=$1; zip=$2; [ -n "$tag" ] && [ -n "$zip" ] || return 0 + rm -f SHA256SUMS.txt + gh release download "$tag" -p SHA256SUMS.txt || touch SHA256SUMS.txt + grep -v " \*\?$zip\$" SHA256SUMS.txt > sums.tmp || true + shasum -a 256 -b "$zip" >> sums.tmp + mv sums.tmp SHA256SUMS.txt + cat SHA256SUMS.txt + gh release upload "$tag" "$zip" SHA256SUMS.txt --clobber + } + publish "${{ inputs.studio_tag }}" "$STUDIO_ZIP" + publish "${{ inputs.launcher_tag }}" "$LAUNCHER_ZIP" diff --git a/.gitignore b/.gitignore index 344c972..a83b122 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ dist/ *.pfx *.p12 *.cer +*.icns diff --git a/launcher/apps.json b/launcher/apps.json index 7e3dab9..59ac56a 100644 --- a/launcher/apps.json +++ b/launcher/apps.json @@ -10,7 +10,8 @@ "repo": "tinygusie2/motion-studio", "asset": "^Motion-Studio-.*-win-x64\\.zip$", "checksums": "SHA256SUMS.txt", - "exe": "Motion Studio.exe" + "exe": "Motion Studio.exe", + "mac": { "asset": "^Motion-Studio-.*-mac-universal\\.zip$", "exe": "Motion Studio.app" } }, { "id": "visual", diff --git a/launcher/main.mjs b/launcher/main.mjs index d712704..b471ad8 100644 --- a/launcher/main.mjs +++ b/launcher/main.mjs @@ -2,9 +2,10 @@ // starts them. Extra editors can be added without a new launcher build in %APPDATA%\Motion Launcher\apps.json. import { app, BrowserWindow, Menu, dialog, ipcMain, shell } from 'electron'; import { existsSync, readFileSync, readdirSync, writeFileSync } from 'node:fs'; +import { homedir } from 'node:os'; import { dirname, join } from 'node:path'; import { fileURLToPath } from 'node:url'; -import { Store, cleanup, compareVersions, findExisting, install, installedExe, latestRelease, launch } from './updater.mjs'; +import { Store, cleanup, compareVersions, findExisting, forPlatform, install, installedExe, latestRelease, launch } from './updater.mjs'; const here = fileURLToPath(new URL('.', import.meta.url)); const smoke = process.argv.includes('--smoke-test'); @@ -27,7 +28,7 @@ function loadApps() { if (at < 0) at = list.findIndex(a => a.placeholder && !a.comingSoon); if (at >= 0) list[at] = extra; else list.push(extra); } - return list.map(a => ({ ...a, name: loc(a.name), description: loc(a.description) })); + return list.map(a => forPlatform(a)).filter(Boolean).map(a => ({ ...a, name: loc(a.name), description: loc(a.description) })); } // Start menu shortcuts, so Windows Search finds the launcher and every app it installed. An app's shortcut points at its // installed version, so it is written again after each update. @@ -42,7 +43,9 @@ function appShortcut(a) { if (info) shortcut(a.name, installedExe(root, a, info), a.description); } // The exes behind the Start menu and desktop shortcuts, for finding editors that were installed without the launcher. +// On a Mac: the .app bundles in /Applications and ~/Applications. function shortcutTargets() { + if (process.platform === 'darwin') return apps.flatMap(a => [join('/Applications', a.exe), join(homedir(), 'Applications', a.exe)]); if (process.platform !== 'win32') return []; const dirs = [startMenu(), join(process.env.ProgramData || 'C:\\ProgramData', 'Microsoft', 'Windows', 'Start Menu', 'Programs'), app.getPath('desktop')]; const out = []; diff --git a/launcher/package.json b/launcher/package.json index 2a266f0..9b3cde8 100644 --- a/launcher/package.json +++ b/launcher/package.json @@ -1,7 +1,7 @@ { "name": "motion-launcher", "productName": "Motion Launcher", - "version": "1.1.1", + "version": "1.2.0", "description": "Installs, updates and starts Motion Studio (and other editors) from their GitHub releases.", "license": "MIT", "private": true, diff --git a/launcher/updater.mjs b/launcher/updater.mjs index 60b0131..34da5c1 100644 --- a/launcher/updater.mjs +++ b/launcher/updater.mjs @@ -89,11 +89,19 @@ export function parseChecksums(text) { return sums; } -// Windows' own tar.exe (bsdtar) unpacks zips; Git Bash's GNU tar that may come first on PATH does not. +// An app as this platform sees it: on a Mac its `mac` block ({ asset, exe: 'Name.app' }) replaces the Windows asset and +// exe. An app without one has no Mac build and is left out there (null). +export function forPlatform(app, platform = process.platform) { + if (platform !== 'darwin') return app; + return app.mac ? { ...app, ...app.mac } : null; +} + +// Windows' own tar.exe (bsdtar) unpacks zips; Git Bash's GNU tar that may come first on PATH does not. On a Mac, ditto +// keeps the symlinks and permissions an .app bundle needs. function extract(zip, dir) { const [cmd, args] = process.platform === 'win32' ? [join(process.env.SystemRoot || 'C:\\Windows', 'System32', 'tar.exe'), ['-xf', zip, '-C', dir]] - : ['unzip', ['-q', zip, '-d', dir]]; + : process.platform === 'darwin' ? ['ditto', ['-x', '-k', zip, dir]] : ['unzip', ['-q', zip, '-d', dir]]; return new Promise((resolve, reject) => execFile(cmd, args, { windowsHide: true }, err => err ? reject(err) : resolve())); } @@ -109,7 +117,9 @@ export function findExisting(app, exes) { for (const exe of exes) { if (!exe || basename(exe).toLowerCase() !== app.exe.toLowerCase() || !existsSync(exe)) continue; let version = '0.0.0'; - try { version = JSON.parse(readFileSync(join(dirname(exe), 'resources', 'app', 'package.json'), 'utf8')).version || version; } catch {} + // An .app bundle keeps the app in Contents/Resources, a Windows build next to the exe in resources. + const pkg = exe.toLowerCase().endsWith('.app') ? join(exe, 'Contents', 'Resources', 'app', 'package.json') : join(dirname(exe), 'resources', 'app', 'package.json'); + try { version = JSON.parse(readFileSync(pkg, 'utf8')).version || version; } catch {} return { version, path: dirname(exe), found: true, installedAt: statSync(exe).mtime.toISOString(), verified: false, previous: null }; } return null; @@ -205,7 +215,9 @@ export function launch(app, { root, store }) { if (!info) throw new Error(`${app.name} is not installed`); const exe = installedExe(root, app, info); if (!existsSync(exe)) throw new Error(`${exe} is missing; install ${app.name} again`); - const child = spawn(exe, app.args || [], { cwd: dirname(exe), detached: true, stdio: 'ignore' }); + // An .app bundle is a folder: macOS starts it through open (-n: a new copy, also when one runs from elsewhere). + const [cmd, args] = exe.toLowerCase().endsWith('.app') ? ['open', ['-n', exe, ...(app.args?.length ? ['--args', ...app.args] : [])]] : [exe, app.args || []]; + const child = spawn(cmd, args, { cwd: dirname(exe), detached: true, stdio: 'ignore' }); child.unref(); return child.pid; } diff --git a/package.json b/package.json index 2647f77..d4c62e3 100644 --- a/package.json +++ b/package.json @@ -23,12 +23,14 @@ "serve": "node src/server.mjs", "build": "node src/cli.mjs build", "pack": "node scripts/pack.mjs", + "pack:mac": "node scripts/pack.mjs --mac", "sign": "powershell -NoProfile -ExecutionPolicy Bypass -File scripts/sign.ps1", "sign:cert": "powershell -NoProfile -ExecutionPolicy Bypass -File scripts/make-selfsigned-cert.ps1", "dist": "npm run pack && npm run sign", "launcher": "electron launcher", "icon:launcher": "electron scripts/make-icon.cjs --launcher", "pack:launcher": "node scripts/pack-launcher.mjs", + "pack:launcher:mac": "node scripts/pack-launcher.mjs --mac", "sign:launcher": "powershell -NoProfile -ExecutionPolicy Bypass -File scripts/sign.ps1 -Exe \"dist/Motion Launcher-win32-x64/Motion Launcher.exe\" -Description \"Motion Launcher\"", "dist:launcher": "npm run pack:launcher && npm run sign:launcher", "test": "node --test \"test/*.test.mjs\"", diff --git a/scripts/pack-launcher.mjs b/scripts/pack-launcher.mjs index 132cf36..297e400 100644 --- a/scripts/pack-launcher.mjs +++ b/scripts/pack-launcher.mjs @@ -1,18 +1,21 @@ // Packages the launcher into dist/Motion Launcher-win32-x64 (npm run pack:launcher). It is its own small app in // launcher/, built with the same Electron as Motion Studio. import { packager } from '@electron/packager'; + +// --mac: a universal (Intel + Apple Silicon) .app; it has to be built on a Mac (see .github/workflows/mac.yml). +const mac = process.argv.includes('--mac'); import { readFileSync } from 'node:fs'; const electronVersion = JSON.parse(readFileSync('node_modules/electron/package.json', 'utf8')).version; const [out] = await packager({ dir: 'launcher', name: 'Motion Launcher', - platform: 'win32', - arch: 'x64', + platform: mac ? 'darwin' : 'win32', + arch: mac ? 'universal' : 'x64', out: 'dist', overwrite: true, electronVersion, - icon: 'launcher/icons/launcher.ico', + icon: mac ? 'launcher/icons/launcher.icns' : 'launcher/icons/launcher.ico', asar: false, prune: false }); diff --git a/scripts/pack.mjs b/scripts/pack.mjs index 9547cfb..ae0be17 100644 --- a/scripts/pack.mjs +++ b/scripts/pack.mjs @@ -3,14 +3,17 @@ // `^` of `--ignore=^/dist`, and an unanchored /dist also threw away node_modules/gsap/dist. import { packager } from '@electron/packager'; +// --mac: a universal (Intel + Apple Silicon) .app; it has to be built on a Mac (see .github/workflows/mac.yml). +const mac = process.argv.includes('--mac'); + const [out] = await packager({ dir: '.', name: 'Motion Studio', - platform: 'win32', - arch: 'x64', + platform: mac ? 'darwin' : 'win32', + arch: mac ? 'universal' : 'x64', out: 'dist', overwrite: true, - icon: 'resources/icon.ico', + icon: mac ? 'resources/icon.icns' : 'resources/icon.ico', asar: false, // Paths are relative to the project, starting with /. ignore: [/^\/dist(\/|$)/, /^\/launcher(\/|$)/, /^\/scripts(\/|$)/, /^\/docs(\/|$)/, /^\/test(\/|$)/, /^\/\.git/, /^\/\.claude(\/|$)/] diff --git a/scripts/smoke-project.mjs b/scripts/smoke-project.mjs new file mode 100644 index 0000000..323aa00 --- /dev/null +++ b/scripts/smoke-project.mjs @@ -0,0 +1,14 @@ +// A project with one video, for the packaged app's --smoke-test on a fresh machine (CI): node scripts/smoke-project.mjs +// Run it with HOME pointing at a scratch folder: the app's settings (~/.motion-studio) then open this project. +import { createWorkspace, Workspace, loadSettings, saveSettings } from '../src/workspace.mjs'; + +const dir = process.argv[2]; +if (!dir) throw new Error('usage: node scripts/smoke-project.mjs '); +createWorkspace(dir, 'Smoke test'); +new Workspace(dir).writeSpec('smoke', { + brand: 'brand', layout: 'text', dur: 4, end: 3, + heads: [{ t: 0.3, text: 'Smoke *test*' }], + clips: [], chips: [], zooms: [], taps: [], subs: [], vo: { lines: [] } +}); +saveSettings({ ...loadSettings(), workspace: dir, recents: [dir] }); +console.log(`Smoke project in ${dir}`); diff --git a/test/launcher.test.mjs b/test/launcher.test.mjs index 2965e40..9b07561 100644 --- a/test/launcher.test.mjs +++ b/test/launcher.test.mjs @@ -7,7 +7,7 @@ import { tmpdir } from 'node:os'; import { join } from 'node:path'; import { after, before, test } from 'node:test'; import { crc32 } from 'node:zlib'; -import { Store, cleanup, compareVersions, findExisting, install, installedExe, latestRelease, parseChecksums } from '../launcher/updater.mjs'; +import { Store, cleanup, compareVersions, findExisting, forPlatform, install, installedExe, latestRelease, parseChecksums } from '../launcher/updater.mjs'; // A zip with stored (uncompressed) entries: { 'path/in/zip': 'content' }. function zip(files) { @@ -142,6 +142,27 @@ test('cleanup never removes a folder with projects in it', () => { assert.deepEqual(new Set(readdirSync(demo)), new Set(['1.0.0', '2.0.0', '3.0.0'])); }); +test('forPlatform: a Mac gets the mac asset and .app, an app without a Mac build is left out there', () => { + const ms = { id: 'ms', asset: '-win-x64', exe: 'MS.exe', mac: { asset: '-mac-universal', exe: 'MS.app' } }; + assert.equal(forPlatform(ms, 'win32'), ms); + assert.deepEqual([forPlatform(ms, 'darwin').asset, forPlatform(ms, 'darwin').exe], ['-mac-universal', 'MS.app']); + assert.equal(forPlatform({ id: 'v', exe: 'V.exe' }, 'darwin'), null); + const real = JSON.parse(readFileSync(new URL('../launcher/apps.json', import.meta.url), 'utf8')); + assert.ok(new RegExp(forPlatform(real[0], 'darwin').asset).test('Motion-Studio-1.3.0-mac-universal.zip')); +}); + +test('findExisting reads the version of an .app bundle', () => { + const dir = mkdtempSync(join(tmpdir(), 'ml-mac-')); + try { + const bundle = join(dir, 'MS.app'); + mkdirSync(join(bundle, 'Contents', 'Resources', 'app'), { recursive: true }); + writeFileSync(join(bundle, 'Contents', 'Resources', 'app', 'package.json'), JSON.stringify({ version: '1.3.0' })); + const found = findExisting({ id: 'ms', exe: 'MS.app' }, [bundle]); + assert.equal(found.version, '1.3.0'); + assert.equal(found.path, dir); + } finally { rmSync(dir, { recursive: true, force: true }); } +}); + test('findExisting adopts a copy installed without the launcher, with its version', () => { const dir = mkdtempSync(join(tmpdir(), 'ml-found-')); try {