ci(sync): merge upstream nightly with failure reports

Co-authored-by: Codex <noreply@openai.com>
This commit is contained in:
ranzhigg
2026-09-04 09:56:54 +08:00
parent d87afba0e6
commit 46a3c8abef
4 changed files with 120 additions and 0 deletions

34
.github/scripts/sync-upstream.sh vendored Normal file
View File

@@ -0,0 +1,34 @@
#!/usr/bin/env bash
set -euo pipefail
report="$RUNNER_TEMP/upstream-sync-report.md"
printf '# 上游同步清单\n\n' > "$report"
git config user.name 'github-actions[bot]'
git config user.email '41898282+github-actions[bot]@users.noreply.github.com'
git fetch --no-tags https://github.com/jxxghp/MoviePilot.git v3
upstream=$(git rev-parse FETCH_HEAD)
base=$(git merge-base HEAD "$upstream")
echo "上游提交:$upstream" >> "$report"
git log --format='- %h %s' HEAD.."$upstream" >> "$report"
if git merge-base --is-ancestor "$upstream" HEAD; then
echo '没有上游更新。' >> "$report"
echo 'changed=false' >> "$GITHUB_OUTPUT"
exit 0
fi
# 双方修改同一文件时交给人工处理,避免自动合并悄悄改变定制行为
git diff --name-only "$base" HEAD | sort > "$RUNNER_TEMP/fork-paths"
git diff --name-only "$base" "$upstream" | sort > "$RUNNER_TEMP/upstream-paths"
comm -12 "$RUNNER_TEMP/fork-paths" "$RUNNER_TEMP/upstream-paths" > "$RUNNER_TEMP/overlap"
if [ -s "$RUNNER_TEMP/overlap" ]; then
echo '需要人工审阅:上游与 fork 同时修改以下文件,未推送:' >> "$report"
cat "$RUNNER_TEMP/overlap" >> "$report"
exit 1
fi
if ! git merge --no-ff --no-edit "$upstream"; then
echo '合并冲突,未推送:' >> "$report"
git diff --name-only --diff-filter=U >> "$report"
git merge --abort
exit 1
fi
git diff --check HEAD^ HEAD
echo 'changed=true' >> "$GITHUB_OUTPUT"
echo '合并完成,等待验证。' >> "$report"

View File

@@ -0,0 +1,69 @@
name: Fork upstream sync
on:
schedule:
- cron: '0 15 * * *'
workflow_dispatch:
permissions:
contents: write
issues: write
concurrency:
group: fork-upstream-sync
cancel-in-progress: false
jobs:
sync:
if: github.repository == 'ranzhigg/MoviePilot'
runs-on: ubuntu-latest
timeout-minutes: 60
steps:
- uses: actions/checkout@v7
with:
ref: v3
fetch-depth: 0
- name: Merge upstream conservatively
id: merge
run: bash .github/scripts/sync-upstream.sh
- name: Set up uv
if: steps.merge.outputs.changed == 'true'
uses: astral-sh/setup-uv@v10.0.1
with:
python-version: '3.14'
- name: Verify merged MoviePilot
if: steps.merge.outputs.changed == 'true'
run: |
uv sync --locked
uv run --locked --no-sync python tests/run.py
- name: Push verified merge
if: steps.merge.outputs.changed == 'true'
run: |
git push origin HEAD:v3
echo '验证通过,已推送;没有更新本地 MP,也没有自动发布插件安装包。' >> "$RUNNER_TEMP/upstream-sync-report.md"
- name: Record failure
if: failure()
run: |
echo '同步失败:请查看失败步骤。主分支不会收到未通过验证的合并。' >> "$RUNNER_TEMP/upstream-sync-report.md"
- name: Publish run summary
if: always()
run: |
test -f "$RUNNER_TEMP/upstream-sync-report.md" || echo '工作流未完成初始化,请查看日志。' > "$RUNNER_TEMP/upstream-sync-report.md"
cat "$RUNNER_TEMP/upstream-sync-report.md" >> "$GITHUB_STEP_SUMMARY"
- name: Save report
if: always()
uses: actions/upload-artifact@v4
with:
name: upstream-sync-report
path: ${{ runner.temp }}/upstream-sync-report.md
retention-days: 30
- name: Report failure as issue
if: failure()
env:
GH_TOKEN: ${{ github.token }}
GH_REPO: ${{ github.repository }}
RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
run: |
printf '\n运行日志:%s\n' "$RUN_URL" >> "$RUNNER_TEMP/upstream-sync-report.md"
issue=$(gh issue list --state open --search '"上游同步失败" in:title' --json number --jq '.[0].number // empty')
if [ -n "$issue" ]; then
gh issue comment "$issue" --body-file "$RUNNER_TEMP/upstream-sync-report.md"
else
gh issue create --title '上游同步失败:需要检查' --body-file "$RUNNER_TEMP/upstream-sync-report.md"
fi

View File

@@ -241,3 +241,7 @@ Docker 镜像发布前还会使用 Trivy 扫描 OS 与语言包;根目录 `.tr
- [pip-audit](https://github.com/pypa/pip-audit)
- [MoviePilot-Resources](https://github.com/jxxghp/MoviePilot-Resources)
- [MoviePilot-Plugins](https://github.com/jxxghp/MoviePilot-Plugins)
## 个人 fork 同步
定时合并和失败通知见 [Fork 上游同步](fork-upstream-sync.md)。

View File

@@ -0,0 +1,13 @@
# Fork 上游同步
每天北京时间 23:00(UTC 15:00)由 GitHub Actions 检查上游;GitHub 定时任务可能延迟。也可在 Actions → Fork upstream sync 手动运行。
使用普通合并,保留 fork 提交;双方改动同一文件时暂停人工审阅,不采用 ours/theirs 或强制覆盖。合并、校验或推送失败时工作流失败,生成日志、30 天报告附件,并创建或更新失败 Issue。每次运行的 Summary 展示上游提交清单及结果。失败不自动回滚已有提交,不修改本地 MP。
推送使用 GITHUB_TOKEN,合并推送不会自动触发其他 push 工作流或插件发布;插件发布及本地安装需要另行执行。验证仅覆盖工作流列出的检查,不保证所有外部服务或第三方插件兼容。
## GitHub 自带失败邮件
仓库代码无法修改账号的邮件通知偏好。在 GitHub Settings → Notifications → System → Actions,启用 Email 并选择仅失败通知;确保该仓库通知路由使用已验证的 `ranzhigg@gmail.com`。首次用自己的账号手动运行本工作流,并检查失败邮件偏好。未开启账号通知前,工作流无法保证邮件送达,也不能从仓库设置强制收件人。
不需要 SMTP 密钥。失败 Issue 和 Actions 日志始终作为反馈入口,修复后可手动重跑;失败 Issue 由人工确认后关闭。