Skip to content

OpenReel Video - Professional browser-based video editor. Open source CapCut alternative. 100% browser-based, no installation, no cloud uploads, no watermarks.

TypeScript

Release prep: watch-folder fixes and GitHub Release fallback (#130)

Augustus Otuae098515182b
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index e7d186f5..4d5c6437 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -57,7 +57,10 @@ jobs:
needs: quality
runs-on: ${{ matrix.os }}
timeout-minutes: 60
+ permissions:
+ contents: write
env:
+ GH_TOKEN: ${{ github.token }}
R2_ACCOUNT_ID: ${{ secrets.R2_ACCOUNT_ID }}
R2_BUCKET: ${{ secrets.R2_BUCKET }}
AWS_ACCESS_KEY_ID: ${{ secrets.R2_ACCESS_KEY_ID }}
@@ -138,6 +141,7 @@ jobs:
xcrun stapler validate "$dmg"
done
fi
+ if [ -z "${R2_ACCOUNT_ID:-}" ]; then echo "::warning::R2 secrets are not set; installers go to the GitHub Release instead."; exit 0; fi
if [ "$R2_UPLOAD" != "true" ]; then exit 0; fi
endpoint="https://$R2_ACCOUNT_ID.r2.cloudflarestorage.com"
# Installers (for manual download from the landing) — always.
@@ -168,6 +172,7 @@ jobs:
unset CSC_LINK CSC_KEY_PASSWORD
fi
pnpm exec electron-builder --win --publish never
+ if [ -z "${R2_ACCOUNT_ID:-}" ]; then echo "::warning::R2 secrets are not set; installers go to the GitHub Release instead."; exit 0; fi
if [ "$R2_UPLOAD" != "true" ]; then exit 0; fi
endpoint="https://$R2_ACCOUNT_ID.r2.cloudflarestorage.com"
aws s3 sync release "s3://$R2_BUCKET/" --endpoint-url "$endpoint" \
@@ -181,6 +186,7 @@ jobs:
run: |
set -euo pipefail
pnpm exec electron-builder --linux --publish never
+ if [ -z "${R2_ACCOUNT_ID:-}" ]; then echo "::warning::R2 secrets are not set; installers go to the GitHub Release instead."; exit 0; fi
if [ "$R2_UPLOAD" != "true" ]; then exit 0; fi
endpoint="https://$R2_ACCOUNT_ID.r2.cloudflarestorage.com"
aws s3 sync release "s3://$R2_BUCKET/" --endpoint-url "$endpoint" \
@@ -188,6 +194,27 @@ jobs:
--include "OpenReel-*.deb" --include "latest-linux.yml" \
--include "*.blockmap"
+ # Without R2 (no dl.openreel.video upload), a tag still publishes: the
+ # installers are attached to the GitHub Release for the tag.
+ - name: Attach installers to the GitHub Release (no R2)
+ if: github.ref_type == 'tag'
+ working-directory: apps/desktop
+ shell: bash
+ run: |
+ set -euo pipefail
+ if [ -n "${R2_ACCOUNT_ID:-}" ]; then exit 0; fi
+ tag="${GITHUB_REF_NAME}"
+ shopt -s nullglob
+ files=(release/OpenReel-*.dmg release/OpenReel-*.exe release/OpenReel-*.AppImage release/OpenReel-*.deb)
+ if [ ${#files[@]} -eq 0 ]; then echo "::error::No installers found in release/"; exit 1; fi
+ for attempt in 1 2 3; do
+ gh release view "$tag" --repo "$GITHUB_REPOSITORY" >/dev/null 2>&1 && break
+ gh release create "$tag" --repo "$GITHUB_REPOSITORY" --title "OpenReel $tag" \
+ --notes "OpenReel Desktop $tag. These builds are unsigned: on macOS right-click the app and choose Open the first time; on Windows choose More info, then Run anyway." \
+ && break || sleep $((attempt * 5))
+ done
+ gh release upload "$tag" "${files[@]}" --repo "$GITHUB_REPOSITORY" --clobber
+
manifest:
name: Publish landing manifest.json
needs: build
@@ -213,6 +240,7 @@ jobs:
# Actions artifact storage quota entirely (it is account-wide and the
# ~600 MB/release installers exhaust it quickly).
run: |
+ if [ -z "${R2_ACCOUNT_ID:-}" ]; then echo "::warning::R2 secrets are not set; skipping manifest.json."; exit 0; fi
VERSION="$(node -p "require('./apps/desktop/package.json').version")"
mkdir -p artifacts
aws s3 sync "s3://$R2_BUCKET/" artifacts \
@@ -221,11 +249,13 @@ jobs:
ls -la artifacts
- name: Build manifest.json
run: |
+ if [ -z "${R2_ACCOUNT_ID:-}" ]; then exit 0; fi
RELEASE_DATE="$(date -u +%Y-%m-%dT%H:%M:%SZ)" \
node apps/desktop/scripts/build-manifest.mjs artifacts manifest.json
cat manifest.json
- name: Upload manifest.json to R2
run: |
+ if [ -z "${R2_ACCOUNT_ID:-}" ]; then exit 0; fi
aws s3 cp manifest.json "s3://$R2_BUCKET/manifest.json" \
--endpoint-url "https://$R2_ACCOUNT_ID.r2.cloudflarestorage.com" \
--no-progress --content-type application/json \
diff --git a/apps/desktop/src/main/watch/manager.ts b/apps/desktop/src/main/watch/manager.ts
index ea08a547..e2115599 100644
--- a/apps/desktop/src/main/watch/manager.ts
+++ b/apps/desktop/src/main/watch/manager.ts
@@ -14,6 +14,7 @@ import {
import { MEDIA_EXTENSIONS } from "../mcp/path-guard";
import { FolderScanner, DEFAULT_SCANNER_OPTIONS, nodeScannerFs, type ScanFile, type ScannerFs, type ScannerOptions } from "./folder-scanner";
import { fingerprintFile, type Ledger } from "./ledger";
+import { canonicalPath, samePath } from "./paths";
import { classifyFile, extensionOf, uniquePath } from "./render";
/**
@@ -144,10 +145,10 @@ export class WatchFolderManager {
/** Adds a folder the user picked. Throws a readable message when it is not usable. */
async add(kind: WatchFolderKind, folderPath: string, overrides: Partial<WatchFolderConfig> = {}): Promise<WatchFolderConfig> {
if (!path.isAbsolute(folderPath)) throw new Error("Choose a folder.");
- const real = await fs.promises.realpath(folderPath).catch(() => null);
+ const real = await canonicalPath(folderPath);
const stat = real ? await fs.promises.stat(real).catch(() => null) : null;
if (!real || !stat?.isDirectory()) throw new Error("That folder does not exist.");
- if (real === path.parse(real).root) throw new Error("Choose a folder, not the whole drive.");
+ if (samePath(real, path.parse(real).root)) throw new Error("Choose a folder, not the whole drive.");
const config: WatchFolderConfig = {
id: randomUUID(),
kind,
@@ -162,10 +163,12 @@ export class WatchFolderManager {
processExisting: false,
...overrides,
};
+ if (config.kind === "export" && config.outputDir && path.isAbsolute(config.outputDir)) config.outputDir = (await canonicalPath(config.outputDir)) ?? path.resolve(config.outputDir);
this.assertUsable(config);
this.folders = [...this.folders, config];
this.persist();
- void this.startFolder(config);
+ // Wait for the baseline: files that appear once add() has returned are never baselined away.
+ await this.startFolder(config);
return { ...config };
}
@@ -190,7 +193,7 @@ export class WatchFolderManager {
async setOutputDir(id: string, dir: string): Promise<WatchFolderConfig> {
const folder = this.folders.find((entry) => entry.id === id);
if (!folder || folder.kind !== "export") throw new Error("That watch folder no longer exists.");
- const real = await fs.promises.realpath(dir).catch(() => null);
+ const real = await canonicalPath(dir);
if (!real) throw new Error("That folder does not exist.");
const next = { ...folder, outputDir: real };
this.assertUsable(next, id);
@@ -250,15 +253,15 @@ export class WatchFolderManager {
private assertUsable(candidate: WatchFolderConfig, ignoreId?: string): void {
const others = this.folders.filter((folder) => folder.id !== ignoreId && folder.id !== candidate.id);
- if (others.some((folder) => folder.path === candidate.path)) throw new Error("That folder is already being watched.");
+ if (others.some((folder) => samePath(folder.path, candidate.path))) throw new Error("That folder is already being watched.");
if (candidate.kind === "export") {
if (!candidate.outputDir || !path.isAbsolute(candidate.outputDir)) throw new Error("Choose an output folder.");
// The output may live inside the watched folder (files there are not rescanned: only the top level is watched).
- if (others.some((folder) => folder.path === candidate.outputDir)) throw new Error("The output folder is watched by another watch folder; rendered files would be picked up again.");
- if (candidate.outputDir === candidate.path) throw new Error("Rendered files cannot go into the watched folder itself; pick a different output folder.");
+ if (others.some((folder) => samePath(folder.path, candidate.outputDir))) throw new Error("The output folder is watched by another watch folder; rendered files would be picked up again.");
+ if (samePath(candidate.outputDir, candidate.path)) throw new Error("Rendered files cannot go into the watched folder itself; pick a different output folder.");
}
for (const other of others) {
- if (other.kind === "export" && other.outputDir === candidate.path) throw new Error("That folder is the output of an export watch folder; watching it would re-process the rendered files.");
+ if (other.kind === "export" && other.outputDir && samePath(other.outputDir, candidate.path)) throw new Error("That folder is the output of an export watch folder; watching it would re-process the rendered files.");
}
}
diff --git a/apps/desktop/src/main/watch/paths.ts b/apps/desktop/src/main/watch/paths.ts
new file mode 100644
index 00000000..2702bd5f
--- /dev/null
+++ b/apps/desktop/src/main/watch/paths.ts
@@ -0,0 +1,31 @@
+import fs from "node:fs";
+import path from "node:path";
+
+/**
+ * Path identity for watch folders. Two spellings of the same place (case, separators, trailing slash,
+ * `.`/`..` segments) must compare equal, otherwise overlap and loop detection can be sidestepped on
+ * Windows. `api` is injectable so the Windows rules are unit-tested on any host.
+ */
+export type PathApi = Pick<typeof path, "resolve" | "sep" | "parse">;
+
+export function pathKey(input: string, api: PathApi = path): string {
+ let resolved = api.resolve(input);
+ const root = api.parse(resolved).root;
+ while (resolved.length > root.length && resolved.endsWith(api.sep)) resolved = resolved.slice(0, -1);
+ // Windows (backslash) volumes are case-insensitive.
+ return api.sep === "\\" ? resolved.toLowerCase() : resolved;
+}
+
+export function samePath(a: string, b: string, api: PathApi = path): boolean {
+ return pathKey(a, api) === pathKey(b, api);
+}
+
+/**
+ * The canonical on-disk spelling. `realpath.native` also expands Windows 8.3 short names (RUNNER~1)
+ * which the JS realpath leaves alone. Resolves to null when the path does not exist.
+ */
+export function canonicalPath(input: string): Promise<string | null> {
+ return new Promise((resolve) => {
+ fs.realpath.native(input, (error, resolved) => resolve(error ? null : resolved));
+ });
+}
diff --git a/apps/desktop/test/watch-folder-manager.test.ts b/apps/desktop/test/watch-folder-manager.test.ts
index a1d5c361..7b22c578 100644
--- a/apps/desktop/test/watch-folder-manager.test.ts
+++ b/apps/desktop/test/watch-folder-manager.test.ts
@@ -28,7 +28,7 @@ const OPTIONS = {
let root = "";
let managers: WatchFolderManager[] = [];
beforeEach(() => {
- root = fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(), "watch-mgr-")));
+ root = fs.realpathSync.native(fs.mkdtempSync(path.join(os.tmpdir(), "watch-mgr-")));
});
afterEach(() => {
for (const manager of managers) manager.stop();
@@ -104,7 +104,6 @@ describe("ingest watch folders", () => {
const dir = makeDir("in");
const h = build({});
await h.manager.add("ingest", dir, { bin: "Dailies" });
- await sleep(120);
fs.writeFileSync(path.join(dir, "a.mp4"), "video bytes");
await until("imported", () => h.ingested.length === 1);
await until("item done", () => itemsOf(h).some((i) => i.state === "done"));
@@ -156,7 +155,6 @@ describe("ingest watch folders", () => {
},
});
await h.manager.add("ingest", dir);
- await sleep(100);
fs.writeFileSync(path.join(dir, "late.mp4"), "bytes");
await until("waiting", () => itemsOf(h).some((i) => i.state === "waiting"));
expect(itemsOf(h)[0].detail).toMatch(/project/);
@@ -179,7 +177,6 @@ describe("ingest watch folders", () => {
},
});
await h.manager.add("ingest", dir);
- await sleep(100);
fs.writeFileSync(path.join(dir, "bad.mp4"), "bytes");
await until("failed", () => itemsOf(h).some((i) => i.state === "failed"));
expect(itemsOf(h)[0].error).toMatch(/decode/);
@@ -196,7 +193,6 @@ describe("ingest watch folders", () => {
const config = memoryConfig();
const first = build({ config, ledger: memoryLedger(ledgerBox) });
await first.manager.add("ingest", dir);
- await sleep(100);
fs.writeFileSync(path.join(dir, "take1.mp4"), "identical content");
await until("imported", () => first.ingested.length === 1);
first.manager.stop();
@@ -218,7 +214,6 @@ describe("ingest watch folders", () => {
const config = memoryConfig();
const first = build({ config });
await first.manager.add("ingest", dir);
- await sleep(200); // baselined (empty)
first.manager.stop();
fs.writeFileSync(path.join(dir, "while-closed.mp4"), "dropped while closed");
const second = build({ config });
@@ -229,7 +224,6 @@ describe("ingest watch folders", () => {
const dir = makeDir("in");
const h = build({});
const folder = await h.manager.add("ingest", dir);
- await sleep(100);
await h.manager.update(folder.id, { paused: true });
fs.writeFileSync(path.join(dir, "while-paused.mp4"), "bytes");
await sleep(600);
@@ -245,7 +239,6 @@ describe("ingest watch folders", () => {
const dir = makeDir("in");
const h = build({});
await h.manager.add("ingest", dir);
- await sleep(100);
fs.rmSync(dir, { recursive: true, force: true });
await until("missing", () => h.manager.snapshot().folders[0].status.state === "missing");
expect(h.manager.snapshot().folders[0].status.message).toMatch(/missing|mounted/);
@@ -258,7 +251,6 @@ describe("export watch folders", () => {
const out = makeDir("rendered");
const h = build({});
await h.manager.add("export", dir, { outputDir: out, presetId: "1080p-high" });
- await sleep(100);
fs.writeFileSync(path.join(dir, "interview.mov"), "raw camera file");
await until("done", () => itemsOf(h).some((i) => i.state === "done"));
expect(h.rendered).toEqual(["interview.mov"]);
@@ -278,7 +270,6 @@ describe("export watch folders", () => {
},
});
await h.manager.add("export", dir, { outputDir: path.join(root, "out") });
- await sleep(100);
fs.writeFileSync(path.join(dir, "broken.mov"), "garbage");
await until("failed", () => itemsOf(h).some((i) => i.state === "failed"));
expect(fs.existsSync(path.join(dir, "failed", "broken.mov"))).toBe(true);
@@ -292,7 +283,6 @@ describe("export watch folders", () => {
const dir = makeDir("export");
const h = build({});
await h.manager.add("export", dir, { outputDir: path.join(root, "out") });
- await sleep(100);
fs.writeFileSync(path.join(dir, "a.mov"), "same bytes in both");
await until("first done", () => itemsOf(h).some((i) => i.state === "done"));
fs.writeFileSync(path.join(dir, "b.mov"), "same bytes in both");
@@ -320,7 +310,6 @@ describe("export watch folders", () => {
},
});
await h.manager.add("export", dir, { outputDir: out });
- await sleep(100);
for (const name of ["one.mov", "two.mov", "three.mov"]) fs.writeFileSync(path.join(dir, name), `bytes of ${name}`);
await until("all done", () => itemsOf(h).filter((i) => i.state === "done").length === 3, 10000);
expect(peak).toBe(1);
@@ -332,7 +321,6 @@ describe("export watch folders", () => {
const out = makeDir("out");
const h = build({});
const folder = await h.manager.add("export", dir, { outputDir: out });
- await sleep(100);
fs.writeFileSync(path.join(dir, "cut.oreel"), "{}");
await sleep(600);
expect(h.rendered).toEqual([]);
@@ -346,7 +334,6 @@ describe("export watch folders", () => {
const dir = makeDir("export");
const h = build({});
await h.manager.add("export", dir, { outputDir: path.join(root, "out") });
- await sleep(100);
fs.writeFileSync(path.join(dir, "readme.txt"), "text");
fs.writeFileSync(path.join(dir, "still.png"), "image");
await sleep(700);
@@ -370,7 +357,6 @@ describe("export watch folders", () => {
},
});
const folder = await h.manager.add("export", dir, { outputDir: path.join(root, "out") });
- await sleep(100);
fs.writeFileSync(path.join(dir, "a.mov"), "aaa");
fs.writeFileSync(path.join(dir, "b.mov"), "bbb");
await until("a running", () => itemsOf(h).some((i) => i.state === "running"));
@@ -406,7 +392,6 @@ describe("validation and persistence", () => {
const store = createFileConfigStore(file);
const first = build({ config: store as ReturnType<typeof memoryConfig> });
const added = await first.manager.add("ingest", dir, { bin: "Cards" });
- await sleep(150); // the first scan records the baseline
await first.manager.update(added.id, { createProxies: true, paused: true });
first.manager.stop();
const second = build({ config: createFileConfigStore(file) as ReturnType<typeof memoryConfig> });
diff --git a/apps/desktop/test/watch-paths.test.ts b/apps/desktop/test/watch-paths.test.ts
new file mode 100644
index 00000000..dcf6d5d5
--- /dev/null
+++ b/apps/desktop/test/watch-paths.test.ts
@@ -0,0 +1,26 @@
+import path from "node:path";
+import { describe, expect, it } from "vitest";
+import { pathKey, samePath } from "../src/main/watch/paths";
+
+describe("watch path identity", () => {
+ it("treats Windows spellings of one folder as the same", () => {
+ const w = path.win32;
+ expect(samePath("C:\\Users\\Me\\Footage", "c:\\users\\me\\FOOTAGE", w)).toBe(true);
+ expect(samePath("C:\\Users\\Me\\Footage", "C:/Users/Me/Footage/", w)).toBe(true);
+ expect(samePath("C:\\Users\\Me\\Footage", "C:\\Users\\Me\\Other\\..\\Footage\\.", w)).toBe(true);
+ expect(samePath("C:\\Users\\Me\\Footage", "C:\\Users\\Me\\Footage2", w)).toBe(false);
+ expect(samePath("C:\\a", "D:\\a", w)).toBe(false);
+ });
+
+ it("keeps drive roots intact and strips only trailing separators below them", () => {
+ expect(pathKey("C:\\", path.win32)).toBe("c:\\");
+ expect(pathKey("C:\\a\\b\\\\", path.win32)).toBe("c:\\a\\b");
+ expect(pathKey("/", path.posix)).toBe("/");
+ expect(pathKey("/a/b/", path.posix)).toBe("/a/b");
+ });
+
+ it("stays case-sensitive on POSIX", () => {
+ expect(samePath("/Media/Cards", "/media/cards", path.posix)).toBe(false);
+ expect(samePath("/media/cards", "/media/./cards/", path.posix)).toBe(true);
+ });
+});
diff --git a/apps/desktop/test/watch-render.test.ts b/apps/desktop/test/watch-render.test.ts
index fab8edbf..39fafe08 100644
--- a/apps/desktop/test/watch-render.test.ts
+++ b/apps/desktop/test/watch-render.test.ts
@@ -63,13 +63,16 @@ describe("watch render planning", () => {
it("reads progress from ffmpeg's out_time and picks unique output names", () => {
expect(parseOutTimeSeconds("frame=1\nout_time_us=1500000\nprogress=continue\nout_time_us=2500000")).toBe(2.5);
expect(parseOutTimeSeconds("nothing")).toBeNull();
- const taken = new Set(["/o/a.mp4", "/o/a-1.mp4"]);
- expect(uniquePath("/o", "a", "mp4", (p) => taken.has(p))).toBe("/o/a-2.mp4");
- expect(uniquePath("/o", "b", "mp4", (p) => taken.has(p))).toBe("/o/b.mp4");
+ const taken = new Set([path.join("/o", "a.mp4"), path.join("/o", "a-1.mp4")]);
+ expect(uniquePath("/o", "a", "mp4", (p) => taken.has(p))).toBe(path.join("/o", "a-2.mp4"));
+ expect(uniquePath("/o", "b", "mp4", (p) => taken.has(p))).toBe(path.join("/o", "b.mp4"));
});
});
-describe.skipIf(!haveFfmpeg)("watch render with a real ffmpeg", () => {
+// Real encodes (1080p H.264 of a 2 s clip) are slow on shared CI runners; give them room.
+const FFMPEG_TEST_TIMEOUT = 60_000;
+
+describe.skipIf(!haveFfmpeg)("watch render with a real ffmpeg", { timeout: FFMPEG_TEST_TIMEOUT }, () => {
let dir = "";
let clip = "";
const deps: RenderDeps = {
@@ -83,7 +86,7 @@ describe.skipIf(!haveFfmpeg)("watch render with a real ffmpeg", () => {
isHardwareEncoder: () => false,
};
beforeAll(() => {
- dir = fs.mkdtempSync(path.join(os.tmpdir(), "watch-render-"));
+ dir = fs.realpathSync.native(fs.mkdtempSync(path.join(os.tmpdir(), "watch-render-")));
clip = path.join(dir, "source.mov");
execFileSync(FFMPEG, ["-v", "error", "-f", "lavfi", "-i", "testsrc2=size=1280x720:rate=25:duration=2", "-f", "lavfi", "-i", "sine=frequency=440:duration=2", "-c:v", "libx264", "-pix_fmt", "yuv420p", "-c:a", "aac", "-shortest", "-y", clip]);
});