Skip to content

Commit fd0de97

Browse files
authored
Merge pull request #540 from tapdata/chore/TAP-10594-git-hook
Chore/tap 10594 git hook
2 parents a23235b + 12d92ce commit fd0de97

File tree

10 files changed

+610
-326
lines changed

10 files changed

+610
-326
lines changed

.github/workflows/auto-commit-comments.yml

Lines changed: 0 additions & 69 deletions
This file was deleted.

.github/workflows/build.yml

Lines changed: 0 additions & 55 deletions
This file was deleted.

.github/workflows/ci.yml

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
name: CI
2+
3+
on:
4+
pull_request:
5+
branches: ['main', 'develop', 'release-v*.*']
6+
7+
concurrency:
8+
group: ${{ github.workflow }}-${{ github.ref }}
9+
cancel-in-progress: true
10+
11+
jobs:
12+
changed-files:
13+
name: Get Changed Files
14+
runs-on: ubuntu-latest
15+
outputs:
16+
lint_files: ${{ steps.changed.outputs.lint_files }}
17+
has_lint_files: ${{ steps.changed.outputs.has_lint_files }}
18+
i18n_files: ${{ steps.changed.outputs.i18n_files }}
19+
has_i18n_files: ${{ steps.changed.outputs.has_i18n_files }}
20+
steps:
21+
- uses: actions/checkout@v4
22+
with:
23+
fetch-depth: 0
24+
25+
- name: Get changed files
26+
id: changed
27+
run: |
28+
FILES=$(git diff --name-only --diff-filter=ACM origin/${{ github.base_ref }}...HEAD)
29+
30+
# ESLint: 所有 vue/js/ts/tsx/jsx 文件
31+
LINT_FILES=$(echo "$FILES" | grep -E '\.(vue|js|ts|tsx|jsx)$' || true)
32+
if [ -n "$LINT_FILES" ]; then
33+
echo "has_lint_files=true" >> $GITHUB_OUTPUT
34+
# 转成空格分隔的单行
35+
echo "lint_files=$(echo "$LINT_FILES" | tr '\n' ' ')" >> $GITHUB_OUTPUT
36+
else
37+
echo "has_lint_files=false" >> $GITHUB_OUTPUT
38+
echo "lint_files=" >> $GITHUB_OUTPUT
39+
fi
40+
41+
# i18n: 排除 locale 目录的 vue/js/ts/tsx/jsx 文件
42+
I18N_FILES=$(echo "$LINT_FILES" | grep -v -E '(locale[s]?/|i18n/langs/)' || true)
43+
if [ -n "$I18N_FILES" ]; then
44+
echo "has_i18n_files=true" >> $GITHUB_OUTPUT
45+
echo "i18n_files=$(echo "$I18N_FILES" | tr '\n' ' ')" >> $GITHUB_OUTPUT
46+
else
47+
echo "has_i18n_files=false" >> $GITHUB_OUTPUT
48+
echo "i18n_files=" >> $GITHUB_OUTPUT
49+
fi
50+
51+
eslint:
52+
name: ESLint
53+
runs-on: ubuntu-latest
54+
needs: changed-files
55+
if: needs.changed-files.outputs.has_lint_files == 'true'
56+
steps:
57+
- uses: actions/checkout@v4
58+
59+
- uses: pnpm/action-setup@v4
60+
61+
- uses: actions/setup-node@v4
62+
with:
63+
node-version: 20
64+
cache: pnpm
65+
66+
- name: Install dependencies
67+
run: pnpm install --frozen-lockfile
68+
69+
- name: Run ESLint on changed files
70+
run: pnpm eslint --no-warn-ignored --quiet ${{ needs.changed-files.outputs.lint_files }}
71+
72+
check-i18n:
73+
name: Check i18n
74+
runs-on: ubuntu-latest
75+
needs: changed-files
76+
if: needs.changed-files.outputs.has_i18n_files == 'true'
77+
steps:
78+
- uses: actions/checkout@v4
79+
80+
- name: Check for hardcoded Chinese text
81+
run: node scripts/check-i18n.js ${{ needs.changed-files.outputs.i18n_files }}
82+

.github/workflows/mr-ci.yaml

Lines changed: 0 additions & 176 deletions
This file was deleted.

.husky/pre-commit

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
pnpm lint-staged
2+

.lintstagedrc.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"*.{vue,js,ts,tsx,jsx}": [
3+
"node scripts/check-i18n.js",
4+
"eslint --fix --no-warn-ignored"
5+
]
6+
}

0 commit comments

Comments
 (0)