From a87d1ee3cc3fe5ce75d5cffa2b3c5ac5570abb65 Mon Sep 17 00:00:00 2001 From: Sped0n Date: Sat, 4 Nov 2023 20:08:36 +0800 Subject: [PATCH] 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 --- .github/workflows/eslint.yml | 47 ++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 .github/workflows/eslint.yml diff --git a/.github/workflows/eslint.yml b/.github/workflows/eslint.yml new file mode 100644 index 0000000..e03a8be --- /dev/null +++ b/.github/workflows/eslint.yml @@ -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