|
| 1 | +name: Fix Drift |
| 2 | +on: |
| 3 | + workflow_dispatch: |
| 4 | + workflow_run: |
| 5 | + workflows: ["Drift Tests"] |
| 6 | + types: [completed] |
| 7 | + branches: [main] |
| 8 | + |
| 9 | +concurrency: |
| 10 | + group: drift-fix |
| 11 | + cancel-in-progress: false |
| 12 | + |
| 13 | +jobs: |
| 14 | + fix: |
| 15 | + if: >- |
| 16 | + github.event_name == 'workflow_dispatch' || |
| 17 | + github.event.workflow_run.conclusion == 'failure' |
| 18 | + runs-on: ubuntu-latest |
| 19 | + timeout-minutes: 30 |
| 20 | + permissions: |
| 21 | + contents: write |
| 22 | + pull-requests: write |
| 23 | + issues: write |
| 24 | + steps: |
| 25 | + - uses: actions/checkout@v4 |
| 26 | + - uses: pnpm/action-setup@v4 |
| 27 | + - uses: actions/setup-node@v4 |
| 28 | + with: |
| 29 | + node-version: 22 |
| 30 | + cache: pnpm |
| 31 | + - run: pnpm install --frozen-lockfile |
| 32 | + |
| 33 | + # Step 0: Configure git identity and create fix branch |
| 34 | + - name: Configure git |
| 35 | + run: | |
| 36 | + git config user.name "llmock-drift-bot" |
| 37 | + git config user.email "drift-bot@copilotkit.ai" |
| 38 | + git checkout -B fix/drift-$(date +%Y-%m-%d)-${{ github.run_id }} |
| 39 | +
|
| 40 | + # Step 1: Detect drift and produce report |
| 41 | + - name: Collect drift report |
| 42 | + id: detect |
| 43 | + run: | |
| 44 | + set +e |
| 45 | + npx tsx scripts/drift-report-collector.ts |
| 46 | + EXIT_CODE=$? |
| 47 | + set -e |
| 48 | + echo "exit_code=$EXIT_CODE" >> $GITHUB_OUTPUT |
| 49 | + if [ "$EXIT_CODE" -eq 2 ]; then |
| 50 | + : # critical drift found, continue |
| 51 | + elif [ "$EXIT_CODE" -ne 0 ]; then |
| 52 | + echo "::error::Collector script crashed with exit code $EXIT_CODE" |
| 53 | + exit $EXIT_CODE |
| 54 | + fi |
| 55 | + env: |
| 56 | + OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} |
| 57 | + ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }} |
| 58 | + GOOGLE_API_KEY: ${{ secrets.GOOGLE_API_KEY }} |
| 59 | + |
| 60 | + # Always upload the report as an artifact |
| 61 | + - name: Upload drift report |
| 62 | + if: always() |
| 63 | + uses: actions/upload-artifact@v4 |
| 64 | + with: |
| 65 | + name: drift-report |
| 66 | + path: drift-report.json |
| 67 | + if-no-files-found: warn |
| 68 | + retention-days: 30 |
| 69 | + |
| 70 | + # Step 2: Exit if no critical drift |
| 71 | + - name: Check for critical diffs |
| 72 | + id: check |
| 73 | + env: |
| 74 | + DETECT_EXIT_CODE: ${{ steps.detect.outputs.exit_code }} |
| 75 | + run: | |
| 76 | + if [ "$DETECT_EXIT_CODE" = "2" ]; then |
| 77 | + echo "skip=false" >> $GITHUB_OUTPUT |
| 78 | + echo "Critical drift detected" |
| 79 | + else |
| 80 | + echo "skip=true" >> $GITHUB_OUTPUT |
| 81 | + echo "No critical drift detected (exit code: $DETECT_EXIT_CODE) — skipping fix" |
| 82 | + fi |
| 83 | +
|
| 84 | + # Step 3: Invoke Claude Code to fix |
| 85 | + - name: Auto-fix drift |
| 86 | + if: steps.check.outputs.skip != 'true' |
| 87 | + run: npx tsx scripts/fix-drift.ts |
| 88 | + env: |
| 89 | + ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }} |
| 90 | + OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} |
| 91 | + GOOGLE_API_KEY: ${{ secrets.GOOGLE_API_KEY }} |
| 92 | + |
| 93 | + # Upload Claude Code output for debugging |
| 94 | + - name: Upload Claude Code logs |
| 95 | + if: always() |
| 96 | + uses: actions/upload-artifact@v4 |
| 97 | + with: |
| 98 | + name: claude-code-output |
| 99 | + path: claude-code-output.log |
| 100 | + if-no-files-found: warn |
| 101 | + retention-days: 30 |
| 102 | + |
| 103 | + # Step 4: Verify fix independently |
| 104 | + - name: Verify conformance |
| 105 | + if: steps.check.outputs.skip != 'true' |
| 106 | + run: pnpm test |
| 107 | + |
| 108 | + - name: Verify drift resolved |
| 109 | + if: steps.check.outputs.skip != 'true' |
| 110 | + run: pnpm test:drift |
| 111 | + env: |
| 112 | + OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} |
| 113 | + ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }} |
| 114 | + GOOGLE_API_KEY: ${{ secrets.GOOGLE_API_KEY }} |
| 115 | + |
| 116 | + # Step 5: Create PR on success |
| 117 | + - name: Create PR |
| 118 | + if: success() && steps.check.outputs.skip != 'true' |
| 119 | + run: npx tsx scripts/fix-drift.ts --create-pr |
| 120 | + env: |
| 121 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 122 | + |
| 123 | + # Step 6: Open issue on failure |
| 124 | + - name: Create issue on failure |
| 125 | + if: failure() && steps.check.outputs.skip != 'true' |
| 126 | + run: npx tsx scripts/fix-drift.ts --create-issue |
| 127 | + env: |
| 128 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments