diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index be727a7..fee1ea9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,6 +21,8 @@ jobs: - run: npm ci env: ELECTRON_SKIP_BINARY_DOWNLOAD: '1' + # The demo tests record and encode clips with ffmpeg, which the Ubuntu runner doesn't have. + - run: sudo apt-get update && sudo apt-get install -y --no-install-recommends ffmpeg - run: npm run check - run: npm test # The editor in the runner's Chrome (playwright-core drives the installed browser, nothing to download). diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml new file mode 100644 index 0000000..da0d23f --- /dev/null +++ b/.github/workflows/linux.yml @@ -0,0 +1,76 @@ +name: Linux build + +# Builds the x64 Linux apps, checks that they start, and adds them to existing releases together with their line in +# SHA256SUMS.txt. Built on Linux so the zip keeps the executable bits and symlinks. +on: + workflow_dispatch: + inputs: + studio_tag: + description: Motion Studio release to add the Linux build to (e.g. v1.3.0), empty to skip + required: false + launcher_tag: + description: Motion Launcher release to add the Linux build to (e.g. launcher-v1.2.0), empty to skip + required: false + +permissions: + contents: write + +jobs: + linux: + runs-on: ubuntu-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 + + - name: Motion Studio + if: inputs.studio_tag != '' + run: | + npm run pack:linux + dir="dist/Motion Studio-linux-x64" + home=$(mktemp -d) + HOME="$home" node scripts/smoke-project.mjs "$home/project" + HOME="$home" xvfb-run -a "$dir/motion-studio" --no-sandbox --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-linux-x64.zip" + (cd "$dir" && zip -qry "$GITHUB_WORKSPACE/$zip" .) + echo "STUDIO_ZIP=$zip" >> "$GITHUB_ENV" + + - name: Motion Launcher + if: inputs.launcher_tag != '' + run: | + npm run pack:launcher:linux + dir="dist/Motion Launcher-linux-x64" + MOTION_LAUNCHER_HOME=$(mktemp -d) xvfb-run -a "$dir/motion-launcher" --no-sandbox --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-linux-x64.zip" + (cd "$dir" && zip -qry "$GITHUB_WORKSPACE/$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 + sha256sum -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/README.md b/README.md index 95864be..c4c5bf0 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ music, rendered to MP4 for TikTok, Reels, Shorts, LinkedIn and YouTube.** [![CI](https://github.com/tinygusie2/motion-studio/actions/workflows/ci.yml/badge.svg)](https://github.com/tinygusie2/motion-studio/actions/workflows/ci.yml) [![PRs welcome](https://img.shields.io/badge/PRs-welcome-c1ec8a.svg)](CONTRIBUTING.md) [![Good first issues](https://img.shields.io/github/issues/tinygusie2/motion-studio/good%20first%20issue?color=ffb77d&label=good%20first%20issues)](https://github.com/tinygusie2/motion-studio/issues?q=is%3Aopen+label%3A%22good+first+issue%22) -![Platform: Windows](https://img.shields.io/badge/platform-Windows-d7baff.svg) +![Platform: Windows | macOS | Linux](https://img.shields.io/badge/platform-Windows%20%7C%20macOS%20%7C%20Linux-d7baff.svg) A video made with Motion Studio @@ -92,6 +92,7 @@ On first start, create a project folder (*New projectโ€ฆ*), drop a screen record | `npm run test:ui` | Editor tests in your installed Chrome or Edge (dragging, trimming, splitting, undo, saving) | | `npm run serve` | Run the editor in your normal browser at http://localhost:3400, which is handy for development | | `npm run pack` | Build `dist/Motion Studio-win32-x64/Motion Studio.exe` | +| `npm run pack:linux` | Build `dist/Motion Studio-linux-x64/motion-studio` (on Linux) | | `npm run sign` | Sign that `.exe` (see [signing](#signing-on-windows)) | | `npm run dist` | `pack` + `sign` | | `npm run launcher` / `npm run dist:launcher` | Run / build and sign the launcher (`dist/Motion Launcher-win32-x64`) | @@ -127,7 +128,7 @@ Everything below is open for grabs. Comment on (or open) an issue so others know - ๐Ÿ“ **Docs**: tutorials, a "your first video" guide, GIFs of features **Bigger features** -- ๐ŸŽ **macOS and Linux builds**: the code is cross-platform, but packaging and testing aren't there yet +- ๐ŸŽ **macOS and Linux testing**: both are built (`pack:mac`, `pack:linux`), but see far less use than Windows - ๐ŸŽ™๏ธ **Whisper on macOS and Linux**: Windows installs whisper.cpp by itself, elsewhere it has to be installed by hand - ๐Ÿงช **More tests**: the modules (`npm test`) and the timeline basics (`npm run test:ui`) are covered; rendering and most of the inspector aren't yet diff --git a/launcher/apps.json b/launcher/apps.json index 59ac56a..d599728 100644 --- a/launcher/apps.json +++ b/launcher/apps.json @@ -11,7 +11,8 @@ "asset": "^Motion-Studio-.*-win-x64\\.zip$", "checksums": "SHA256SUMS.txt", "exe": "Motion Studio.exe", - "mac": { "asset": "^Motion-Studio-.*-mac-universal\\.zip$", "exe": "Motion Studio.app" } + "mac": { "asset": "^Motion-Studio-.*-mac-universal\\.zip$", "exe": "Motion Studio.app" }, + "linux": { "asset": "^Motion-Studio-.*-linux-x64\\.zip$", "exe": "motion-studio" } }, { "id": "visual", diff --git a/launcher/main.mjs b/launcher/main.mjs index b471ad8..8e593f2 100644 --- a/launcher/main.mjs +++ b/launcher/main.mjs @@ -1,7 +1,7 @@ // Motion Launcher: installs the editors listed in apps.json from their GitHub releases, keeps them up to date and // 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 { existsSync, mkdirSync, readFileSync, readdirSync, writeFileSync } from 'node:fs'; import { homedir } from 'node:os'; import { dirname, join } from 'node:path'; import { fileURLToPath } from 'node:url'; @@ -34,10 +34,21 @@ function loadApps() { // installed version, so it is written again after each update. const startMenu = () => join(app.getPath('appData'), 'Microsoft', 'Windows', 'Start Menu', 'Programs'); function shortcut(name, target, description = '') { + if (process.platform === 'linux' && !smoke && existsSync(target)) return desktopEntry(name, target, description); if (process.platform !== 'win32' || smoke || !existsSync(target)) return; const file = join(startMenu(), `${name.replace(/[\\/:*?"<>|]/g, '')}.lnk`); try { shell.writeShortcutLink(file, existsSync(file) ? 'replace' : 'create', { target, cwd: dirname(target), icon: target, iconIndex: 0, description }); } catch {} } +// On Linux: a .desktop file in ~/.local/share/applications, so the app menu finds it. +function desktopEntry(name, target, description) { + const dir = join(process.env.XDG_DATA_HOME || join(homedir(), '.local', 'share'), 'applications'); + const icon = [join(dirname(target), 'resources', 'app', 'resources', 'icon.png'), join(dirname(target), 'resources', 'app', 'icons', 'launcher.png')].find(existsSync) || ''; + const q = s => `"${s.replace(/["`$\\]/g, '\\$&')}"`; + try { + mkdirSync(dir, { recursive: true }); + writeFileSync(join(dir, `${name.toLowerCase().replace(/[^a-z0-9]+/g, '-')}.desktop`), ['[Desktop Entry]', 'Type=Application', `Name=${name}`, `Comment=${description}`, `Exec=${q(target)}`, `Path=${dirname(target)}`, icon && `Icon=${icon}`, 'Terminal=false', 'Categories=AudioVideo;Video;', ''].filter(s => s !== '').join('\n')); + } catch {} +} function appShortcut(a) { const info = store.installed(a.id); if (info) shortcut(a.name, installedExe(root, a, info), a.description); diff --git a/launcher/updater.mjs b/launcher/updater.mjs index 34da5c1..35a87b2 100644 --- a/launcher/updater.mjs +++ b/launcher/updater.mjs @@ -89,11 +89,12 @@ export function parseChecksums(text) { return sums; } -// 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). +// An app as this platform sees it: on a Mac its `mac` block ({ asset, exe: 'Name.app' }) and on Linux its `linux` block +// ({ asset, exe: 'name' }) replace the Windows asset and exe. An app without that block has no build there (null). export function forPlatform(app, platform = process.platform) { - if (platform !== 'darwin') return app; - return app.mac ? { ...app, ...app.mac } : null; + const key = platform === 'darwin' ? 'mac' : platform === 'linux' ? 'linux' : null; + if (!key) return app; + return app[key] ? { ...app, ...app[key] } : 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 diff --git a/package.json b/package.json index d4c62e3..334ee42 100644 --- a/package.json +++ b/package.json @@ -24,6 +24,7 @@ "build": "node src/cli.mjs build", "pack": "node scripts/pack.mjs", "pack:mac": "node scripts/pack.mjs --mac", + "pack:linux": "node scripts/pack.mjs --linux", "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", @@ -31,6 +32,7 @@ "icon:launcher": "electron scripts/make-icon.cjs --launcher", "pack:launcher": "node scripts/pack-launcher.mjs", "pack:launcher:mac": "node scripts/pack-launcher.mjs --mac", + "pack:launcher:linux": "node scripts/pack-launcher.mjs --linux", "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 297e400..3a70925 100644 --- a/scripts/pack-launcher.mjs +++ b/scripts/pack-launcher.mjs @@ -4,18 +4,21 @@ 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'); +// --linux: an x64 build with a lowercase executable; build it on Linux (see .github/workflows/linux.yml). +const linux = process.argv.includes('--linux'); 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: mac ? 'darwin' : 'win32', + platform: mac ? 'darwin' : linux ? 'linux' : 'win32', arch: mac ? 'universal' : 'x64', out: 'dist', overwrite: true, electronVersion, - icon: mac ? 'launcher/icons/launcher.icns' : 'launcher/icons/launcher.ico', + icon: mac ? 'launcher/icons/launcher.icns' : linux ? 'launcher/icons/launcher.png' : 'launcher/icons/launcher.ico', + ...(linux && { executableName: 'motion-launcher' }), asar: false, prune: false }); diff --git a/scripts/pack.mjs b/scripts/pack.mjs index ae0be17..1f0eab7 100644 --- a/scripts/pack.mjs +++ b/scripts/pack.mjs @@ -5,15 +5,18 @@ 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'); +// --linux: an x64 build with a lowercase executable; build it on Linux (see .github/workflows/linux.yml). +const linux = process.argv.includes('--linux'); const [out] = await packager({ dir: '.', name: 'Motion Studio', - platform: mac ? 'darwin' : 'win32', + platform: mac ? 'darwin' : linux ? 'linux' : 'win32', arch: mac ? 'universal' : 'x64', out: 'dist', overwrite: true, - icon: mac ? 'resources/icon.icns' : 'resources/icon.ico', + icon: mac ? 'resources/icon.icns' : linux ? 'resources/icon.png' : 'resources/icon.ico', + ...(linux && { executableName: 'motion-studio' }), asar: false, // Paths are relative to the project, starting with /. ignore: [/^\/dist(\/|$)/, /^\/launcher(\/|$)/, /^\/scripts(\/|$)/, /^\/docs(\/|$)/, /^\/test(\/|$)/, /^\/\.git/, /^\/\.claude(\/|$)/] diff --git a/src/server.mjs b/src/server.mjs index a733a04..45b00f0 100644 --- a/src/server.mjs +++ b/src/server.mjs @@ -72,7 +72,7 @@ function wavSeconds(file) { // Tool locations: settings first, then the RepFlow-promo venv this app grew out of. function tools(settings) { const legacy = join(homedir(), 'Documents', 'RepFlow-promo'); - const python = settings.python || [join(legacy, '.tts-venv', 'Scripts', 'python.exe')].find(existsSync) || ''; + const python = settings.python || [join(legacy, '.tts-venv', 'Scripts', 'python.exe'), join(legacy, '.tts-venv', 'bin', 'python')].find(existsSync) || ''; const piperVoices = settings.piperVoices || [join(legacy, 'pww', 'vo', 'voices')].find(existsSync) || ''; return { python, piperVoices, hf: settings.hyperframes || 'hyperframes@0.8.73' }; } diff --git a/test/launcher.test.mjs b/test/launcher.test.mjs index 9b07561..e54ace5 100644 --- a/test/launcher.test.mjs +++ b/test/launcher.test.mjs @@ -151,6 +151,14 @@ test('forPlatform: a Mac gets the mac asset and .app, an app without a Mac build assert.ok(new RegExp(forPlatform(real[0], 'darwin').asset).test('Motion-Studio-1.3.0-mac-universal.zip')); }); +test('forPlatform: Linux gets the linux asset and executable, an app without a Linux build is left out there', () => { + const ms = { id: 'ms', asset: '-win-x64', exe: 'MS.exe', linux: { asset: '-linux-x64', exe: 'ms' } }; + assert.deepEqual([forPlatform(ms, 'linux').asset, forPlatform(ms, 'linux').exe], ['-linux-x64', 'ms']); + assert.equal(forPlatform({ id: 'v', exe: 'V.exe' }, 'linux'), null); + const real = JSON.parse(readFileSync(new URL('../launcher/apps.json', import.meta.url), 'utf8')); + assert.ok(new RegExp(forPlatform(real[0], 'linux').asset).test('Motion-Studio-1.3.0-linux-x64.zip')); +}); + test('findExisting reads the version of an .app bundle', () => { const dir = mkdtempSync(join(tmpdir(), 'ml-mac-')); try { @@ -172,7 +180,8 @@ test('findExisting adopts a copy installed without the launcher, with its versio writeFileSync(join(appDir, 'resources', 'app', 'package.json'), JSON.stringify({ version: '0.1.0' })); const a = { id: 'visual', exe: 'Visual.exe' }; assert.equal(findExisting(a, ['C:\nope\Other.exe', join(dir, 'missing', 'Visual.exe')]), null); - const found = findExisting(a, ['C:\nope\Other.exe', join(appDir, 'visual.EXE')]); + // Windows and macOS match names regardless of case; Linux file names are case-sensitive. + const found = findExisting(a, ['C:\nope\Other.exe', join(appDir, process.platform === 'linux' ? 'Visual.exe' : 'visual.EXE')]); assert.equal(found.version, '0.1.0'); assert.equal(found.path, appDir); assert.equal(installedExe(dir, a, found), join(appDir, 'Visual.exe')); diff --git a/test/ui/editor.test.mjs b/test/ui/editor.test.mjs index 55d469a..28c062b 100644 --- a/test/ui/editor.test.mjs +++ b/test/ui/editor.test.mjs @@ -58,7 +58,8 @@ const W = 1400, PPS = 100; async function open(t, patch = {}) { await fetch(`${url}/api/videos/ui-test`, { method: 'PUT', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ ...spec, ...patch, id: 'ui-test' }) }); const ctx = await browser.newContext({ viewport: { width: W, height: 900 }, locale: 'nl-NL' }); - await ctx.addInitScript(pps => { localStorage.setItem('ms-pps', String(pps)); }, PPS); + // The media pane (clips, Demo) is a tab next to Add; the tests start on it. + await ctx.addInitScript(pps => { localStorage.setItem('ms-pps', String(pps)); localStorage.setItem('ms-lib-pane', 'media'); }, PPS); page = await ctx.newPage(); await page.goto(url); await page.locator('.tl-item.k-clips').first().waitFor(); @@ -247,7 +248,15 @@ uiTest('captions from audio: without Whisper the install dialog asks first, and await open(t, { audio: 'talk.wav' }); await page.getByRole('button', { name: /Uit audio|From audio/ }).click(); const dlg = page.locator('#dlg-whisper'); - await dlg.waitFor(); + if (process.platform === 'win32' && process.arch === 'x64') await dlg.waitFor(); + else { + // Elsewhere Whisper can't install itself: the app says so instead of asking. + await page.locator('#toast.err').waitFor(); + assert.match(await page.locator('#toast').textContent(), /whisper\.cpp/); + assert.equal(await dlg.evaluate(d => d.open), false); + assert.equal(await page.locator('#dlg-job').evaluate(d => d.open), false, 'no job was started'); + return; + } assert.equal(await dlg.locator('input[type=radio]').count(), 2); assert.equal(await dlg.locator('input[type=radio]:checked').getAttribute('value'), 'small'); await dlg.getByRole('button', { name: /Annuleren|Cancel/ }).click();