Sync Tool Fix PR Changes #76
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 Tool Fix PR Changes | |
| on: | |
| schedule: | |
| # Every 8 hours, same as sync-cached and sync-vim-pr | |
| - cron: '0 1,9,17 * * *' | |
| workflow_dispatch: | |
| permissions: | |
| contents: read | |
| issues: write | |
| jobs: | |
| check-pr-drift: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Check if PR #16751 has changed | |
| id: check | |
| run: | | |
| # Check if PR is still open | |
| PR_STATE=$(gh pr view 16751 --repo anomalyco/opencode --json state --jq .state 2>/dev/null || echo "UNKNOWN") | |
| echo "pr_state=$PR_STATE" >> $GITHUB_OUTPUT | |
| if [ "$PR_STATE" = "MERGED" ]; then | |
| echo "PR #16751 has been merged -- tool fix patch may no longer be needed" | |
| echo "merged=true" >> $GITHUB_OUTPUT | |
| exit 0 | |
| fi | |
| if [ "$PR_STATE" = "CLOSED" ]; then | |
| echo "PR #16751 was closed without merging" | |
| echo "closed=true" >> $GITHUB_OUTPUT | |
| exit 0 | |
| fi | |
| # Fetch current PR diff | |
| gh pr diff 16751 --repo anomalyco/opencode > /tmp/current-tool-fix.patch 2>/dev/null || { | |
| echo "Failed to fetch PR diff" | |
| echo "fetch_failed=true" >> $GITHUB_OUTPUT | |
| exit 0 | |
| } | |
| # Compare with committed patch (by hash) | |
| CURRENT_HASH=$(sha256sum /tmp/current-tool-fix.patch | cut -d' ' -f1) | |
| COMMITTED_HASH=$(sha256sum patches/tool-fix.patch | cut -d' ' -f1) | |
| echo "Current PR diff hash: $CURRENT_HASH" | |
| echo "Committed patch hash: $COMMITTED_HASH" | |
| if [ "$CURRENT_HASH" != "$COMMITTED_HASH" ]; then | |
| echo "PR diff has changed since tool-fix.patch was generated" | |
| echo "drifted=true" >> $GITHUB_OUTPUT | |
| else | |
| echo "No changes detected" | |
| echo "drifted=false" >> $GITHUB_OUTPUT | |
| fi | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| - name: Create drift issue | |
| if: steps.check.outputs.drifted == 'true' | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const title = 'Patch drift: tool-fix.patch no longer matches PR #16751 - review needed'; | |
| const body = ` | |
| ## Patch Drift Detected: tool-fix.patch vs PR #16751 | |
| The upstream [PR #16751](https://github.com/anomalyco/opencode/pull/16751) has been updated. | |
| The committed \`patches/tool-fix.patch\` no longer matches the current PR diff. | |
| **This is a review signal, not a build failure.** The build continues to use the | |
| committed \`patches/tool-fix.patch\` as-is. Whether that patch still applies cleanly and | |
| whether publication is blocked is determined by the build/release workflow, not this check. | |
| ### Action Required | |
| 1. Review what changed in the PR: \`gh pr diff 16751 --repo anomalyco/opencode\` | |
| 2. Decide whether to adopt the updated diff: | |
| - If yes, regenerate the patch: | |
| \`\`\`bash | |
| gh pr diff 16751 --repo anomalyco/opencode > patches/tool-fix.patch | |
| git add patches/tool-fix.patch | |
| git commit -m "chore: update tool-fix.patch from PR #16751" | |
| git push | |
| \`\`\` | |
| - If no, close this issue with a note explaining why | |
| 3. Verify the updated patch still stacks cleanly with the caching and vim patches | |
| 4. Close this issue when done | |
| **PR**: https://github.com/anomalyco/opencode/pull/16751 | |
| `; | |
| const issues = await github.rest.issues.listForRepo({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| state: 'open', | |
| labels: 'patch-drift' | |
| }); | |
| const existingIssue = issues.data.find(i => i.title.includes('PR #16751')); | |
| if (existingIssue) { | |
| console.log(`Issue already exists: #${existingIssue.number}`); | |
| await github.rest.issues.createComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: existingIssue.number, | |
| body: `Drift still present (${new Date().toISOString().split('T')[0]}): PR #16751 diff continues to differ from committed \`patches/tool-fix.patch\`. Build is unaffected until manually reviewed and updated.` | |
| }); | |
| } else { | |
| await github.rest.issues.create({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| title: title, | |
| body: body, | |
| labels: ['patch-drift', 'review-needed'] | |
| }); | |
| console.log('Created drift issue'); | |
| } | |
| - name: Report status | |
| run: | | |
| echo "PR #16751 state: ${{ steps.check.outputs.pr_state }}" | |
| echo "Drifted: ${{ steps.check.outputs.drifted }}" |