Skip to content

Commit 4a16d4f

Browse files
committed
Extend Dependabot workflow to auto-fix build, lint, and test failures
- Add test step (pnpm test:unit) so Claude can diagnose and fix test failures from dependency bumps (e.g. React 18→19 in PR #308) - Move git config before any commit steps so Claude's commits work even when lockfile is unchanged - Fix pipefail in build/lint steps so exit codes propagate through tee - Fix output capture: use GITHUB_OUTPUT with heredoc delimiters instead of shell substitution (which doesn't work in with: values) - Truncate logs to last 200 lines to avoid GITHUB_OUTPUT size limits - Use accurate fallback messages instead of misleading "succeeded" text
1 parent 8f2a62d commit 4a16d4f

1 file changed

Lines changed: 55 additions & 7 deletions

File tree

.github/workflows/dependabot-lockfile.yml

Lines changed: 55 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,42 +11,58 @@ permissions:
1111
jobs:
1212
fix-dependabot:
1313
runs-on: ubuntu-latest
14-
if: github.actor == 'dependabot[bot]'
1514
timeout-minutes: 15
1615

1716
steps:
17+
- name: Skip if not Dependabot
18+
id: guard
19+
run: |
20+
if [[ "${{ github.actor }}" != "dependabot[bot]" ]]; then
21+
echo "Not a Dependabot PR (actor: ${{ github.actor }}), nothing to do."
22+
echo "skip=true" >> "$GITHUB_OUTPUT"
23+
else
24+
echo "skip=false" >> "$GITHUB_OUTPUT"
25+
fi
26+
1827
- name: Generate App Token
28+
if: steps.guard.outputs.skip != 'true'
1929
id: generate-token
2030
uses: actions/create-github-app-token@v3
2131
with:
2232
app-id: ${{ secrets.CI_APP_ID }}
2333
private-key: ${{ secrets.CI_APP_PRIVATE_KEY }}
2434

2535
- name: Checkout Dependabot branch
36+
if: steps.guard.outputs.skip != 'true'
2637
uses: actions/checkout@v6
2738
with:
2839
ref: ${{ github.event.pull_request.head.ref }}
2940
token: ${{ steps.generate-token.outputs.token }}
3041

3142
- name: Set up pnpm
43+
if: steps.guard.outputs.skip != 'true'
3244
uses: pnpm/action-setup@v5
3345
with:
3446
version: 10
3547

3648
- name: Set up Node.js
49+
if: steps.guard.outputs.skip != 'true'
3750
uses: actions/setup-node@v6
3851
with:
3952
node-version: "22.x"
4053

4154
- name: Configure git identity
55+
if: steps.guard.outputs.skip != 'true'
4256
run: |
4357
git config user.name "github-actions[bot]"
4458
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
4559
4660
- name: Regenerate lockfile
61+
if: steps.guard.outputs.skip != 'true'
4762
run: pnpm install --no-frozen-lockfile --ignore-scripts
4863

4964
- name: Commit lockfile changes
65+
if: steps.guard.outputs.skip != 'true'
5066
id: lockfile
5167
run: |
5268
if git diff --quiet pnpm-lock.yaml; then
@@ -59,6 +75,7 @@ jobs:
5975
fi
6076
6177
- name: Try building
78+
if: steps.guard.outputs.skip != 'true'
6279
id: build
6380
continue-on-error: true
6481
run: |
@@ -67,16 +84,37 @@ jobs:
6784
pnpm run build 2>&1 | tee /tmp/build-output.txt
6885
6986
- name: Try linting
87+
if: steps.guard.outputs.skip != 'true' && steps.build.outcome == 'success'
7088
id: lint
71-
if: steps.build.outcome == 'success'
7289
continue-on-error: true
7390
run: |
7491
set -o pipefail
7592
pnpm exec eslint . 2>&1 | tee /tmp/lint-output.txt
7693
94+
- name: Try testing
95+
if: steps.guard.outputs.skip != 'true' && steps.build.outcome == 'success'
96+
id: test
97+
continue-on-error: true
98+
run: |
99+
set -o pipefail
100+
failed=0
101+
pnpm test:unit 2>&1 | tee /tmp/test-output.txt || failed=1
102+
pnpm --filter @ably/react-web-cli test 2>&1 | tee -a /tmp/test-output.txt || failed=1
103+
exit $failed
104+
105+
- name: Check if fixes needed
106+
if: steps.guard.outputs.skip != 'true'
107+
id: needs-fix
108+
run: |
109+
if [[ "${{ steps.build.outcome }}" == "failure" || "${{ steps.lint.outcome }}" == "failure" || "${{ steps.test.outcome }}" == "failure" ]]; then
110+
echo "needed=true" >> "$GITHUB_OUTPUT"
111+
else
112+
echo "needed=false" >> "$GITHUB_OUTPUT"
113+
fi
114+
77115
- name: Capture error output
78116
id: errors
79-
if: steps.build.outcome == 'failure' || steps.lint.outcome == 'failure'
117+
if: steps.needs-fix.outputs.needed == 'true'
80118
run: |
81119
{
82120
echo "build_output<<ENDOFOUTPUT"
@@ -93,17 +131,24 @@ jobs:
93131
echo "Lint was not run"
94132
fi
95133
echo "ENDOFOUTPUT"
134+
echo "test_output<<ENDOFOUTPUT"
135+
if [ -f /tmp/test-output.txt ]; then
136+
tail -n 200 /tmp/test-output.txt
137+
else
138+
echo "Tests were not run"
139+
fi
140+
echo "ENDOFOUTPUT"
96141
} >> "$GITHUB_OUTPUT"
97142
98143
- name: Fix issues with Claude
99-
if: steps.build.outcome == 'failure' || steps.lint.outcome == 'failure'
144+
if: steps.needs-fix.outputs.needed == 'true'
100145
uses: anthropics/claude-code-action@v1
101146
with:
102147
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
103148
github_token: ${{ steps.generate-token.outputs.token }}
104149
direct_prompt: |
105150
This is a Dependabot PR that bumps dependencies. The lockfile has been
106-
regenerated but the build or lint is failing.
151+
regenerated but the build, lint, or tests are failing.
107152
108153
Read .claude/CLAUDE.md for project context.
109154
@@ -115,11 +160,14 @@ jobs:
115160
Lint output (if failed):
116161
${{ steps.errors.outputs.lint_output }}
117162
163+
Test output (if failed):
164+
${{ steps.errors.outputs.test_output }}
165+
118166
## Instructions
119167
120-
1. Diagnose why the build/lint fails after the dependency bump
168+
1. Diagnose why the build/lint/tests fail after the dependency bump
121169
2. Make the MINIMUM changes needed to fix it — do not refactor unrelated code
122-
3. Run `pnpm run build` and `pnpm exec eslint .` to verify your fixes
170+
3. Run `pnpm run build`, `pnpm exec eslint .`, and `pnpm test:unit` to verify your fixes
123171
4. Commit your changes with a descriptive message
124172
5. Push to the current branch
125173

0 commit comments

Comments
 (0)