Skip to content

adds prettier gh action #1

adds prettier gh action

adds prettier gh action #1

Workflow file for this run

name: Prettier Check
on:
pull_request:
types: [opened, synchronize, reopened]
workflow_dispatch:
jobs:
prettier-check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: pnpm/action-setup@v2
with:
version: 8
- uses: actions/setup-node@v4
with:
node-version: "20.x"
registry-url: "https://registry.npmjs.org"
cache: 'pnpm'
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Check formatting
run: pnpm run fmt:check
- name: Create comment if there are formatting issues
if: failure()
run: |
COMMENT_BODY="There are formatting errors in this PR. Would you like me to try to auto fix them and push up a commit? [YES](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})"
gh pr comment ${{ github.event.pull_request.number }} --body "$COMMENT_BODY"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
auto-fix:
runs-on: ubuntu-latest
if: github.event.inputs.auto_fix == 'yes'
steps:
- uses: actions/checkout@v3
- uses: pnpm/action-setup@v2
with:
version: 8
- uses: actions/setup-node@v4
with:
node-version: "20.x"
registry-url: "https://registry.npmjs.org"
cache: 'pnpm'
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Run prettier to format the code
run: pnpm run fmt
- name: Commit and push changes
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
git commit -am "Auto-fix formatting issues"
git push
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}