mirror of
https://github.com/System-End/My-website.git
synced 2026-04-19 16:28:16 +00:00
ci: add prettier auto-format workflow
This commit is contained in:
parent
6af3af9903
commit
8a113fc438
1 changed files with 66 additions and 0 deletions
66
.github/workflows/format.yml
vendored
Normal file
66
.github/workflows/format.yml
vendored
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
name: Format
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [main]
|
||||
pull_request:
|
||||
branches: [main]
|
||||
|
||||
concurrency:
|
||||
group: format-${{ github.ref }}
|
||||
cancel-in-progress: true
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
|
||||
jobs:
|
||||
format-check:
|
||||
name: Prettier
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
ref: ${{ github.head_ref || github.ref_name }}
|
||||
|
||||
- name: Setup Node.js
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: 20
|
||||
|
||||
- name: Setup pnpm
|
||||
uses: pnpm/action-setup@v4
|
||||
with:
|
||||
version: 9
|
||||
|
||||
- name: Get pnpm store directory
|
||||
id: pnpm-cache
|
||||
shell: bash
|
||||
run: echo "STORE_PATH=$(pnpm store path)" >> "$GITHUB_OUTPUT"
|
||||
|
||||
- name: Cache pnpm dependencies
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
|
||||
key: pnpm-store-${{ runner.os }}-${{ hashFiles('pnpm-lock.yaml') }}
|
||||
restore-keys: |
|
||||
pnpm-store-${{ runner.os }}-
|
||||
|
||||
- name: Install dependencies
|
||||
run: pnpm install --frozen-lockfile
|
||||
|
||||
- name: Check formatting (PR)
|
||||
if: github.event_name == 'pull_request'
|
||||
run: pnpm prettier --check "src/**/*.{ts,tsx,css}" "*.{json,js,cjs,ts,md}"
|
||||
|
||||
- name: Fix formatting (push to main)
|
||||
if: github.event_name == 'push'
|
||||
run: pnpm format
|
||||
|
||||
- name: Commit formatting fixes
|
||||
if: github.event_name == 'push'
|
||||
uses: stefanzweifel/git-auto-commit-action@v5
|
||||
with:
|
||||
commit_message: "style: auto-format with prettier"
|
||||
file_pattern: "src/**/*.ts src/**/*.tsx src/**/*.css *.json *.js *.cjs *.ts *.md"
|
||||
Loading…
Add table
Reference in a new issue