Sync from upstream + auto-regen intarweb-dev #3
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: Sync from upstream + auto-regen intarweb-dev | |
| on: | |
| schedule: | |
| - cron: '7 */6 * * *' # every 6h, offset 7m to stagger | |
| workflow_dispatch: | |
| permissions: | |
| actions: write # workflow_dispatch trigger (publish step) 403s without this | |
| contents: write | |
| pull-requests: read | |
| jobs: | |
| sync: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: 📥 Checkout fork | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| token: ${{ secrets.SYNC_WORKFLOW_TOKEN || secrets.GITHUB_TOKEN }} | |
| - name: ⚙️ Configure git identity | |
| run: | | |
| git config user.email "actions@github.com" | |
| git config user.name "intarweb sync bot" | |
| - name: 🔗 Add upstream remote | |
| run: git remote add upstream https://github.com/yzfly/mcp-python-interpreter.git | |
| - name: 🔄 Fetch upstream + all fork branches | |
| run: | | |
| git fetch upstream main --tags | |
| git fetch origin --prune | |
| - name: 🔁 Rebase main onto upstream | |
| run: | | |
| git checkout main | |
| git rebase upstream/main | |
| git push --force-with-lease origin main | |
| - name: 🔍 Discover open PRs from intarweb to upstream | |
| id: prs | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| gh api --paginate "repos/yzfly/mcp-python-interpreter/pulls?state=open&per_page=100" \ | |
| --jq '.[] | select(.head.repo.owner.login == "${{ github.repository_owner }}") | "\(.number) \(.head.ref) \(.title)"' \ | |
| | sort -n > /tmp/prs.txt | |
| if [ ! -s /tmp/prs.txt ]; then | |
| echo " No open PRs from ${{ github.repository_owner }} to upstream — intarweb-dev will == main" | |
| else | |
| echo " Open PRs to cherry-pick onto intarweb-dev:" | |
| sed 's/^/ /' /tmp/prs.txt | |
| fi | |
| - name: 🌿 Regenerate intarweb-dev = main + open-PR cherry-picks | |
| id: regen | |
| run: | | |
| git checkout -B intarweb-dev main | |
| while read num branch title; do | |
| [ -z "$num" ] && continue | |
| echo "::group::PR #$num — $branch ($title)" | |
| git fetch origin "$branch" || { echo " ✗ failed to fetch origin/$branch"; exit 1; } | |
| COMMITS=$(git log --reverse --format=%H "intarweb-dev..origin/$branch") | |
| if [ -z "$COMMITS" ]; then | |
| echo " - no unique commits — already on intarweb-dev (likely merged upstream); skipping" | |
| else | |
| for c in $COMMITS; do | |
| if ! git cherry-pick --allow-empty --keep-redundant-commits "$c"; then | |
| echo "::error::CONFLICT cherry-picking $c from PR #$num. intarweb-dev unchanged. Manual resolve required." | |
| git cherry-pick --abort || true | |
| exit 1 | |
| fi | |
| done | |
| echo " ✓ applied $(echo "$COMMITS" | wc -w) commits from PR #$num" | |
| fi | |
| echo "::endgroup::" | |
| done < /tmp/prs.txt | |
| # Did intarweb-dev's TREE actually change vs the existing remote? | |
| if git rev-parse origin/intarweb-dev^{tree} >/dev/null 2>&1; then | |
| OLD_TREE=$(git rev-parse origin/intarweb-dev^{tree}) | |
| NEW_TREE=$(git rev-parse intarweb-dev^{tree}) | |
| if [ "$OLD_TREE" = "$NEW_TREE" ]; then | |
| echo " - intarweb-dev tree unchanged; skipping push + publish trigger" | |
| echo "changed=false" >> "$GITHUB_OUTPUT" | |
| else | |
| echo " - intarweb-dev tree changed; will push + trigger publish" | |
| echo "changed=true" >> "$GITHUB_OUTPUT" | |
| fi | |
| else | |
| echo " - intarweb-dev did not exist on origin; will push + trigger publish" | |
| echo "changed=true" >> "$GITHUB_OUTPUT" | |
| fi | |
| - name: 📤 Force-push intarweb-dev | |
| if: steps.regen.outputs.changed == 'true' | |
| run: git push --force-with-lease origin intarweb-dev | |
| - name: 🚀 Trigger publish on intarweb-dev | |
| if: steps.regen.outputs.changed == 'true' | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| gh workflow run "Build from source → GHCR" --repo ${{ github.repository }} --ref intarweb-dev || echo "::warning::publish-workflow dispatch failed (probably disabled or stale); sync still succeeded" | |
| - name: ✅ Show final state | |
| run: | | |
| echo " main HEAD: $(git log main --oneline -1)" | |
| echo " intarweb-dev HEAD: $(git log intarweb-dev --oneline -1)" | |
| echo " intarweb-dev commits ahead of upstream/main:" | |
| git log --oneline upstream/main..intarweb-dev | sed 's/^/ /' || true |