Skip to content

Open source CapCut alternative.

TypeScript

feat(build): vendor bundled tools and publish them via CI

David Leae9d6e8d04bf
diff --git a/.github/workflows/publish-bundled-tools.yml b/.github/workflows/publish-bundled-tools.yml
new file mode 100644
index 00000000..fce62854
--- /dev/null
+++ b/.github/workflows/publish-bundled-tools.yml
@@ -0,0 +1,74 @@
+name: Publish Bundled Tools
+
+# Builds the prebuilt CLI tools bundle (ffmpeg, yt-dlp, lit, pdf-fill, qpdf, exiftool) from source and
+# publishes it as a GitHub release asset, then commits the refreshed bundled-tools.json so the shipped app
+# and the dev script download the new bundle on first run. This is the ONE place the heavy source build
+# runs — end users and dev machines only ever download the result.
+#
+# Runs on demand, and automatically whenever the tools recipe changes (a new ffmpeg, a pdf-fill tweak).
+
+on:
+ workflow_dispatch:
+ inputs:
+ version:
+ description: "Version for the tools bundle (default: today's UTC date)"
+ required: false
+ push:
+ branches: [main]
+ paths:
+ - scripts/fetch-bundled-tools.sh
+ - tools/pdf-fill/main.swift
+
+permissions:
+ contents: write
+
+concurrency:
+ group: publish-bundled-tools
+ cancel-in-progress: true
+
+jobs:
+ publish:
+ name: Build and publish tools
+ # macos-26 is arm64 with the Xcode SDK the in-repo pdf-fill source builds against.
+ runs-on: macos-26
+
+ steps:
+ - name: Check out repository
+ uses: actions/checkout@v6
+ with:
+ fetch-depth: 0
+ ref: ${{ github.event.repository.default_branch }}
+
+ - name: Determine version
+ id: ver
+ run: |
+ v="${{ github.event.inputs.version }}"
+ if [ -z "$v" ]; then v="$(date -u +'%Y.%m.%d')"; fi
+ echo "version=$v" >> "$GITHUB_OUTPUT"
+
+ # Same cache key as the nightly build, so the two share a single ffmpeg/Rust build. The key busts
+ # when the recipe or the in-repo pdf-fill source changes, which is also what triggers this workflow.
+ - name: Restore bundled tools cache
+ id: tools-cache
+ uses: actions/cache@v4
+ with:
+ path: vendor/donkey-tools
+ key: donkey-tools-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('scripts/fetch-bundled-tools.sh', 'tools/pdf-fill/main.swift') }}
+
+ - name: Build and publish the tools bundle
+ env:
+ GH_TOKEN: ${{ github.token }}
+ run: ./scripts/publish-bundled-tools.sh "${{ steps.ver.outputs.version }}"
+
+ - name: Commit the refreshed manifest
+ run: |
+ manifest="apps/Donkey/Sources/DonkeyRuntime/Resources/bundled-tools.json"
+ if git diff --quiet -- "$manifest"; then
+ echo "Manifest unchanged; nothing to commit."
+ exit 0
+ fi
+ git config user.name "github-actions[bot]"
+ git config user.email "github-actions[bot]@users.noreply.github.com"
+ git add "$manifest"
+ git commit -m "chore(tools): publish bundled tools ${{ steps.ver.outputs.version }} [skip ci]"
+ git push origin "HEAD:${{ github.event.repository.default_branch }}"
diff --git a/scripts/ensure-bundled-tools.sh b/scripts/ensure-bundled-tools.sh
new file mode 100755
index 00000000..afb925ba
--- /dev/null
+++ b/scripts/ensure-bundled-tools.sh
@@ -0,0 +1,102 @@
+#!/usr/bin/env bash
+#
+# Guarantees vendor/donkey-tools/ holds the command-line tools Donkey's capability
+# skills run by bare name (yt-dlp, ffmpeg, ...). The dev run script and the offline
+# packaging override both call this, so the tools are present without a manual step.
+#
+# Strategy: prefer the published prebuilt bundle named in bundled-tools.json (a fast
+# download, the same artifact the shipped app installs on first run). If nothing is
+# published yet, or the download/checksum fails, fall back to building from source via
+# fetch-bundled-tools.sh. Either way, fail loudly if a mandatory tool is still missing
+# rather than letting a build run without the media/pdf capabilities.
+set -uo pipefail
+
+SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
+ROOT_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"
+VENDOR_DIR="${DONKEY_TOOLS_DIR:-$ROOT_DIR/vendor/donkey-tools}"
+MANIFEST="$ROOT_DIR/apps/Donkey/Sources/DonkeyRuntime/Resources/bundled-tools.json"
+
+# Tools without which a build is not shippable: ffmpeg/ffprobe (media), yt-dlp (the
+# YouTube/download path), lit + pdf-fill (the pdf skill). Keep in sync with
+# fetch-bundled-tools.sh and BundledTools.swift.
+MANDATORY_TOOLS=(ffmpeg ffprobe yt-dlp lit pdf-fill)
+OPTIONAL_TOOLS=(qpdf exiftool)
+
+missing_of() {
+ local t out=()
+ for t in "$@"; do
+ [ -x "$VENDOR_DIR/$t" ] || out+=("$t")
+ done
+ printf '%s\n' "${out[@]:-}"
+}
+
+manifest_value() {
+ [ -f "$MANIFEST" ] || return 1
+ python3 -c "import json,sys; print(json.load(open(sys.argv[1])).get(sys.argv[2],''))" "$MANIFEST" "$1" 2>/dev/null
+}
+
+# Download + verify + extract the published prebuilt bundle into VENDOR_DIR. Returns
+# non-zero (so the caller falls back to a source build) when nothing is published yet.
+download_prebuilt() {
+ local url sha
+ url="$(manifest_value url || true)"
+ sha="$(manifest_value sha256 || true)"
+ if [ -z "$sha" ] || [ -z "$url" ]; then
+ echo "No published tools bundle yet (bundled-tools.json has no sha256)."
+ return 1
+ fi
+ local tmp stage got root
+ tmp="$(mktemp)"; stage="$(mktemp -d)"
+ echo "Downloading prebuilt tools: $url"
+ if ! curl -fsSL -o "$tmp" "$url"; then
+ echo "Download failed." >&2; rm -rf "$tmp" "$stage"; return 1
+ fi
+ got="$(shasum -a 256 "$tmp" | awk '{print $1}')"
+ if [ "$got" != "$sha" ]; then
+ echo "Checksum mismatch (expected $sha, got $got)." >&2; rm -rf "$tmp" "$stage"; return 1
+ fi
+ if ! tar -xzf "$tmp" -C "$stage"; then
+ echo "Extract failed." >&2; rm -rf "$tmp" "$stage"; return 1
+ fi
+ # The tarball may be flat (ffmpeg at the root) or wrapped in a top-level dir.
+ root="$stage"
+ [ -x "$stage/ffmpeg" ] || root="$(find "$stage" -maxdepth 2 -name ffmpeg -type f -exec dirname {} \; | head -1)"
+ if [ -z "$root" ] || [ ! -x "$root/ffmpeg" ]; then
+ echo "Archive did not contain ffmpeg." >&2; rm -rf "$tmp" "$stage"; return 1
+ fi
+ rm -rf "$VENDOR_DIR"; mkdir -p "$(dirname "$VENDOR_DIR")"; mv "$root" "$VENDOR_DIR"
+ rm -rf "$tmp" "$stage"
+ echo "Installed prebuilt tools into $VENDOR_DIR."
+}
+
+mandatory_missing=$(missing_of "${MANDATORY_TOOLS[@]}" | grep -c .)
+optional_missing=$(missing_of "${OPTIONAL_TOOLS[@]}" | grep -c .)
+if [ "$mandatory_missing" -eq 0 ] && [ "$optional_missing" -eq 0 ]; then
+ echo "Bundled tools present in $VENDOR_DIR"
+ exit 0
+fi
+
+# A custom DONKEY_TOOLS_DIR is a caller-supplied prebuilt set; validate, never build into it.
+if [ -n "${DONKEY_TOOLS_DIR:-}" ]; then
+ echo "ERROR: DONKEY_TOOLS_DIR=$VENDOR_DIR is missing required tools: $(missing_of "${MANDATORY_TOOLS[@]}" | tr '\n' ' ')" >&2
+ exit 1
+fi
+
+if ! download_prebuilt; then
+ echo "Building tools from source (one-time; ffmpeg builds from source and can take several minutes)..."
+ "$SCRIPT_DIR/fetch-bundled-tools.sh" || true
+fi
+
+still_mandatory=$(missing_of "${MANDATORY_TOOLS[@]}" | grep -v '^$' || true)
+if [ -n "$still_mandatory" ]; then
+ echo "ERROR: bundled tools still missing after install: $(echo "$still_mandatory" | tr '\n' ' ')" >&2
+ echo " Source build needs Homebrew + network; fix that and re-run." >&2
+ exit 1
+fi
+
+still_optional=$(missing_of "${OPTIONAL_TOOLS[@]}" | grep -v '^$' || true)
+if [ -n "$still_optional" ]; then
+ echo "Warning: optional bundled tools missing (skills fall back to installed copies): $(echo "$still_optional" | tr '\n' ' ')" >&2
+fi
+
+echo "Bundled tools ready in $VENDOR_DIR"
diff --git a/scripts/fetch-bundled-tools.sh b/scripts/fetch-bundled-tools.sh
index 60a2a2c8..6504b4b4 100755
--- a/scripts/fetch-bundled-tools.sh
+++ b/scripts/fetch-bundled-tools.sh
@@ -100,6 +100,9 @@ build_libass() {
# above). Built shared, then dylibbundled. ffmpeg is MANDATORY: any failure here aborts
# the whole vendoring run, because a bundle without ffmpeg is not shippable.
build_lgpl_ffmpeg() {
+ if [ -x "$VENDOR_DIR/ffmpeg" ] && [ -x "$VENDOR_DIR/ffprobe" ]; then
+ ok "ffmpeg (cached)"; ok "ffprobe (cached)"; return 0
+ fi
local ver="7.1.1"
local work="/tmp/ffmpeg-lgpl-build"
local brew_prefix; brew_prefix="$(brew --prefix)"
@@ -142,6 +145,7 @@ build_lgpl_ffmpeg() {
# bundling). MANDATORY: the pdf skill's extraction/OCR depends on it, and it
# replaces a separate tesseract.
build_liteparse() {
+ if [ -x "$VENDOR_DIR/lit" ]; then ok "lit (cached)"; return 0; fi
local ver="2.1.1"
command -v cargo >/dev/null 2>&1 || brew install rust >/dev/null 2>&1
command -v cmake >/dev/null 2>&1 || brew install cmake >/dev/null 2>&1
@@ -164,6 +168,7 @@ build_liteparse() {
# self-contained binary — no dylib bundling. MANDATORY: it is the pdf skill's
# headless form-fill/overlay path (litparse reads PDFs; this writes them).
build_pdf_fill() {
+ if [ -x "$VENDOR_DIR/pdf-fill" ]; then ok "pdf-fill (cached)"; return 0; fi
command -v swiftc >/dev/null 2>&1 || { echo "FATAL: swiftc unavailable for pdf-fill build" >&2; exit 1; }
if ! swiftc -O "$ROOT_DIR/tools/pdf-fill/main.swift" -o "$VENDOR_DIR/pdf-fill" 2>/tmp/pdf-fill-build.log; then
echo "FATAL: pdf-fill build failed; tail of /tmp/pdf-fill-build.log:" >&2
@@ -187,7 +192,9 @@ build_liteparse
build_pdf_fill
# --- qpdf (Homebrew) ---
-if ensure_brew_tool qpdf qpdf; then
+if [ -x "$VENDOR_DIR/qpdf" ]; then
+ ok "qpdf (cached)"
+elif ensure_brew_tool qpdf qpdf; then
bundle "$(brew --prefix qpdf)/bin/qpdf" qpdf
fi
@@ -206,18 +213,23 @@ fi
# optional tool used only when the user has it installed. ---
# --- yt-dlp: official self-contained macOS build (bundles its own Python) ---
-log "Downloading yt-dlp"
-if curl -fsSL -o "$VENDOR_DIR/yt-dlp" \
- "https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp_macos"; then
- chmod +x "$VENDOR_DIR/yt-dlp"
- ok "yt-dlp"
+if [ -x "$VENDOR_DIR/yt-dlp" ]; then
+ ok "yt-dlp (cached)"
else
- fail "yt-dlp" "download failed"
+ log "Downloading yt-dlp"
+ if curl -fsSL -o "$VENDOR_DIR/yt-dlp" \
+ "https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp_macos"; then
+ chmod +x "$VENDOR_DIR/yt-dlp"
+ ok "yt-dlp"
+ else
+ fail "yt-dlp" "download failed"
+ fi
fi
# --- exiftool: standalone Perl distribution, runs via system /usr/bin/perl ---
-log "Downloading exiftool"
-if curl -fsSL -o /tmp/exiftool.tar.gz \
+if [ -x "$VENDOR_DIR/exiftool" ]; then
+ ok "exiftool (cached)"
+elif log "Downloading exiftool"; curl -fsSL -o /tmp/exiftool.tar.gz \
"https://github.com/exiftool/exiftool/archive/refs/heads/master.tar.gz"; then
rm -rf /tmp/exiftool-src "$VENDOR_DIR/exiftool" "$VENDOR_DIR/lib/Image"
mkdir -p /tmp/exiftool-src
diff --git a/scripts/package-donkey-app.sh b/scripts/package-donkey-app.sh
index b9b1f31d..106212bf 100755
--- a/scripts/package-donkey-app.sh
+++ b/scripts/package-donkey-app.sh
@@ -190,18 +190,23 @@ cd "$BUILD_DIR"
echo "Compiling Donkey for Mac ..."
swift build -c release --product Donkey
-# Stage the bundled command-line tools (yt-dlp, ffmpeg, pandoc, qpdf, exiftool,
-# tesseract, magick) into the app so the capability skills work with nothing
-# installed. The arm64 binaries are NOT committed to the repo; point
-# DONKEY_TOOLS_DIR at a directory containing them (default: vendor/donkey-tools).
-# When that directory is absent this is a no-op, so a normal build still succeeds
-# and the skills fall back to whatever the user has installed.
+# The bundled command-line tools (yt-dlp, ffmpeg, qpdf, exiftool, ...) are NOT baked into
+# the app: the shipped app stays small and downloads a prebuilt, self-contained arm64 tools
+# bundle on first run (see BundledToolsInstaller + bundled-tools.json). The release pipeline
+# that *produces and publishes* that artifact is scripts/publish-bundled-tools.sh.
+#
+# As an offline/airgapped escape hatch, point DONKEY_TOOLS_DIR at a prebuilt directory to
+# bake it into the app anyway; otherwise this stages nothing and the app self-installs.
stage_bundled_tools() {
- local source_dir="${DONKEY_TOOLS_DIR:-$ROOT_DIR/vendor/donkey-tools}"
- if [ ! -d "$source_dir" ]; then
- echo "No bundled tools at $source_dir; skipping (capability skills will use installed tools)."
+ local source_dir="${DONKEY_TOOLS_DIR:-}"
+ if [ -z "$source_dir" ]; then
+ echo "Not baking tools into the app; it downloads them on first run."
return 0
fi
+ if [ ! -d "$source_dir" ]; then
+ echo "DONKEY_TOOLS_DIR=$source_dir does not exist." >&2
+ exit 1
+ fi
local dest_dir="$RESOURCES_DIR/donkey-tools"
rm -rf "$dest_dir"
mkdir -p "$dest_dir"
@@ -215,7 +220,7 @@ stage_bundled_tools() {
codesign --force --sign - "$tool" >/dev/null 2>&1 || true
done
fi
- echo "Staged bundled tools from $source_dir into $dest_dir."
+ echo "Baked bundled tools from $source_dir into $dest_dir (offline override)."
}
rm -rf "$APP_DIR"
diff --git a/scripts/publish-bundled-tools.sh b/scripts/publish-bundled-tools.sh
new file mode 100755
index 00000000..3c9bbe84
--- /dev/null
+++ b/scripts/publish-bundled-tools.sh
@@ -0,0 +1,69 @@
+#!/usr/bin/env bash
+#
+# Builds the prebuilt CLI tools bundle (ffmpeg, yt-dlp, ...) from source and publishes it as a GitHub
+# release asset, then rewrites bundled-tools.json (version, url, sha256) so the shipped app and the dev
+# script fetch the new bundle. This is the ONE place the heavy source build runs — end users and dev
+# machines only ever download the result.
+#
+# Run on an arm64 macOS build machine with Homebrew + Xcode and an authenticated `gh`. Usage:
+# scripts/publish-bundled-tools.sh [version] # version defaults to today's date (YYYY.MM.DD)
+#
+# After it finishes, commit the updated bundled-tools.json so the app ships pointing at the new asset.
+set -euo pipefail
+
+SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
+ROOT_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"
+VENDOR_DIR="$ROOT_DIR/vendor/donkey-tools"
+MANIFEST="$ROOT_DIR/apps/Donkey/Sources/DonkeyRuntime/Resources/bundled-tools.json"
+
+REPO="${DONKEY_TOOLS_REPO:-DonkeyUseCorp/Donkey}"
+ARCH="arm64"
+VERSION="${1:-$(date +%Y.%m.%d)}"
+TAG="bundled-tools-$VERSION"
+ASSET="donkey-tools-$VERSION-$ARCH.tar.gz"
+URL="https://github.com/$REPO/releases/download/$TAG/$ASSET"
+OUT="/tmp/$ASSET"
+
+MANDATORY_TOOLS=(ffmpeg ffprobe yt-dlp lit pdf-fill)
+
+echo "==> Building tools from source (idempotent; skips already-built)"
+"$SCRIPT_DIR/fetch-bundled-tools.sh"
+
+for t in "${MANDATORY_TOOLS[@]}"; do
+ [ -x "$VENDOR_DIR/$t" ] || { echo "FATAL: $t missing from $VENDOR_DIR after build" >&2; exit 1; }
+done
+
+# NOTE: for public distribution the binaries should be Developer ID-signed and the tarball notarized here,
+# or Gatekeeper will block first launch of the downloaded tools. Left as a deliberate follow-up; the
+# checksum in the manifest already guarantees integrity of the download.
+
+echo "==> Packaging $ASSET (bundle contents at archive root)"
+rm -f "$OUT"
+tar -czf "$OUT" -C "$VENDOR_DIR" .
+SHA="$(shasum -a 256 "$OUT" | awk '{print $1}')"
+echo " size=$(du -h "$OUT" | awk '{print $1}') sha256=$SHA"
+
+echo "==> Updating $MANIFEST"
+python3 - "$MANIFEST" "$VERSION" "$ARCH" "$URL" "$SHA" <<'PY'
+import json, sys
+path, version, arch, url, sha = sys.argv[1:6]
+m = json.load(open(path))
+m["version"] = version
+m["arch"] = arch
+m["url"] = url
+m["sha256"] = sha
+with open(path, "w") as f:
+ json.dump(m, f, indent=2)
+ f.write("\n")
+PY
+
+echo "==> Publishing to GitHub release $TAG ($REPO)"
+if ! gh release view "$TAG" --repo "$REPO" >/dev/null 2>&1; then
+ gh release create "$TAG" --repo "$REPO" --title "$TAG" \
+ --notes "Prebuilt Donkey CLI tools ($ARCH) — $VERSION."
+fi
+gh release upload "$TAG" "$OUT" --repo "$REPO" --clobber
+
+echo
+echo "Published $ASSET → $URL"
+echo "Now commit the updated $MANIFEST so the app ships pointing at this bundle."
diff --git a/scripts/run-donkey-dev.sh b/scripts/run-donkey-dev.sh
index 82f3f1da..c0e6b4a3 100755
--- a/scripts/run-donkey-dev.sh
+++ b/scripts/run-donkey-dev.sh
@@ -460,6 +460,14 @@ create_debug_app_bundle() {
exit 1
fi
+ # Stage the bundled CLI tools at Contents/Resources/donkey-tools so bundledToolsDirectory
+ # resolves in dev exactly as in release. Symlinked to the repo's vendor dir rather than
+ # copied: the bundle is rebuilt every run, and a ~250MB copy (+ re-sign) each time is
+ # needless when ad-hoc dev signing has no hardened-runtime constraint on the target.
+ if [ -d "$ROOT_DIR/vendor/donkey-tools" ]; then
+ ln -sfn "$ROOT_DIR/vendor/donkey-tools" "$RESOURCES_DIR/donkey-tools"
+ fi
+
sparkle_framework="$(find "$APP_DIR/.build" -path "*/debug/Sparkle.framework" -type d | head -n 1 || true)"
if [ -n "$sparkle_framework" ]; then
cp -R "$sparkle_framework" "$FRAMEWORKS_DIR/"
@@ -531,6 +539,12 @@ if [ ! -x "$DONKEY_BIN" ]; then
exit 1
fi
+# Make sure the bundled CLI tools (yt-dlp, ffmpeg, ...) are vendored before staging them
+# into the app, so a dev build behaves like release: capability skills run them by bare
+# name instead of hunting for Homebrew. Cached after the first run.
+echo "Ensuring bundled tools..."
+"$ROOT_DIR/scripts/ensure-bundled-tools.sh"
+
echo "Creating debug app bundle..."
create_debug_app_bundle