add ci formmater #1
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: Check JavaScript, HTML, and CSS Formatting | |
on: | |
pull_request: | |
types: [opened, synchronize, reopened] | |
permissions: | |
contents: read | |
pull-requests: write | |
jobs: | |
lint-and-format: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Set up Node.js | |
uses: actions/setup-node@v2 | |
with: | |
node-version: '16' | |
- name: Install dependencies | |
run: | | |
npm install -g eslint prettier | |
npm install eslint-config-prettier eslint-plugin-prettier | |
- name: Run ESLint and Prettier | |
run: | | |
eslint --ext .js,.html,.css . | |
prettier --write "**/*.{js,html,css}" | |
- name: Add PR review comment if formatting is incorrect | |
if: failure() | |
uses: actions/github-script@v4 | |
with: | |
script: | | |
const { pull_request } = context.payload; | |
const comment = "Your code does not meet the formatting standards.\nPlease run `npm install -g eslint prettier && npm install eslint-config-prettier eslint-plugin-prettier && eslint --ext .js,.html,.css . && prettier --write \"**/*.{js,html,css}\"` to format your code."; | |
await github.issues.createComment({ | |
issue_number: pull_request.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
body: comment | |
}); |