Skip to content

Commit 5d15346

Browse files
committed
ci: add automatic lint fixing to CI workflow
1 parent 2c87de7 commit 5d15346

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

.github/workflows/ci.yml

Lines changed: 40 additions & 1 deletion
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,6 +45,41 @@ jobs:
4145
run: |
4246
npx commitlint --from ${{ github.event.pull_request.base.sha }} --to ${{ github.event.pull_request.head.sha }}
4347
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
82+
4483
- name: Type check
4584
run: npx tsc --noEmit
4685

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
"test": "vitest run --coverage",
1515
"test:watch": "vitest --watch",
1616
"test:ci": "vitest run --coverage --reporter=json --reporter=default",
17+
"lint": "biome check .",
18+
"lint:fix": "biome check --write .",
19+
"format": "biome format --write .",
1720
"prepare": "npm run build",
1821
"prepublishOnly": "npm test && npm run build",
1922
"start": "node dist/index.js"

0 commit comments

Comments
 (0)