From 0f49ce4ade035faf994962ea07568bacb44c630d Mon Sep 17 00:00:00 2001 From: Innei Date: Sun, 22 Sep 2024 20:01:00 +0800 Subject: [PATCH] chore(ci): add fix lint and format ci Signed-off-by: Innei --- .../workflows/auto-fix-lint-format-commit.yml | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 .github/workflows/auto-fix-lint-format-commit.yml diff --git a/.github/workflows/auto-fix-lint-format-commit.yml b/.github/workflows/auto-fix-lint-format-commit.yml new file mode 100644 index 000000000..2bdb01168 --- /dev/null +++ b/.github/workflows/auto-fix-lint-format-commit.yml @@ -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 + });