From 7481017465addf6a4fb26820e84f0d6cb592ea8a Mon Sep 17 00:00:00 2001 From: zhifu gao Date: Wed, 2 Dec 2026 02:05:24 +0800 Subject: [PATCH] test(release): verify video exports from both source archives Run the model-free CLI regression from each extracted archive and bind the publisher to their accepted checksums. Distinguish source support from v2.2.1. Signed-off-by: LauraGPT --- .github/actions/clip-export/action.yml | 31 ++++++++++++++++ .github/workflows/release.yml | 22 ++++++++++++ .github/workflows/tests.yml | 13 ++----- README.md | 2 ++ README_zh.md | 2 ++ scripts/verify_release_cli.py | 49 ++++++++++++++++++++++++++ tests/test_release_contract.py | 20 +++++++++++ 7 files changed, 128 insertions(+), 11 deletions(-) create mode 100644 .github/actions/clip-export/action.yml create mode 100644 scripts/verify_release_cli.py diff --git a/.github/actions/clip-export/action.yml b/.github/actions/clip-export/action.yml new file mode 100644 index 0000000..a9ebd52 --- /dev/null +++ b/.github/actions/clip-export/action.yml @@ -0,0 +1,31 @@ +name: Check source and packaged video export +description: Build both FunClip release archives and exercise the CLI inside each one. +outputs: + sha256: + description: SHA-256 of the verified two-archive checksum file + value: ${{ steps.archives.outputs.sha256 }} +runs: + using: composite + steps: + - uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0 + with: + python-version: "3.12" + - name: Install clipping dependencies (no ASR models) + shell: bash + run: | + python -m pip install --disable-pip-version-check \ + pytest==8.3.5 moviepy==1.0.3 numpy==1.26.4 librosa==0.11.0 soundfile pillow PyYAML + python -m pip check + - name: Test the CLI from source + shell: bash + env: + HF_HUB_OFFLINE: "1" + run: python -m pytest -q tests/test_cli_video_clip.py + - name: Test the CLI from both built archives + id: archives + shell: bash + run: | + dist="$RUNNER_TEMP/funclip-release-assets" + python scripts/build_release_assets.py --ref "$GITHUB_SHA" --output-dir "$dist" + python scripts/verify_release_cli.py "$dist" + echo "sha256=$(sha256sum "$dist/SHA256SUMS" | cut -d' ' -f1)" >> "$GITHUB_OUTPUT" diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 3df10a3..0f756df 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -12,7 +12,21 @@ concurrency: cancel-in-progress: false jobs: + archives: + runs-on: ubuntu-latest + permissions: + contents: read + outputs: + sha256: ${{ steps.verify.outputs.sha256 }} + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + - id: verify + uses: ./.github/actions/clip-export + release: + needs: archives runs-on: ubuntu-latest steps: - name: Check out tagged source @@ -41,6 +55,14 @@ jobs: - name: Build release archives run: python scripts/build_release_assets.py --ref "$GITHUB_SHA" --output-dir dist + - name: Match the archive bytes accepted by the read-only job + working-directory: dist + env: + EXPECTED_SHA256: ${{ needs.archives.outputs.sha256 }} + run: | + printf '%s SHA256SUMS\n' "$EXPECTED_SHA256" | sha256sum --strict --check - + sha256sum --strict --check SHA256SUMS + - name: Publish GitHub release env: GH_TOKEN: ${{ github.token }} diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 06212a5..7dc9813 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -40,15 +40,6 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - - uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0 with: - python-version: "3.12" - - name: Install clipping dependencies (no ASR models) - run: | - python -m pip install --disable-pip-version-check \ - pytest==8.3.5 moviepy==1.0.3 numpy==1.26.4 librosa==0.11.0 soundfile pillow PyYAML - python -m pip check - - name: Export clips from saved recognition results - env: - HF_HUB_OFFLINE: "1" - run: python -m pytest -q tests/test_cli_video_clip.py + persist-credentials: false + - uses: ./.github/actions/clip-export diff --git a/README.md b/README.md index f49848b..6474bb9 100644 --- a/README.md +++ b/README.md @@ -177,6 +177,8 @@ python funclip/videoclipper.py --stage 2 \ --output_file './output/res.mp4' ``` +**Version:** The exact output paths and exit behavior below require [commit 7c63759 or later](https://github.com/modelscope/FunClip/tree/7c63759dee98c74635dcc8e388299f88bb183239). The v2.2.1 release archives predate this fix. + For this **stage-2 video** command, exit code 0 means both `./output/res.mp4` and `./output/res.srt` were written. Choose a fresh output name: an existing MP4 or SRT is not overwritten when you specify `--output_file`. If no text matches, the command exits nonzero without creating either file. Copy the words from the saved transcript before retrying. diff --git a/README_zh.md b/README_zh.md index 743c2eb..5b96814 100644 --- a/README_zh.md +++ b/README_zh.md @@ -190,6 +190,8 @@ python funclip/videoclipper.py --stage 2 \ --output_file './output/res.mp4' ``` +**适用版本:** 下文的输出路径和退出状态从[提交 7c63759](https://github.com/modelscope/FunClip/tree/7c63759dee98c74635dcc8e388299f88bb183239) 起生效。v2.2.1 发布包不含此修复。 + 这条**第二阶段视频剪辑**命令退出码为 0 时,应同时得到 `./output/res.mp4` 和 `./output/res.srt`。使用 `--output_file` 时请选择新文件名:已有的视频或同名字幕均不会被覆盖。未匹配到文字时,命令以非零状态退出,不生成这两个文件;请先从已保存的转写结果核对选词,再重试。 ### C.通过创空间与Space体验FunClip diff --git a/scripts/verify_release_cli.py b/scripts/verify_release_cli.py new file mode 100644 index 0000000..80621fd --- /dev/null +++ b/scripts/verify_release_cli.py @@ -0,0 +1,49 @@ +"""Exercise the stage-2 CLI in both archives produced by build_release_assets.py.""" +import argparse +import hashlib +import os +from pathlib import Path +import subprocess +import sys +import tarfile +import tempfile +import zipfile + + +ROOT = Path(__file__).resolve().parents[1] +TEST = Path("tests/test_cli_video_clip.py") +CASE = TEST.as_posix() + "::CLIClipTests::test_stage_two_exports_the_selected_video_and_subtitle" + + +def verify(dist): + prefix = "FunClip-" + (ROOT / "VERSION").read_text().strip() + artifacts = [dist / (prefix + ext) for ext in (".tar.gz", ".zip")] + lines = [] + for artifact in artifacts: + with artifact.open("rb") as stream: + lines.append(f"{hashlib.file_digest(stream, 'sha256').hexdigest()} {artifact.name}") + if (dist / "SHA256SUMS").read_text().splitlines() != lines: + raise ValueError("SHA256SUMS does not match the two built archives") + + env = {**os.environ, "HF_HUB_OFFLINE": "1", "PYTEST_DISABLE_PLUGIN_AUTOLOAD": "1"} + env.pop("PYTHONPATH", None) + for artifact in artifacts: + with tempfile.TemporaryDirectory() as tmp: + if artifact.suffix == ".zip": + with zipfile.ZipFile(artifact) as archive: + archive.extractall(tmp) + else: + with tarfile.open(artifact, "r:gz") as archive: + archive.extractall(tmp, filter="data") + root = Path(tmp) / prefix + if (root / TEST).read_bytes() != (ROOT / TEST).read_bytes(): + raise ValueError(f"Packaged CLI regression differs from checkout in {artifact.name}") + print(f"Testing stage-2 export from {artifact.name}", flush=True) + subprocess.run([sys.executable, "-I", "-m", "pytest", "-q", CASE], + cwd=root, env=env, check=True, timeout=180) + + +if __name__ == "__main__": + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument("dist", type=Path, help="directory of freshly built release assets") + verify(parser.parse_args().dist) diff --git a/tests/test_release_contract.py b/tests/test_release_contract.py index f14ab31..3373016 100644 --- a/tests/test_release_contract.py +++ b/tests/test_release_contract.py @@ -112,6 +112,26 @@ def test_tag_workflow_builds_and_publishes_all_release_assets(): assert "dist/SHA256SUMS" in workflow +def test_publisher_requires_the_bytes_checked_by_the_read_only_archive_job(): + workflow = (ROOT / ".github/workflows/release.yml").read_text() + acceptance, publisher = workflow.split(" release:\n", 1) + assert " archives:\n" in acceptance + assert "contents: read" in acceptance + assert "sha256: ${{ steps.verify.outputs.sha256 }}" in acceptance + assert "uses: ./.github/actions/clip-export" in acceptance + assert "needs: archives" in publisher + before_publish = publisher.split(" - name: Publish GitHub release", 1)[0] + assert before_publish.index("build_release_assets.py") < before_publish.index("needs.archives.outputs.sha256") + assert "sha256sum --strict --check" in before_publish + + tests_workflow = (ROOT / ".github/workflows/tests.yml").read_text() + assert "uses: ./.github/actions/clip-export" in tests_workflow + action = (ROOT / ".github/actions/clip-export/action.yml").read_text() + assert "scripts/verify_release_cli.py" in action + assert "tests/test_cli_video_clip.py" in action + assert '>> "$GITHUB_OUTPUT"' in action + + def test_release_builder_creates_reproducible_scoped_archives(tmp_path): repository = tmp_path / "fixture" _create_fixture_repository(repository)