diff --git a/.github/workflows/checkpoint-fix.yml b/.github/workflows/checkpoint-fix.yml new file mode 100644 index 0000000..624039f --- /dev/null +++ b/.github/workflows/checkpoint-fix.yml @@ -0,0 +1,131 @@ +name: Checkpoint AI Fix + +on: + repository_dispatch: + types: [checkpoint-fix] + +permissions: + contents: write + pull-requests: write + +jobs: + fix: + runs-on: ubuntu-latest + timeout-minutes: 15 + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Notify running + run: | + curl -s -X POST "${{ github.event.client_payload.callbackUrl }}" \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer ${{ secrets.CHECKPOINT_SECRET }}" \ + -d '{ + "reportId": "${{ github.event.client_payload.reportId }}", + "status": "running" + }' + + - name: Create fix branch + run: | + git checkout -b checkpoint-fix/${{ github.event.client_payload.reportId }} + + - name: Write bug context + run: | + cat > /tmp/checkpoint-context.json << 'CONTEXT_EOF' + ${{ toJSON(github.event.client_payload) }} + CONTEXT_EOF + + - name: Install Amp + run: curl -fsSL https://ampcode.com/install.sh | bash + + - name: Run AI Agent + env: + AMP_API_KEY: ${{ secrets.AMP_API_KEY }} + run: | + amp -x --dangerously-allow-all "You are fixing a bug reported by QA via Checkpoint. Here is the bug report: + + Title: ${{ github.event.client_payload.title }} + Description: ${{ github.event.client_payload.description }} + URL: ${{ github.event.client_payload.url }} + + The full bug context (element selectors, computed styles, console errors, failed requests, DOM snapshots) is in /tmp/checkpoint-context.json. Read that file first. + + Find the relevant source files using the CSS selectors and React component names from the context. Fix the bug. Do not add comments explaining the fix - just fix it." + + - name: Commit and push + run: | + git config user.name "checkpoint-bot" + git config user.email "checkpoint@tempo.xyz" + if git diff --quiet; then + echo "No changes to commit" + curl -s -X POST "${{ github.event.client_payload.callbackUrl }}" \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer ${{ secrets.CHECKPOINT_SECRET }}" \ + -d '{ + "reportId": "${{ github.event.client_payload.reportId }}", + "status": "failed", + "error": "Agent produced no changes" + }' + exit 0 + fi + git add -A + git commit -m "fix: ${{ github.event.client_payload.title }} + + Checkpoint Report: ${{ github.event.client_payload.reportId }} + Linear: ${{ github.event.client_payload.issueId }}" + git push origin checkpoint-fix/${{ github.event.client_payload.reportId }} + + - name: Create PR + id: create_pr + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + PR_URL=$(gh pr create \ + --title "fix: ${{ github.event.client_payload.title }}" \ + --body "## Checkpoint Auto-Fix + + **Linear:** [${{ github.event.client_payload.issueId }}](${{ github.event.client_payload.issueUrl }}) + **Report ID:** \`${{ github.event.client_payload.reportId }}\` + **URL:** ${{ github.event.client_payload.url }} + + --- + + This PR was automatically generated by [Checkpoint](https://tempo-qa.vercel.app) in response to a QA bug report. + + ### Bug Description + ${{ github.event.client_payload.description }} + + ### Screenshots + See the linked Linear issue for screenshots and element context." \ + --head "checkpoint-fix/${{ github.event.client_payload.reportId }}" \ + --base main) + + PR_NUMBER=$(echo "$PR_URL" | grep -oE '[0-9]+$') + echo "pr_url=$PR_URL" >> $GITHUB_OUTPUT + echo "pr_number=$PR_NUMBER" >> $GITHUB_OUTPUT + + - name: Notify PR opened + if: steps.create_pr.outputs.pr_url + run: | + curl -s -X POST "${{ github.event.client_payload.callbackUrl }}" \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer ${{ secrets.CHECKPOINT_SECRET }}" \ + -d '{ + "reportId": "${{ github.event.client_payload.reportId }}", + "status": "pr_opened", + "prUrl": "${{ steps.create_pr.outputs.pr_url }}", + "prNumber": ${{ steps.create_pr.outputs.pr_number }} + }' + + - name: Notify failure + if: failure() + run: | + curl -s -X POST "${{ github.event.client_payload.callbackUrl }}" \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer ${{ secrets.CHECKPOINT_SECRET }}" \ + -d '{ + "reportId": "${{ github.event.client_payload.reportId }}", + "status": "failed", + "error": "Workflow failed" + }'