Files
Folo/.github/workflows/auto-fix-lint-format-commit.yml
T
Innei a5a4de00e3 fix: ci
Signed-off-by: Innei <i@innei.in>
2024-09-22 20:15:57 +08:00

67 lines
2.0 KiB
YAML

name: Auto Fix Lint and Format
on:
pull_request:
types: [opened, synchronize]
jobs:
auto-fix:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.head_ref }}
- 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 add -A
git diff --cached --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 commit -m "chore: auto-fix linting and formatting issues" --no-verify
#git push origin HEAD:${{ github.head_ref }}
git push https://${{ secrets.PAT }}@github.com/${{ github.repository }}.git HEAD:${{ github.head_ref }}
- name: Add PR comment
uses: actions/github-script@v7
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
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
});