Skip to content

AI media harness for planning, generating, and editing locally

TypeScript

Publish updater releases through GitHub CLI

Bittif9c7fce7d8bb
diff --git a/docs/updater.md b/docs/updater.md
index 761e282..4e32999 100644
--- a/docs/updater.md
+++ b/docs/updater.md
@@ -35,6 +35,40 @@ Do not regenerate the key for each release.
## Publish a Windows update
+To build and publish automatically, install [GitHub CLI](https://cli.github.com/)
+and sign in once with `gh auth login`, using an account with write access to
+`bitti-ai/slopus`. After updating the version as described below, commit the
+release changes (including the Cargo lockfile and runtime DLL, if changed),
+then push the matching tag. For example, for version 0.2.0:
+
+```powershell
+git tag v0.2.0
+git push origin v0.2.0
+.\release.cmd --publish
+```
+
+The command checks that the working tree is clean, the remote tag points to the
+current commit, the repository is public, and the stable version is newer than
+all published stable releases. It then builds using the existing updater signing
+key and validates the manifest's version, URLs and signature contents against
+the local artifacts. The private key remains on the build machine.
+
+Publishing creates a draft, uploads only this version's installers, their `.sig`
+files and portable ZIP, then uploads `latest.json`. After verifying that every
+expected asset is uploaded with the correct size, it publishes the draft as the
+latest stable release. This is when the existing updater endpoint begins serving
+the new manifest. Release notes from `UPDATE_NOTES_FILE` appear in both the app
+and the GitHub release. Installation still requires the user's action in the app.
+
+If an upload fails, the release stays a draft and the previous latest release
+remains available. Run `release.cmd --publish` again to rebuild and retry, or
+`node scripts/publish-release.mjs --publish` to retry with the same artifacts.
+Published versions are never overwritten. Automatic publishing supports the
+single Windows architecture produced by `release.cmd`; prereleases and releases
+combining architectures need a separate publishing workflow.
+
+For a local build followed by manual publishing, use the existing steps:
+
1. Set the same new version in `package.json`, `package-lock.json`,
`src-tauri/Cargo.toml`, and `src-tauri/tauri.conf.json`. Update the configured
window title too. Cargo updates its lockfile during the build.
@@ -68,4 +102,6 @@ signed build, launch the older updater-enabled build, then check, install and
verify the restarted version. A live upgrade cannot be tested until a newer
release is hosted.
-Reference: [Tauri updater documentation](https://v2.tauri.app/plugin/updater/).
+References: [Tauri updater documentation](https://v2.tauri.app/plugin/updater/),
+[GitHub CLI release creation](https://cli.github.com/manual/gh_release_create),
+[publishing a draft](https://cli.github.com/manual/gh_release_edit).
diff --git a/release.cmd b/release.cmd
index 8f5a198..72510d3 100644
--- a/release.cmd
+++ b/release.cmd
@@ -3,6 +3,15 @@ setlocal EnableExtensions
pushd "%~dp0" || exit /b 1
+set "PUBLISH_RELEASE="
+if /I "%~1"=="--publish" set "PUBLISH_RELEASE=1"
+if /I "%~1"=="--help" goto :help
+if not "%~1"=="" if not defined PUBLISH_RELEASE goto :usage_error
+if not "%~2"=="" goto :usage_error
+if defined PUBLISH_RELEASE (
+ node scripts\publish-release.mjs --check || goto :fail
+)
+
set "ROOT_DIR=%CD%"
set "ARTIFACTS_DIR=%ROOT_DIR%\artifacts"
set "BUNDLE_DIR=%ROOT_DIR%\src-tauri\target\release\bundle"
@@ -166,9 +175,25 @@ echo Install with the setup executable - it installs the WebView2 runtime if the
echo machine does not already have it. The portable archive assumes WebView2 is
echo already present.
echo.
+if defined PUBLISH_RELEASE (
+ node scripts\publish-release.mjs --publish || goto :fail
+)
+popd
+exit /b 0
+
+:help
+echo Usage: release.cmd [--publish]
+echo Build signed installers, updater manifest and portable ZIP.
+echo --publish uploads a draft to GitHub, then publishes it as latest.
+echo Requires gh auth login and a pushed version tag matching this commit.
popd
exit /b 0
+:usage_error
+echo Usage: release.cmd [--publish]
+popd
+exit /b 1
+
:write_readme
> "%~1" echo Slopus %APP_VERSION% ^(windows-%PACKAGE_ARCH%, portable^)
>>"%~1" echo.
diff --git a/scripts/publish-release.mjs b/scripts/publish-release.mjs
new file mode 100644
index 0000000..6ab7fba
--- /dev/null
+++ b/scripts/publish-release.mjs
@@ -0,0 +1,131 @@
+import { readFileSync, statSync } from 'node:fs';
+import { resolve } from 'node:path';
+import { spawnSync } from 'node:child_process';
+import { pathToFileURL } from 'node:url';
+import { releaseVersion } from './updater-manifest.mjs';
+
+const repository = 'bitti-ai/slopus';
+const endpoint = `https://github.com/${repository}/releases/latest/download/latest.json`;
+const stableVersion = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$/;
+
+function command(root, executable, args, input) {
+ const result = spawnSync(executable, args, {
+ cwd: root, encoding: 'utf8', input, windowsHide: true,
+ env: { ...process.env, GH_PROMPT_DISABLED: '1' },
+ });
+ if (result.error) throw new Error(`Could not run ${executable}: ${result.error.message}`);
+ if (result.status !== 0) throw new Error(`${executable} ${args.slice(0, 2).join(' ')} failed: ${result.stderr?.trim() || result.stdout?.trim()}`);
+ return result.stdout.trim();
+}
+
+export function checkReleaseOrder(version, releases) {
+ if (!stableVersion.test(version)) throw new Error('Automatic publishing requires a stable X.Y.Z version.');
+ for (const release of releases) {
+ if (release.draft || release.prerelease) continue;
+ const previous = release.tag_name.replace(/^v/, '');
+ if (!stableVersion.test(previous)) throw new Error(`Cannot compare published version ${release.tag_name}.`);
+ const a = version.split('.').map(BigInt), b = previous.split('.').map(BigInt);
+ const differing = a.findIndex((part, index) => part !== b[index]);
+ if (differing === -1 || a[differing] < b[differing]) {
+ throw new Error(`Version ${version} must be newer than published release ${release.tag_name}. Bump the version before publishing.`);
+ }
+ }
+}
+
+export function releaseFiles(root, version) {
+ const directory = resolve(root, 'artifacts');
+ const manifestPath = resolve(directory, 'latest.json');
+ const manifest = JSON.parse(readFileSync(manifestPath, 'utf8'));
+ if (manifest.version !== version) throw new Error('latest.json does not match the release version. Rebuild with release.cmd.');
+ if (typeof manifest.notes !== 'string' || !Number.isFinite(Date.parse(manifest.pub_date))) throw new Error('Invalid updater notes or publication date.');
+ const platforms = Object.entries(manifest.platforms ?? {});
+ const generic = platforms.filter(([key]) => /^windows-(x86_64|aarch64|i686)$/.test(key));
+ if (generic.length !== 1) throw new Error('Automatic publishing requires a single Windows architecture.');
+ const target = generic[0][0];
+ const arch = { 'windows-x86_64': 'x64', 'windows-aarch64': 'arm64', 'windows-i686': 'x86' }[target];
+ const stem = `Slopus-${version}-windows-${arch}`;
+ const names = new Set();
+ for (const [key, entry] of platforms) {
+ if (![target, `${target}-nsis`, `${target}-msi`].includes(key)) throw new Error(`Unexpected updater target: ${key}`);
+ const name = key.endsWith('-msi') ? `${stem}.msi` : `${stem}-setup.exe`;
+ const expected = `https://github.com/${repository}/releases/download/v${version}/${encodeURIComponent(name)}`;
+ if (entry.url !== expected) throw new Error(`Updater URL does not match this release: ${key}`);
+ const signature = readFileSync(resolve(directory, `${name}.sig`), 'utf8').trim();
+ if (!signature || entry.signature !== signature) throw new Error(`Updater signature mismatch: ${name}`);
+ names.add(name); names.add(`${name}.sig`);
+ }
+ if (!manifest.platforms[`${target}-nsis`]) throw new Error('Missing NSIS updater target.');
+ names.add(`${stem}-portable.zip`);
+ // Upload the manifest last. Only this explicit list can become release assets.
+ names.add('latest.json');
+ const files = [...names].map((name) => {
+ const path = resolve(directory, name);
+ const stat = statSync(path);
+ if (!stat.isFile() || !stat.size) throw new Error(`Missing or empty release artifact: ${name}`);
+ return { name, path, size: stat.size };
+ });
+ return { manifest, files };
+}
+
+export function publishRelease(root, { checkOnly = false, run = (exe, args, input) => command(root, exe, args, input) } = {}) {
+ const version = releaseVersion(root), tag = `v${version}`;
+ if (!stableVersion.test(version)) throw new Error('Automatic publishing requires a stable X.Y.Z version.');
+ const config = JSON.parse(readFileSync(resolve(root, 'src-tauri/tauri.conf.json'), 'utf8'));
+ if (config.plugins.updater.endpoints.length !== 1 || config.plugins.updater.endpoints[0] !== endpoint) {
+ throw new Error('The updater endpoint must point to this repository’s latest.json.');
+ }
+ const gh = (args, input) => run('gh', args, input);
+ const api = (path, ...args) => JSON.parse(gh(['api', `repos/${repository}${path}`, ...args]));
+ const releases = () => api('/releases?per_page=100', '--paginate', '--slurp').flat();
+ const check = () => {
+ if (run('git', ['status', '--porcelain']).trim()) throw new Error('Commit your changes before publishing so the release matches its tag.');
+ const head = run('git', ['rev-parse', 'HEAD']).trim();
+ let object = api(`/git/ref/tags/${tag}`).object;
+ for (let depth = 0; object.type === 'tag' && depth < 10; depth++) object = api(`/git/tags/${object.sha}`).object;
+ if (object.type !== 'commit' || object.sha !== head) throw new Error(`Push tag ${tag} pointing to the current commit before publishing.`);
+ const all = releases();
+ checkReleaseOrder(version, all);
+ const existing = all.find((release) => release.tag_name === tag);
+ if (existing && (!existing.draft || existing.prerelease)) throw new Error(`${tag} must be an unpublished stable draft.`);
+ return existing;
+ };
+ // Check GitHub access before the expensive build. Never read or upload the signing key.
+ const repo = api('');
+ if (repo.private) throw new Error('The updater requires publicly downloadable releases.');
+ if (!repo.permissions?.push) throw new Error('GitHub write access is required. Sign in with gh auth login.');
+ let draft = check();
+ if (checkOnly) return `Ready to publish ${tag} to ${repository}.`;
+ const { manifest, files } = releaseFiles(root, version);
+ if (!draft) {
+ gh(['release', 'create', tag, '--repo', repository, '--draft', '--verify-tag', '--title', `Slopus ${version}`, '--notes-file', '-'], manifest.notes);
+ draft = check();
+ }
+ if (!draft?.draft) throw new Error('Could not find the draft release.');
+ const assets = () => api(`/releases/${draft.id}/assets?per_page=100`, '--paginate', '--slurp').flat();
+ const expected = new Set(files.map(({ name }) => name));
+ if (assets().some((asset) => !expected.has(asset.name))) throw new Error('The draft contains unexpected assets. Review it before retrying.');
+ gh(['release', 'edit', tag, '--repo', repository, '--notes-file', '-'], manifest.notes);
+ // Replacement is allowed only while the release is a draft, making interrupted uploads retryable.
+ gh(['release', 'upload', tag, ...files.slice(0, -1).map(({ path }) => path), '--repo', repository, '--clobber']);
+ gh(['release', 'upload', tag, files.at(-1).path, '--repo', repository, '--clobber']);
+ const uploaded = assets();
+ for (const file of files) {
+ const asset = uploaded.find(({ name }) => name === file.name);
+ if (!asset || asset.state !== 'uploaded' || asset.size !== file.size) throw new Error(`Upload verification failed: ${file.name}. Release remains a draft.`);
+ }
+ if (!check()?.draft) throw new Error('The release is no longer a draft.');
+ // This is the only step that makes the new manifest visible to installed apps.
+ gh(['release', 'edit', tag, '--repo', repository, '--draft=false', '--prerelease=false', '--latest', '--verify-tag']);
+ return `Published https://github.com/${repository}/releases/tag/${tag}`;
+}
+
+if (process.argv[1] && import.meta.url === pathToFileURL(resolve(process.argv[1])).href) {
+ try {
+ const args = process.argv.slice(2);
+ if (args.length !== 1 || !['--check', '--publish'].includes(args[0])) throw new Error('Usage: node scripts/publish-release.mjs --check|--publish');
+ console.log(publishRelease(resolve(import.meta.dirname, '..'), { checkOnly: args[0] === '--check' }));
+ } catch (error) {
+ console.error(error.message);
+ process.exitCode = 1;
+ }
+}
diff --git a/scripts/publish-release.test.mjs b/scripts/publish-release.test.mjs
new file mode 100644
index 0000000..62f2218
--- /dev/null
+++ b/scripts/publish-release.test.mjs
@@ -0,0 +1,142 @@
+import { mkdtempSync, mkdirSync, writeFileSync, readFileSync, rmSync } from 'node:fs';
+import { tmpdir } from 'node:os';
+import { join, resolve, dirname, basename } from 'node:path';
+import { afterEach, expect, it, vi } from 'vitest';
+import { createManifest } from './updater-manifest.mjs';
+import { checkReleaseOrder, publishRelease, releaseFiles } from './publish-release.mjs';
+
+const directories = [];
+afterEach(() => {
+ for (const directory of directories.splice(0)) {
+ if (dirname(resolve(directory)) !== resolve(tmpdir()) || !basename(directory).startsWith('slopus-publish-')) throw new Error('Unexpected temporary path.');
+ rmSync(directory, { recursive: true });
+ }
+});
+
+function fixture() {
+ const root = mkdtempSync(join(tmpdir(), 'slopus-publish-'));
+ directories.push(root);
+ mkdirSync(join(root, 'src-tauri'));
+ mkdirSync(join(root, 'artifacts'));
+ writeFileSync(join(root, 'package.json'), JSON.stringify({ version: '0.2.0' }));
+ writeFileSync(join(root, 'src-tauri/Cargo.toml'), 'version = "0.2.0"');
+ writeFileSync(join(root, 'src-tauri/tauri.conf.json'), JSON.stringify({
+ version: '0.2.0', bundle: { createUpdaterArtifacts: true },
+ plugins: { updater: { pubkey: 'public key', endpoints: ['https://github.com/bitti-ai/slopus/releases/latest/download/latest.json'] } },
+ }));
+ const setupPath = join(root, 'artifacts/Slopus-0.2.0-windows-x64-setup.exe');
+ const msiPath = join(root, 'artifacts/Slopus-0.2.0-windows-x64.msi');
+ for (const path of [setupPath, msiPath]) {
+ writeFileSync(path, 'installer');
+ writeFileSync(`${path}.sig`, 'signature\n');
+ }
+ writeFileSync(join(root, 'artifacts/Slopus-0.2.0-windows-x64-portable.zip'), 'zip');
+ // Unrelated artifacts and secrets must never be included by a wildcard upload.
+ writeFileSync(join(root, 'artifacts/private.key'), 'secret');
+ writeFileSync(join(root, 'artifacts/Slopus-0.1.0-windows-x64-setup.exe'), 'old');
+ const manifest = createManifest({ version: '0.2.0', arch: 'x64', setupPath, msiPath, notes: 'First line\nSecond line `literal` $(literal)' });
+ const manifestPath = join(root, 'artifacts/latest.json');
+ writeFileSync(manifestPath, JSON.stringify(manifest));
+ const state = { releases: [], uploaded: [], dirty: false, sha: 'head', failUpload: false, failManifest: false, corrupt: false, private: false };
+ const run = vi.fn((exe, args) => {
+ if (exe === 'git') return args[0] === 'status' ? (state.dirty ? ' M file' : '') : 'head';
+ if (args[0] === 'api') {
+ const path = args[1].replace('repos/bitti-ai/slopus', '');
+ if (!path) return JSON.stringify({ private: state.private, permissions: { push: true } });
+ if (path === '/git/ref/tags/v0.2.0') return JSON.stringify({ object: { type: 'commit', sha: state.sha } });
+ if (path.startsWith('/releases?')) return JSON.stringify([state.releases]);
+ if (path.includes('/assets?')) return JSON.stringify([state.uploaded]);
+ }
+ if (args[0] === 'release' && args[1] === 'create') state.releases.push({ id: 1, tag_name: 'v0.2.0', draft: true, prerelease: false });
+ else if (args[0] === 'release' && args[1] === 'upload') {
+ if (state.failUpload) throw new Error('Network failed');
+ if (state.failManifest && args.some((arg) => basename(arg) === 'latest.json')) throw new Error('Manifest upload failed');
+ for (const path of args.slice(3, args.indexOf('--repo'))) {
+ const name = basename(path);
+ state.uploaded = state.uploaded.filter((asset) => asset.name !== name);
+ state.uploaded.push({ name, state: 'uploaded', size: state.corrupt ? 0 : readFileSync(path).length });
+ }
+ } else if (args[0] !== 'release' || args[1] !== 'edit') throw new Error(`Unexpected command: ${exe} ${args}`);
+ return '';
+ });
+ return { root, manifest, manifestPath, state, run };
+}
+
+const mutations = (run) => run.mock.calls.filter(([exe, args]) => exe === 'gh' && args[0] === 'release');
+const published = (run) => mutations(run).some(([, args]) => args.includes('--draft=false'));
+
+it('uploads only current artifacts, puts the manifest last, and publishes after verification', () => {
+ const { root, run, manifest } = fixture();
+ expect(publishRelease(root, { run })).toContain('/releases/tag/v0.2.0');
+ const calls = mutations(run);
+ expect(calls[0][1]).toContain('--draft');
+ expect(calls[0][2]).toBe(manifest.notes);
+ const uploads = calls.filter(([, args]) => args[1] === 'upload');
+ expect(uploads).toHaveLength(2);
+ expect(uploads[0][1]).not.toContain(join(root, 'artifacts/latest.json'));
+ expect(uploads[1][1][3]).toBe(join(root, 'artifacts/latest.json'));
+ expect(JSON.stringify(uploads)).not.toMatch(/private\.key|0\.1\.0/);
+ expect(calls.at(-1)[1]).toEqual(expect.arrayContaining(['--draft=false', '--latest', '--verify-tag']));
+});
+
+it('checks prerequisites without creating or uploading a release', () => {
+ const { root, run } = fixture();
+ publishRelease(root, { run, checkOnly: true });
+ expect(mutations(run)).toEqual([]);
+});
+
+it.each(['failUpload', 'failManifest', 'corrupt'])('keeps the release in draft when %s occurs', (failure) => {
+ const { root, run, state } = fixture();
+ state[failure] = true;
+ expect(() => publishRelease(root, { run })).toThrow();
+ expect(published(run)).toBe(false);
+ expect(state.releases[0].draft).toBe(true);
+ state[failure] = false;
+ publishRelease(root, { run });
+ expect(mutations(run).filter(([, args]) => args[1] === 'create')).toHaveLength(1);
+ expect(published(run)).toBe(true);
+});
+
+it('refuses to mix existing draft assets from another build or architecture', () => {
+ const { root, run, state } = fixture();
+ state.releases.push({ id: 1, tag_name: 'v0.2.0', draft: true, prerelease: false });
+ state.uploaded.push({ name: 'Slopus-0.2.0-windows-arm64-setup.exe', size: 10, state: 'uploaded' });
+ expect(() => publishRelease(root, { run })).toThrow('unexpected assets');
+ expect(mutations(run)).toEqual([]);
+});
+
+it.each(['version', 'url', 'signature', 'platform'])('rejects a mismatched manifest %s before writing to GitHub', (field) => {
+ const { root, run, manifest, manifestPath } = fixture();
+ if (field === 'version') manifest.version = '0.1.0';
+ if (field === 'url') manifest.platforms['windows-x86_64'].url = 'https://github.com/other/repo/releases/download/v0.2.0/setup.exe';
+ if (field === 'signature') manifest.platforms['windows-x86_64'].signature = 'wrong';
+ if (field === 'platform') manifest.platforms['windows-aarch64'] = manifest.platforms['windows-x86_64'];
+ writeFileSync(manifestPath, JSON.stringify(manifest));
+ expect(() => publishRelease(root, { run })).toThrow();
+ expect(mutations(run)).toEqual([]);
+});
+
+it('rejects missing artifacts', () => {
+ const { root } = fixture();
+ writeFileSync(join(root, 'artifacts/Slopus-0.2.0-windows-x64-portable.zip'), '');
+ expect(() => releaseFiles(root, '0.2.0')).toThrow('empty');
+});
+
+it.each(['dirty', 'tag', 'private', 'published'])('blocks %s releases before mutation', (failure) => {
+ const { root, run, state } = fixture();
+ if (failure === 'dirty') state.dirty = true;
+ if (failure === 'tag') state.sha = 'other';
+ if (failure === 'private') state.private = true;
+ if (failure === 'published') state.releases.push({ tag_name: 'v0.2.0', draft: false, prerelease: false });
+ expect(() => publishRelease(root, { run })).toThrow();
+ expect(mutations(run)).toEqual([]);
+});
+
+it('compares versions numerically and excludes prereleases from the stable channel', () => {
+ const releases = [{ tag_name: 'v0.9.0', draft: false, prerelease: false }];
+ expect(() => checkReleaseOrder('0.10.0', releases)).not.toThrow();
+ expect(() => checkReleaseOrder('0.8.0', releases)).toThrow('newer');
+ expect(() => checkReleaseOrder('0.9.0', releases)).toThrow('newer');
+ expect(() => checkReleaseOrder('1.0.0-beta.1', releases)).toThrow('stable');
+ expect(() => checkReleaseOrder('0.10.0', [{ tag_name: 'v1.0.0-beta.1', prerelease: true }])).not.toThrow();
+});