|
| 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 | + |
0 commit comments