Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions .github/actions/clip-export/action.yml
Original file line number Diff line number Diff line change
@@ -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"
22 changes: 22 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 }}
Expand Down
13 changes: 2 additions & 11 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

<a name="Community"></a>
Expand Down
2 changes: 2 additions & 0 deletions README_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
49 changes: 49 additions & 0 deletions scripts/verify_release_cli.py
Original file line number Diff line number Diff line change
@@ -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)
20 changes: 20 additions & 0 deletions tests/test_release_contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down