Skip to content

Auto Sync hf-cn/blog-zh with Upstream #556

Auto Sync hf-cn/blog-zh with Upstream

Auto Sync hf-cn/blog-zh with Upstream #556

Workflow file for this run

name: Auto Sync hf-cn/blog-zh with Upstream
on:
schedule:
- cron: '0 * * * *' # 每小时执行一次
workflow_dispatch: # 允许手动执行
jobs:
sync:
runs-on: ubuntu-latest
env:
GH_TOKEN: ${{ secrets.HF_SYNC_PAT }}
steps:
- name: Checkout blog-zh repository
uses: actions/checkout@v3
with:
repository: huggingface-cn/hf-blog-translation
token: ${{ secrets.HF_SYNC_PAT }} # 使用 PAT 访问目标 repo
fetch-depth: 0 # 获取所有历史记录,确保能检查 PR 状态
- name: Set GH_TOKEN environment variable
run: echo "GH_TOKEN=${{ secrets.HF_SYNC_PAT }}" >> $GITHUB_ENV
- name: Check for open pull requests to upstream repo
id: check_pr
run: |
OPEN_PRS=$(gh pr list --repo "huggingface/blog" --state open --json headRepository --jq '.[] | select(.headRepository.name == "R_kgDOJVBgQQ") | length')
if [ "$OPEN_PRS" -gt 0 ]; then
echo "There are open PRs to upstream, stopping sync."
exit 1
fi
- name: Set up git configuration
if: success()
run: |
git config user.name "github-actions"
git config user.email "[email protected]"
- name: Add upstream repository
if: success()
run: |
git remote add upstream https://github.com/huggingface/blog.git # 替换为上游 repo 的地址
git fetch upstream
- name: Reset and sync with upstream
if: success()
run: |
git reset --hard upstream/main
git push origin main --force
- name: Notify success
if: success()
run: echo "Repository has been successfully synced with upstream."