From be7f785b17d24660d4a06f90ee657a62b522a53d Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Sun, 11 Oct 2026 15:45:13 +0000 Subject: [PATCH] fix(gst): install and smoke-test packaged plugins (#5216) Backport to release. Conflicts in .github/justfile (kept release's ffi recipe beside gst-formula, dropped main-only sh/changed.test.py) and quest/m1/README.md (kept release's; it never listed gst-brew-path). (cherry picked from commit 98d2c0872be7f91f1fc587ec4ccfddde2701ab9b) Co-authored-by: GPT-6 Co-Authored-By: Claude Opus 5.5 --- .github/homebrew/Formula/moq-gst.rb.tmpl | 18 ++++---- .github/justfile | 6 +++ .github/workflows/moq-gst.yml | 7 ++++ doc/bin/gstreamer.md | 4 +- nix/overlay.nix | 8 +++- rs/moq-gst/README.md | 2 +- sh/gh/gst-formula.py | 34 ++++++++++++++++ sh/gh/gst-formula.test.py | 52 ++++++++++++++++++++++++ 8 files changed, 121 insertions(+), 10 deletions(-) create mode 100644 sh/gh/gst-formula.py create mode 100644 sh/gh/gst-formula.test.py diff --git a/.github/homebrew/Formula/moq-gst.rb.tmpl b/.github/homebrew/Formula/moq-gst.rb.tmpl index f78531620cb..59987c954b8 100644 --- a/.github/homebrew/Formula/moq-gst.rb.tmpl +++ b/.github/homebrew/Formula/moq-gst.rb.tmpl @@ -25,16 +25,17 @@ class MoqGst < Formula end def install - lib.install Dir["lib/libgstmoq.*"] + plugin = OS.mac? ? "libgstmoq.dylib" : "libgstmoq.so" + (lib/"gstreamer-1.0").install "lib/gstreamer-1.0/#{plugin}" end def caveats <<~EOS The moq GStreamer plugin is installed at: - #{opt_lib}/libgstmoq.#{OS.mac? ? "dylib" : "so"} + #{opt_lib}/gstreamer-1.0/libgstmoq.#{OS.mac? ? "dylib" : "so"} - For GStreamer to discover it, add this prefix to GST_PLUGIN_PATH: - export GST_PLUGIN_PATH="#{opt_lib}:$GST_PLUGIN_PATH" + For GStreamer to discover it, add this directory to GST_PLUGIN_PATH_1_0: + export GST_PLUGIN_PATH_1_0="#{opt_lib}/gstreamer-1.0:$GST_PLUGIN_PATH_1_0" Then verify with: gst-inspect-1.0 moq @@ -43,8 +44,11 @@ class MoqGst < Formula test do plugin = OS.mac? ? "libgstmoq.dylib" : "libgstmoq.so" - assert_predicate lib/plugin, :exist? - ENV["GST_PLUGIN_PATH"] = lib - system Formula["gstreamer"].opt_bin/"gst-inspect-1.0", "moq" + assert_predicate lib/"gstreamer-1.0"/plugin, :exist? + ENV["GST_REGISTRY"] = (testpath/"registry.bin").to_s + ENV["GST_PLUGIN_PATH_1_0"] = (lib/"gstreamer-1.0").to_s + ENV["GST_PLUGIN_SYSTEM_PATH_1_0"] = "" + output = shell_output("#{Formula["gstreamer"].opt_bin}/gst-inspect-1.0 moq") + assert_match (lib/"gstreamer-1.0"/plugin).to_s, output end end diff --git a/.github/justfile b/.github/justfile index df327809b99..d8eb716d16f 100644 --- a/.github/justfile +++ b/.github/justfile @@ -8,6 +8,7 @@ check: # Tests of the release tooling itself; nightly, not on every pull request. test: + python3 sh/gh/gst-formula.test.py python3 sh/gh/install-formula.test.py sh/gh/release.test.sh python3 sh/gh/ffi.test.py @@ -45,3 +46,8 @@ trigger-repo-publish *args: [positional-arguments] ffi *args: python3 sh/gh/ffi.py "$@" + +# Install the rendered GStreamer formula against the current macOS tarball. +[positional-arguments] +gst-formula *args: + python3 sh/gh/gst-formula.py "$@" diff --git a/.github/workflows/moq-gst.yml b/.github/workflows/moq-gst.yml index 7ce0e927052..09d8b173d80 100644 --- a/.github/workflows/moq-gst.yml +++ b/.github/workflows/moq-gst.yml @@ -89,6 +89,13 @@ jobs: tar -xzf "dist/moq-gst-v${VERSION}-${TARGET}.tar.gz" -C dist/ just rs gst-smoke "dist/moq-gst-v${VERSION}-${TARGET}/lib/gstreamer-1.0" + - name: Test Homebrew formula against tarball + if: runner.os == 'macOS' + env: + TARGET: ${{ matrix.target }} + VERSION: ${{ steps.parse.outputs.version }} + run: just gh gst-formula "$VERSION" "$TARGET" dist + - name: Upload artifact uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7 with: diff --git a/doc/bin/gstreamer.md b/doc/bin/gstreamer.md index e51a5fc5044..da8d677b8b2 100644 --- a/doc/bin/gstreamer.md +++ b/doc/bin/gstreamer.md @@ -25,7 +25,9 @@ gst-launch-1.0 -e videotestsrc is-live=true ! x264enc tune=zerolatency ! h264par ``` Install via `apt install gstreamer1.0-moq` or `dnf install gstreamer1-moq` -([Install](/setup/install)), or build with `cargo build -p moq-gst` and point +([Install](/setup/install)). With Homebrew, run `brew install moq-dev/tap/moq-gst` +and add `$(brew --prefix moq-gst)/lib/gstreamer-1.0` to `GST_PLUGIN_PATH_1_0`. +For a source build, run `cargo build -p moq-gst` and point `GST_PLUGIN_PATH_1_0` at the output. `http://` URLs pin the relay's certificate fingerprint automatically, so local development needs no TLS setup. That scheme is for localhost only: the fingerprint is fetched unauthenticated diff --git a/nix/overlay.nix b/nix/overlay.nix index e13c1f40516..4bf52e539ee 100644 --- a/nix/overlay.nix +++ b/nix/overlay.nix @@ -326,7 +326,7 @@ in # User-facing flake output. Bundles the plugin with wrapped gstreamer # tools so a single `nix shell .#moq-gst` gives you gst-inspect-1.0 / # gst-launch-1.0 that already know about the moq plugin plus the usual - # base/good/bad plugin set, matching the "install a plugin and the + # base/good/bad/ugly/libav plugin set, matching the "install a plugin and the # standard tools find it" UX. `nix shell` (unlike nix-shell / nix # develop) doesn't run nixpkgs setup-hooks, so a bare lib/gstreamer-1.0 # directory in $out isn't enough on its own. @@ -340,6 +340,8 @@ in "${final.gst_all_1.gst-plugins-base}/lib/gstreamer-1.0" "${final.gst_all_1.gst-plugins-good}/lib/gstreamer-1.0" "${final.gst_all_1.gst-plugins-bad}/lib/gstreamer-1.0" + "${final.gst_all_1.gst-plugins-ugly}/lib/gstreamer-1.0" + "${final.gst_all_1.gst-libav}/lib/gstreamer-1.0" ]; in final.symlinkJoin { @@ -353,6 +355,10 @@ in makeWrapper "${final.gst_all_1.gstreamer.bin}/bin/$tool" "$out/bin/$tool" \ --suffix GST_PLUGIN_SYSTEM_PATH_1_0 : "${pluginPaths}" done + export GST_REGISTRY="$TMPDIR/gst-registry.bin" + for element in moq x264enc avenc_aac avdec_h264; do + $out/bin/gst-inspect-1.0 "$element" > /dev/null + done ''; meta.mainProgram = "gst-inspect-1.0"; }; diff --git a/rs/moq-gst/README.md b/rs/moq-gst/README.md index 6e1ec211a76..5baafcc1e06 100644 --- a/rs/moq-gst/README.md +++ b/rs/moq-gst/README.md @@ -33,7 +33,7 @@ sudo dnf install gstreamer1-moq ### Nix (Linux or Apple Silicon macOS) -The `moq-gst` flake output bundles the plugin with wrappers around `gst-inspect-1.0` / `gst-launch-1.0` that preload moq + the standard `gst-plugins-{base,good,bad}` set, so no `GST_PLUGIN_PATH` setup is needed. +The `moq-gst` flake output bundles the plugin with wrappers around `gst-inspect-1.0` / `gst-launch-1.0` that preload moq + the standard `gst-plugins-{base,good,bad,ugly}` and `gst-libav` sets, so no `GST_PLUGIN_PATH` setup is needed. ```bash # Inspect: list moqsink + moqsrc. (Or one-shot: `nix run github:moq-dev/moq/release#moq-gst -- moq`.) diff --git a/sh/gh/gst-formula.py b/sh/gh/gst-formula.py new file mode 100644 index 00000000000..3a8d36fd44a --- /dev/null +++ b/sh/gh/gst-formula.py @@ -0,0 +1,34 @@ +#!/usr/bin/env python3 +"""Install and test the GStreamer formula with the just-built macOS tarball.""" + +import hashlib +import os +from pathlib import Path +import subprocess +import sys + +version, target, release_dir = sys.argv[1:] +if target != "aarch64-apple-darwin": + raise ValueError("the Homebrew smoke test requires the macOS arm64 archive") +archive = (Path(release_dir) / f"moq-gst-v{version}-{target}.tar.gz").resolve(strict=True) +template = Path(".github/homebrew/Formula/moq-gst.rb.tmpl").read_text() +sha = hashlib.sha256(archive.read_bytes()).hexdigest() +formula = template.replace("__VERSION__", version) +for platform in ["AARCH64_APPLE_DARWIN", "AARCH64_UNKNOWN_LINUX_GNU", "X86_64_UNKNOWN_LINUX_GNU"]: + formula = formula.replace(f"__SHA256_{platform}__", sha) +remote = f"https://github.com/moq-dev/moq/releases/download/moq-gst-v#{{version}}/moq-gst-v#{{version}}-{target}.tar.gz" +formula = formula.replace(remote, archive.as_uri()) +environment = dict(os.environ, HOMEBREW_NO_AUTO_UPDATE="1") +installed = subprocess.run(["brew", "list", "--formula", "--versions"], capture_output=True, text=True, env=environment, check=True) +if any(line.split()[0].split("/")[-1] == "moq-gst" for line in installed.stdout.splitlines() if line.strip()): + raise ValueError("moq-gst is already installed; run this test in a clean Homebrew environment") +subprocess.run(["brew", "tap-new", "moq-dev/ci-gst"], check=True, env=environment) +try: + tap = subprocess.check_output(["brew", "--repository", "moq-dev/ci-gst"], text=True, env=environment).strip() + output = Path(tap) / "Formula/moq-gst.rb" + output.write_text(formula) + subprocess.run(["brew", "install", "--build-from-source", "moq-dev/ci-gst/moq-gst"], check=True, env=environment) + subprocess.run(["brew", "test", "moq-dev/ci-gst/moq-gst"], check=True, env=environment) +finally: + subprocess.run(["brew", "uninstall", "--force", "moq-dev/ci-gst/moq-gst"], check=False, env=environment) + subprocess.run(["brew", "untap", "moq-dev/ci-gst"], check=True, env=environment) diff --git a/sh/gh/gst-formula.test.py b/sh/gh/gst-formula.test.py new file mode 100644 index 00000000000..9bb84bb919e --- /dev/null +++ b/sh/gh/gst-formula.test.py @@ -0,0 +1,52 @@ +"""Exercise the CI installer's ownership boundary without changing Homebrew.""" +import runpy +import subprocess +import sys +import tempfile +import unittest +from pathlib import Path +from unittest.mock import patch + +SCRIPT = Path(__file__).with_name('gst-formula.py') + + +class Installer(unittest.TestCase): + def invoke(self, directory, target='aarch64-apple-darwin'): + archive = directory / f'moq-gst-v1.2.3-{target}.tar.gz' + archive.write_bytes(b'archive fixture') + with patch.object(sys, 'argv', [str(SCRIPT), '1.2.3', target, str(directory)]): + runpy.run_path(str(SCRIPT), run_name='__main__') + + def test_existing_install_is_not_owned_or_removed(self): + with tempfile.TemporaryDirectory() as tmp, patch('subprocess.run', return_value=subprocess.CompletedProcess([], 0, 'moq-gst 1.0\n', '')) as run, patch('subprocess.check_output', return_value=tmp): + (Path(tmp) / 'Formula').mkdir() + with self.assertRaisesRegex(ValueError, 'already installed'): + self.invoke(Path(tmp)) + self.assertEqual([call.args[0] for call in run.call_args_list], [['brew', 'list', '--formula', '--versions']]) + + def test_other_target_refused_before_brew(self): + with tempfile.TemporaryDirectory() as tmp, patch('subprocess.run') as run: + with self.assertRaisesRegex(ValueError, 'macOS'): + self.invoke(Path(tmp), 'x86_64-unknown-linux-gnu') + run.assert_not_called() + + def test_failed_test_cleans_only_created_tap_and_install(self): + with tempfile.TemporaryDirectory() as tmp: + root = Path(tmp) + (root / 'Formula').mkdir() + def brew(command, **kwargs): + if command[1] == 'test': + raise subprocess.CalledProcessError(1, command) + return subprocess.CompletedProcess(command, 0, '', '') + with patch('subprocess.run', side_effect=brew) as run, patch('subprocess.check_output', return_value=str(root)): + with self.assertRaises(subprocess.CalledProcessError): + self.invoke(root) + commands = [call.args[0] for call in run.call_args_list] + self.assertEqual(commands[-2:], [['brew', 'uninstall', '--force', 'moq-dev/ci-gst/moq-gst'], ['brew', 'untap', 'moq-dev/ci-gst']]) + formula = (root / 'Formula/moq-gst.rb').read_text() + self.assertIn((root / 'moq-gst-v1.2.3-aarch64-apple-darwin.tar.gz').as_uri(), formula) + self.assertNotIn('__VERSION__', formula) + + +if __name__ == '__main__': + unittest.main()