Add prettier and eslint workflow #5
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: TypeScript, Vue.js, and CSS Formatting And Linting | |
on: | |
pull_request: | |
types: [opened, synchronize, reopened] | |
permissions: | |
contents: write | |
pull-requests: write | |
jobs: | |
format_and_lint: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Set up Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: '20.9.0' | |
- name: Install dependencies | |
run: npm install prettier eslint @eslint/js typescript-eslint eslint-plugin-vue globals | |
- name: Run Prettier & ESLint | |
id: lint | |
run: | | |
npx prettier --write src//**/*.{css,ts,vue} | |
npx eslint src | |
eslint_ret=$? | |
echo "eslint_ret=$eslint_ret" >> $GITHUB_OUTPUT | |
- name: Auto commit Prettierformatted files | |
uses: stefanzweifel/git-auto-commit-action@v5 | |
with: | |
commit_message: "auto prettier format code" | |
file_pattern: "*.css *.ts *.vue" # Don't update package-lock.json and package.json | |
- name: Add PR review comment if eslint fails | |
if: steps.lint.outputs.eslint_ret != 0 | |
uses: actions/github-script@v4 | |
with: | |
script: | | |
const { pull_request } = context.payload; | |
const comment = "Your code does not meet our eslint standards.\nPlease run `npm install -g eslint @eslint/js typescript-eslint eslint-plugin-vue && npx eslint src` to lint your code."; | |
await github.issues.createComment({ | |
issue_number: pull_request.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
body: comment | |
}); |