Files
Cloud-Home/.github/workflows/lint-format.yml

81 lines
1.8 KiB
YAML

name: Lint and Format
on:
push:
branches: ["**"]
pull_request:
branches: ["**"]
jobs:
lint:
name: ESLint
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: "20"
cache: "pnpm"
- name: Enable corepack and install pnpm
run: |
corepack enable
corepack prepare pnpm@latest --activate
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Run ESLint
run: pnpm lint
- name: Run Prettier check
run: pnpm format:check
format:
name: Auto-format (eslint --fix)
runs-on: ubuntu-latest
needs: lint
if: github.event_name == 'push'
steps:
- name: Checkout
uses: actions/checkout@v4
with:
persist-credentials: true
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: "20"
cache: "pnpm"
- name: Enable corepack and install pnpm
run: |
corepack enable
corepack prepare pnpm@latest --activate
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Run Prettier --write
run: pnpm format
- name: Run ESLint --fix
run: pnpm lint:fix
- name: Commit & push fixes
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
if ! git diff --quiet; then
git add -A
git commit -m "chore: auto format by GitHub Actions" || echo "No changes to commit"
git push
else
echo "No formatting changes"
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}