chore(ci): add fix lint and format ci
Signed-off-by: Innei <i@innei.in>
This commit is contained in:
parent
5a81dd6786
commit
0f49ce4ade
|
|
@ -0,0 +1,62 @@
|
|||
name: Auto Fix Lint and Format
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
types: [opened, synchronize]
|
||||
|
||||
jobs:
|
||||
auto-fix:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Setup Node.js
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: "20"
|
||||
|
||||
- name: Setup pnpm
|
||||
uses: pnpm/action-setup@v2
|
||||
|
||||
- name: Install dependencies
|
||||
run: pnpm install
|
||||
|
||||
- name: Run linter and fix issues
|
||||
run: pnpm run lint:fix
|
||||
|
||||
- name: Run formatter
|
||||
run: pnpm run format
|
||||
|
||||
- name: Check for changes
|
||||
id: git-check
|
||||
run: |
|
||||
git diff --exit-code || echo "changes=true" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Commit and push changes
|
||||
if: steps.git-check.outputs.changes == 'true'
|
||||
run: |
|
||||
git config --local user.email "action@github.com"
|
||||
git config --local user.name "GitHub Action"
|
||||
git add -A
|
||||
git commit -m "chore: auto-fix linting and formatting issues"
|
||||
git push
|
||||
|
||||
- name: Add PR comment
|
||||
uses: actions/github-script@v7
|
||||
with:
|
||||
github-token: ${{secrets.GITHUB_TOKEN}}
|
||||
script: |
|
||||
const fs = require('fs');
|
||||
const changes = ${{ steps.git-check.outputs.changes == 'true' }};
|
||||
const message = changes
|
||||
? 'Linting and formatting issues were automatically fixed. Please review the changes.'
|
||||
: 'No linting or formatting issues were found.';
|
||||
github.rest.issues.createComment({
|
||||
issue_number: context.issue.number,
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
body: message
|
||||
});
|
||||
Loading…
Reference in New Issue