Skip to content

Commit fd44875

Browse files
committed
ci: add automatic lint fixing to CI workflow
- Auto-apply Biome formatting and linting fixes - Commit and push fixes automatically on push events - Use EndBug/add-and-commit action for PR workflows - Only run auto-fix on Node 20 to avoid conflicts - Add lint:fix script to package.json - Update permissions to allow writing commits - Add [skip ci] to prevent infinite loops
1 parent 29543b8 commit fd44875

File tree

2 files changed

+41
-10
lines changed

2 files changed

+41
-10
lines changed

.github/workflows/ci.yml

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ on:
99
- main
1010

1111
permissions:
12-
contents: read
12+
contents: write
13+
pull-requests: write
1314

1415
jobs:
1516
test:
@@ -24,6 +25,9 @@ jobs:
2425
steps:
2526
- name: Checkout code
2627
uses: actions/checkout@v4
28+
with:
29+
token: ${{ secrets.GITHUB_TOKEN }}
30+
fetch-depth: 0
2731

2832
- name: Setup Node.js ${{ matrix.node-version }}
2933
uses: actions/setup-node@v4
@@ -41,8 +45,40 @@ jobs:
4145
run: |
4246
npx commitlint --from ${{ github.event.pull_request.base.sha }} --to ${{ github.event.pull_request.head.sha }}
4347
44-
- name: Lint code
45-
run: yarn lint
48+
- name: Lint and auto-fix code
49+
id: lint
50+
run: |
51+
# First try to apply fixes
52+
yarn format || true
53+
yarn lint:fix || true
54+
55+
# Check if there are any changes
56+
if [[ -n $(git status --porcelain) ]]; then
57+
echo "has_changes=true" >> $GITHUB_OUTPUT
58+
else
59+
echo "has_changes=false" >> $GITHUB_OUTPUT
60+
fi
61+
62+
# Run lint check to see if issues remain
63+
yarn lint
64+
65+
- name: Commit and push lint fixes
66+
if: steps.lint.outputs.has_changes == 'true' && github.event_name == 'push' && matrix.node-version == '20'
67+
run: |
68+
git config user.name "github-actions[bot]"
69+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
70+
git add -A
71+
git commit -m "style: apply automatic lint fixes [skip ci]"
72+
git push
73+
74+
- name: Commit lint fixes to PR
75+
if: steps.lint.outputs.has_changes == 'true' && github.event_name == 'pull_request' && matrix.node-version == '20'
76+
uses: EndBug/add-and-commit@v9
77+
with:
78+
author_name: github-actions[bot]
79+
author_email: 41898282+github-actions[bot]@users.noreply.github.com
80+
message: 'style: apply automatic lint fixes'
81+
push: true
4682

4783
- name: Type check
4884
run: npx tsc --noEmit

package.json

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,12 @@
1111
"test:watch": "vitest --watch",
1212
"test:ci": "vitest run --coverage --reporter=json --reporter=default",
1313
"lint": "biome check .",
14+
"lint:fix": "biome check --write .",
1415
"format": "biome format --write .",
1516
"prepare": "husky",
1617
"start": "node dist/index.js"
1718
},
18-
"keywords": [
19-
"mcp",
20-
"model-context-protocol",
21-
"typescript",
22-
"template",
23-
"mcp-server"
24-
],
19+
"keywords": ["mcp", "model-context-protocol", "typescript", "template", "mcp-server"],
2520
"author": "",
2621
"license": "MIT",
2722
"repository": {

0 commit comments

Comments
 (0)