Pi Sync Upstream #396
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Pi Sync Upstream | |
| on: | |
| schedule: | |
| - cron: "5 * * * *" # 每小时 :05,错开其他流水线 | |
| workflow_dispatch: | |
| permissions: | |
| contents: write | |
| jobs: | |
| sync: | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 10 | |
| steps: | |
| - uses: actions/checkout@v6 | |
| with: | |
| fetch-depth: 0 | |
| - name: Merge upstream into main | |
| run: | | |
| set -euo pipefail | |
| git config user.name "yuloop" | |
| git config user.email "yuloop@users.noreply.github.com" | |
| git remote add upstream "https://github.com/earendil-works/pi.git" | |
| git fetch upstream main | |
| # 无新提交 → 静默退出(不产生任何 commit) | |
| if git merge-base --is-ancestor upstream/main HEAD; then | |
| echo "上游无新提交,跳过" | |
| exit 0 | |
| fi | |
| # fork 关系、共享历史:普通 merge 即可 | |
| # --no-commit:暂存 merge 不自动提交,给下面的 restore 机会 | |
| # 上游带入的 .github/workflows 文件(如 build-binaries.yml)需要 workflows 权限才能 push | |
| # GITHUB_TOKEN 只有 contents: write,没有 workflows 权限, | |
| # 所以 merge 后 restore 本仓库的 workflow 目录,防止 push 被拒 | |
| git config user.name "yuloop" | |
| git config user.email "yuloop@users.noreply.github.com" | |
| git config merge.ours.driver true | |
| printf '.github/workflows/build-binaries.yml merge=ours\n' >> .git/info/attributes | |
| printf 'packages/ai/src/providers/cloudflare-ai-gateway.ts merge=ours\n' >> .git/info/attributes | |
| git merge --allow-unrelated-histories --no-commit --no-edit FETCH_HEAD 2>&1 || true | |
| # Resolve conflicts | |
| if [ -n "$(git diff --name-only --diff-filter=U 2>/dev/null)" ]; then | |
| echo "Resolving conflicts: taking upstream for source code" | |
| git diff --name-only --diff-filter=U | while read -r f; do | |
| git checkout --theirs "$f" 2>/dev/null || true | |
| done | |
| git checkout HEAD -- .github/workflows/ pi-i18n/ packages/ai/src/providers/cloudflare-ai-gateway.ts 2>/dev/null || true | |
| git add -A 2>/dev/null || true | |
| fi | |
| git restore --source=HEAD --staged --worktree .github/workflows | |
| git commit --no-edit || echo "无变更,跳过提交" | |
| git push origin main |