mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-11-02 05:17:23 +08:00
refactor: move site collector releases and sources to independent repository
This commit is contained in:
257
.github/workflows/site-adapter-collector.yml
vendored
257
.github/workflows/site-adapter-collector.yml
vendored
@@ -1,257 +0,0 @@
|
||||
name: Site Adapter Collector
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- v3
|
||||
paths:
|
||||
- scripts/site_adapter_collector.py
|
||||
- scripts/site_adapter_collector.spec
|
||||
- scripts/site_adapter_collector_requirements.txt
|
||||
- scripts/start-site-adapter-collector.command
|
||||
- scripts/collect-site-adapter.sh
|
||||
- scripts/collector/**
|
||||
- .github/workflows/site-adapter-collector.yml
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
publish:
|
||||
description: Publish an independent release only when collector inputs changed
|
||||
required: true
|
||||
default: true
|
||||
type: boolean
|
||||
|
||||
# 串行选择版本和发布,避免多个采集器提交争抢同一个版本。
|
||||
concurrency:
|
||||
group: site-adapter-collector-release
|
||||
cancel-in-progress: false
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
prepare:
|
||||
name: Check collector changes and select independent version
|
||||
if: github.ref == 'refs/heads/v3'
|
||||
runs-on: ubuntu-latest
|
||||
outputs:
|
||||
changed: ${{ steps.version.outputs.changed }}
|
||||
version: ${{ steps.version.outputs.version }}
|
||||
tag: ${{ steps.version.outputs.tag }}
|
||||
previous_tag: ${{ steps.version.outputs.previous_tag }}
|
||||
source_sha: ${{ steps.version.outputs.source_sha }}
|
||||
steps:
|
||||
- name: Checkout current collector source
|
||||
uses: actions/checkout@v7
|
||||
with:
|
||||
# 排队期间可能已有新提交;统一构建当前 v3,避免旧任务回退采集器。
|
||||
ref: v3
|
||||
fetch-depth: 0
|
||||
fetch-tags: false
|
||||
|
||||
- name: Set up Python
|
||||
uses: actions/setup-python@v7
|
||||
with:
|
||||
python-version: '3.14'
|
||||
|
||||
- name: Select collector release version
|
||||
id: version
|
||||
env:
|
||||
GH_TOKEN: ${{ github.token }}
|
||||
run: |
|
||||
gh api "repos/$GITHUB_REPOSITORY/releases?per_page=100" --paginate \
|
||||
--jq '.[] | select(.draft == false and .prerelease == false) | .tag_name' \
|
||||
> collector-release-tags.txt
|
||||
python scripts/collector/release.py plan \
|
||||
--tags-file collector-release-tags.txt --output "$GITHUB_OUTPUT"
|
||||
|
||||
build:
|
||||
name: Build ${{ matrix.platform_name }} collector
|
||||
needs: prepare
|
||||
if: needs.prepare.outputs.changed == 'true' || (github.event_name == 'workflow_dispatch' && !inputs.publish)
|
||||
runs-on: ${{ matrix.runner }}
|
||||
timeout-minutes: 30
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include:
|
||||
- platform_name: Windows
|
||||
platform_id: windows
|
||||
runner: windows-latest
|
||||
source_name: moviepilot-site-collector.exe
|
||||
asset_name: moviepilot-site-collector-windows.exe
|
||||
artifact_name: site-adapter-collector-windows
|
||||
- platform_name: macOS
|
||||
platform_id: macos
|
||||
runner: macos-latest
|
||||
source_name: moviepilot-site-collector
|
||||
asset_name: MoviePilot-Site-Collector-macOS.zip
|
||||
artifact_name: site-adapter-collector-macos
|
||||
- platform_name: Linux
|
||||
platform_id: linux
|
||||
runner: ubuntu-latest
|
||||
source_name: moviepilot-site-collector
|
||||
asset_name: moviepilot-site-collector-linux
|
||||
artifact_name: site-adapter-collector-linux
|
||||
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v7
|
||||
with:
|
||||
ref: ${{ needs.prepare.outputs.source_sha }}
|
||||
|
||||
- name: Set up Python
|
||||
uses: actions/setup-python@v7
|
||||
with:
|
||||
python-version: '3.14'
|
||||
|
||||
- name: Set up uv
|
||||
uses: astral-sh/setup-uv@v10.0.1
|
||||
with:
|
||||
enable-cache: true
|
||||
cache-dependency-glob: scripts/site_adapter_collector_requirements.txt
|
||||
|
||||
- name: Install build dependencies
|
||||
run: uv pip install --system --requirement scripts/site_adapter_collector_requirements.txt
|
||||
|
||||
- name: Build single-file collector
|
||||
shell: bash
|
||||
env:
|
||||
COLLECTOR_VERSION: ${{ needs.prepare.outputs.version }}
|
||||
run: |
|
||||
python scripts/collector/release.py stamp --version "$COLLECTOR_VERSION"
|
||||
pyinstaller --clean --noconfirm scripts/site_adapter_collector.spec
|
||||
|
||||
- name: Smoke-test collector
|
||||
env:
|
||||
SOURCE_NAME: ${{ matrix.source_name }}
|
||||
COLLECTOR_VERSION: ${{ needs.prepare.outputs.version }}
|
||||
run: |
|
||||
python -c "import os, subprocess; from pathlib import Path; subprocess.run([str((Path('dist') / os.environ['SOURCE_NAME']).resolve()), '--help'], check=True)"
|
||||
python -c "import os, subprocess; from pathlib import Path; result = subprocess.run([str((Path('dist') / os.environ['SOURCE_NAME']).resolve()), '--version'], check=True, capture_output=True, text=True); assert result.stdout.strip() == os.environ['COLLECTOR_VERSION'], result.stdout"
|
||||
|
||||
- name: Package macOS double-click archive
|
||||
if: matrix.platform_id == 'macos'
|
||||
shell: bash
|
||||
env:
|
||||
ASSET_NAME: ${{ matrix.asset_name }}
|
||||
SOURCE_NAME: ${{ matrix.source_name }}
|
||||
run: |
|
||||
package_dir="dist/MoviePilot-Collector"
|
||||
mkdir -p "$package_dir"
|
||||
cp "dist/$SOURCE_NAME" "$package_dir/moviepilot-site-collector-macos"
|
||||
cp scripts/start-site-adapter-collector.command "$package_dir/start-site-adapter-collector.command"
|
||||
chmod +x "$package_dir/moviepilot-site-collector-macos"
|
||||
chmod +x "$package_dir/start-site-adapter-collector.command"
|
||||
cd dist
|
||||
COPYFILE_DISABLE=1 zip -q -r -X "$ASSET_NAME" MoviePilot-Collector
|
||||
|
||||
- name: Rename Windows and Linux collector
|
||||
if: matrix.platform_id != 'macos'
|
||||
env:
|
||||
ASSET_NAME: ${{ matrix.asset_name }}
|
||||
SOURCE_NAME: ${{ matrix.source_name }}
|
||||
run: |
|
||||
python -c "import os; from pathlib import Path; (Path('dist') / os.environ['SOURCE_NAME']).replace(Path('dist') / os.environ['ASSET_NAME'])"
|
||||
|
||||
- name: Generate SHA-256 checksum
|
||||
env:
|
||||
ASSET_NAME: ${{ matrix.asset_name }}
|
||||
run: |
|
||||
python -c "import hashlib, os; from pathlib import Path; path = Path('dist') / os.environ['ASSET_NAME']; path.with_name(path.name + '.sha256').write_text(f'{hashlib.sha256(path.read_bytes()).hexdigest()} {path.name}\n', encoding='utf-8', newline='\n')"
|
||||
|
||||
- name: Upload collector artifact
|
||||
uses: actions/upload-artifact@v7
|
||||
with:
|
||||
name: ${{ matrix.artifact_name }}
|
||||
path: |
|
||||
dist/${{ matrix.asset_name }}
|
||||
dist/${{ matrix.asset_name }}.sha256
|
||||
if-no-files-found: error
|
||||
retention-days: 3
|
||||
|
||||
publish:
|
||||
name: Publish independent collector release
|
||||
if: needs.prepare.outputs.changed == 'true' && (github.event_name == 'push' || inputs.publish)
|
||||
needs:
|
||||
- prepare
|
||||
- build
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: write
|
||||
|
||||
steps:
|
||||
- name: Checkout release source
|
||||
uses: actions/checkout@v7
|
||||
with:
|
||||
ref: ${{ needs.prepare.outputs.source_sha }}
|
||||
fetch-depth: 0
|
||||
fetch-tags: false
|
||||
|
||||
- name: Download collector artifacts
|
||||
uses: actions/download-artifact@v8
|
||||
with:
|
||||
pattern: site-adapter-collector-*
|
||||
path: release-assets
|
||||
merge-multiple: true
|
||||
|
||||
- name: Generate collector release notes
|
||||
env:
|
||||
COLLECTOR_VERSION: ${{ needs.prepare.outputs.version }}
|
||||
PREVIOUS_TAG: ${{ needs.prepare.outputs.previous_tag }}
|
||||
SOURCE_SHA: ${{ needs.prepare.outputs.source_sha }}
|
||||
run: |
|
||||
if [[ -n "$PREVIOUS_TAG" ]]; then
|
||||
git fetch --no-tags origin "refs/tags/$PREVIOUS_TAG:refs/tags/$PREVIOUS_TAG"
|
||||
fi
|
||||
python - <<'PY'
|
||||
import os
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
from scripts.collector.release import RELEASE_PATHS
|
||||
|
||||
version = os.environ['COLLECTOR_VERSION']
|
||||
previous = os.environ['PREVIOUS_TAG']
|
||||
revision = f"{previous}..HEAD" if previous else "HEAD"
|
||||
records = subprocess.check_output(
|
||||
['git', 'log', revision, '--no-merges', '--format=- %s (%h) — %an', '--', *RELEASE_PATHS],
|
||||
text=True,
|
||||
).strip()
|
||||
notes = (
|
||||
f"MoviePilot 站点适配采集器 {version},独立于后端版本发布。\n\n"
|
||||
"下载与系统对应的程序及同名 `.sha256` 校验文件。\n\n"
|
||||
"[使用说明](https://github.com/jxxghp/MoviePilot/blob/v3/docs/site-adapter-collector-release.md)\n\n"
|
||||
f"源码提交:`{os.environ['SOURCE_SHA']}`\n\n## 变更记录\n\n{records}\n"
|
||||
)
|
||||
Path('collector-release-notes.md').write_text(notes, encoding='utf-8')
|
||||
PY
|
||||
|
||||
- name: Create and publish independent collector release
|
||||
env:
|
||||
GH_TOKEN: ${{ github.token }}
|
||||
RELEASE_TAG: ${{ needs.prepare.outputs.tag }}
|
||||
COLLECTOR_VERSION: ${{ needs.prepare.outputs.version }}
|
||||
SOURCE_SHA: ${{ needs.prepare.outputs.source_sha }}
|
||||
run: |
|
||||
if gh release view "$RELEASE_TAG" --repo "$GITHUB_REPOSITORY" \
|
||||
--json isDraft,targetCommitish --jq '[.isDraft, .targetCommitish] | @tsv' \
|
||||
> collector-draft-state.txt; then
|
||||
# 草稿尚未发布时标签可能不存在,应核对创建草稿时绑定的源码提交。
|
||||
IFS=$'\t' read -r is_draft draft_source < collector-draft-state.txt
|
||||
if [[ "$is_draft" != "true" || "$draft_source" != "$SOURCE_SHA" ]]; then
|
||||
echo "Refusing to overwrite a published release or a draft from another source commit" >&2
|
||||
exit 1
|
||||
fi
|
||||
gh release upload "$RELEASE_TAG" release-assets/* \
|
||||
--clobber --repo "$GITHUB_REPOSITORY"
|
||||
gh release edit "$RELEASE_TAG" --repo "$GITHUB_REPOSITORY" \
|
||||
--title "Site Adapter Collector v$COLLECTOR_VERSION" \
|
||||
--notes-file collector-release-notes.md
|
||||
else
|
||||
gh release create "$RELEASE_TAG" release-assets/* \
|
||||
--repo "$GITHUB_REPOSITORY" --target "$SOURCE_SHA" --draft \
|
||||
--title "Site Adapter Collector v$COLLECTOR_VERSION" \
|
||||
--notes-file collector-release-notes.md --latest=false
|
||||
fi
|
||||
# 全部附件上传完成才转正式发布,上传失败不会消耗正式版本。
|
||||
gh release edit "$RELEASE_TAG" --repo "$GITHUB_REPOSITORY" \
|
||||
--draft=false --latest=false
|
||||
Reference in New Issue
Block a user