metube/.github/workflows/sync-upstream.yml
TonyBlu a85a564ed5 fix(ci): rewrite sync-upstream workflow to avoid third-party actions
Replace actions-cool/issues-helper and aormsby/Fork-Sync-With-Upstream-action
with native git commands and actions/github-script. This fixes the
'Repository access blocked' error caused by GitHub restricting access
to third-party actions in fork repositories.
2026-05-25 22:26:01 +08:00

68 lines
2.2 KiB
YAML

name: Upstream Sync
permissions:
contents: write
on:
schedule:
- cron: "0 */6 * * *"
workflow_dispatch:
jobs:
sync_latest_from_upstream:
name: Sync latest commits from upstream repo
runs-on: ubuntu-latest
if: ${{ github.event.repository.fork }}
steps:
- uses: actions/checkout@v4
with:
ref: master
fetch-depth: 0
token: ${{ secrets.UPSTREAM_TOKEN || secrets.GITHUB_TOKEN }}
- name: Sync upstream changes
id: sync
run: |
git remote add upstream https://github.com/alexta69/metube.git 2>/dev/null || true
git fetch upstream master
LOCAL=$(git rev-parse HEAD)
UPSTREAM=$(git rev-parse upstream/master)
if [ "$LOCAL" = "$UPSTREAM" ]; then
echo "Already up-to-date"
echo "has_changes=false" >> "$GITHUB_OUTPUT"
exit 0
fi
echo "Local: $LOCAL"
echo "Upstream: $UPSTREAM"
echo "has_changes=true" >> "$GITHUB_OUTPUT"
# Try merge first (preserves both histories)
if git merge upstream/master --no-edit; then
git push origin master
echo "Merge succeeded"
echo "sync_result=success" >> "$GITHUB_OUTPUT"
else
echo "Merge conflict detected, aborting"
git merge --abort
echo "sync_result=conflict" >> "$GITHUB_OUTPUT"
exit 1
fi
- name: Sync check — create issue on failure
if: failure()
uses: actions/github-script@v7
with:
script: |
await github.rest.issues.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: "🚨 同步失败 | Sync Fail",
labels: ["🚨 Sync Fail"],
body: `Due to conflicts or workflow changes in the [alexta69/metube](https://github.com/alexta69/metube) upstream repository, the automatic sync has failed. Please manually sync your fork and resolve any conflicts.
由于上游仓库 [alexta69/metube](https://github.com/alexta69/metube) 存在冲突或 workflow 变更,自动同步失败。请手动 Sync Fork 并解决冲突。`
});