来点儿格式化 #3
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: Format Check | |
on: | |
pull_request: # 在每次提交 PR 时运行 | |
branches: | |
- main # 针对 main 分支运行 | |
- dev # 针对 dev 分支运行 | |
jobs: | |
format-check: | |
runs-on: ubuntu-latest | |
steps: | |
# Step 1: 检出代码 | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
# Step 2: 设置 Node.js 环境 | |
- name: Setup Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: '18' # 使用 Node.js 18 | |
# Step 3: 安装依赖 | |
- name: Install dependencies | |
run: npm install | |
# Step 4: 检查格式化 | |
- name: Run Prettier to check formatting | |
run: npx prettier --check "**/*.js" | |
# Step 5: 如果有差异则失败 | |
- name: Fail if formatting is incorrect | |
run: | | |
DIFF=$(npx prettier --check "**/*.js" | grep -E "^[^✓]" || true) | |
if [ -n "$DIFF" ]; then | |
echo "The following files need formatting:" | |
echo "$DIFF" | |
exit 1 | |
fi |