feat(eslint.yml): add ESLint and Prettier workflow

This commit adds a new workflow file `.github/workflows/eslint.yml` that sets up a workflow for running ESLint and Prettier on push to the `main` branch, pull requests targeting the `main` branch, and manually triggered workflow dispatch events.

The workflow runs on `ubuntu-latest` and consists of the following steps:
1. Checkout the repository
2. Setup pnpm version 8
3. Get the pnpm store directory path
4. Setup pnpm cache using the store path
5. Install dependencies using pnpm
6. Run ESLint and Prettier linting
7. Configure git user email and name for the commit
8. Check if there are any changes using `git diff`
9. If there are changes, add all changes and commit with the message "style: ESLint && Prettier"
10. Push the changes to the repository
This commit is contained in:
Sped0n
2023-11-04 20:08:36 +08:00
parent 2ebdebd86b
commit a87d1ee3cc

47
.github/workflows/eslint.yml vendored Normal file
View File

@@ -0,0 +1,47 @@
name: 'ESLint && Prettier'
on:
push:
branches:
- main
pull_request:
branches:
- main
workflow_dispatch:
permissions:
contents: write
jobs:
lint:
runs-on: ubuntu-latest
name: Lint
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup pnpm
uses: pnpm/action-setup@v2
with:
version: 8
- name: Get pnpm store directory
id: pnpm-cache
run: echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT
- name: Setup pnpm cache
uses: actions/cache@v3
with:
path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: ${{ runner.os }}-pnpm-store-
- name: Install dependencies
run: pnpm install
- name: Lint
run: |
pnpm run lint
git config --global user.email "noreply@github.com"
git config --global user.name "CI"
git diff --quiet || (git add -A && git commit -m "style: ESlint && Prettier")
git push