GitHub action to automatically run eslint --fix on PRs and commit the changes #100
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Pull Request Checks | ||
on: | ||
pull_request: | ||
branches: | ||
- main | ||
jobs: | ||
tests-and-file-checks: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
with: | ||
ref: ${{ github.head_ref }} | ||
- name: Set up Node.js | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: '18' | ||
- name: Install dependencies | ||
run: npm install | ||
- name: Linting | ||
run: npm run lint | ||
- name: Project structure | ||
run: npm run lint:structure | ||
- name: Unit tests | ||
run: npm run test:unit | ||
- name: Build | ||
run: npm run build | ||
- name: Auto-fix ESLint Issues | ||
run: npx eslint . --fix | ||
- name: Commit changes if any | ||
run: | | ||
git config --global user.name "github-actions[bot]" | ||
git config --global user.email "github-actions[bot]@users.noreply.github.com" | ||
git add . | ||
git diff --quiet || git commit -m "ESLint auto-fix applied by GitHub Actions" || exit 0 | ||
git push | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # GitHub token for authentication |