-
Notifications
You must be signed in to change notification settings - Fork 0
152 lines (132 loc) · 5.03 KB
/
ci.yml
File metadata and controls
152 lines (132 loc) · 5.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
name: CI - PR Checks
on:
pull_request:
workflow_dispatch:
env:
NODE_VERSION: '24'
jobs:
# ==================== Self-hosted 快速链路 ====================
ci-fast:
if: vars.USE_SELF_HOSTED == 'true'
runs-on: self-hosted
timeout-minutes: 15
steps:
- name: Git checkout
run: |
COMMIT="${{ github.event.pull_request.head.sha || github.sha }}"
EXCLUDES="-e .turbo -e '**/.turbo' -e node_modules -e '**/node_modules' -e 'packages/*/dist' -e 'miniapps/*/dist'"
if [ ! -d ".git" ]; then
git clone --depth=1 https://github.com/${{ github.repository }}.git .
git fetch origin $COMMIT --depth=1
git checkout -f $COMMIT
else
git fetch origin $COMMIT --depth=1
git checkout -f $COMMIT
eval "git clean -fdx $EXCLUDES"
fi
- name: Detect changes
id: changes
run: |
CODE_CHANGED=$(git diff --name-only origin/${{ github.base_ref || 'main' }}...HEAD | grep -E '^src/|^e2e/|^packages/|^miniapps/' || true)
if [ -n "$CODE_CHANGED" ]; then
echo "code=true" >> $GITHUB_OUTPUT
else
echo "code=false" >> $GITHUB_OUTPUT
fi
- name: Install & Run
env:
E2E_TEST_MNEMONIC: ${{ secrets.E2E_TEST_MNEMONIC }}
run: |
# Enable pipefail to capture turbo exit code through pipe
set -o pipefail
pnpm install --frozen-lockfile
if [ "${{ steps.changes.outputs.code }}" == "true" ]; then
# 运行静态检查
pnpm i18n:run
pnpm turbo run lint:run typecheck:run build i18n:run theme:run test:run test:storybook e2e:audit
# 使用 e2e:runner 分片运行 E2E 测试,避免单次全部运行
pnpm e2e:runner --all --mock -j 2
pnpm e2e:runner --all -j 2
pnpm e2e:ci:real
else
pnpm i18n:run
pnpm turbo run lint:run typecheck:run build i18n:run theme:run test:run test:storybook
fi
echo "All checks passed!"
checks-fast:
if: vars.USE_SELF_HOSTED == 'true'
needs: ci-fast
runs-on: self-hosted
steps:
- run: echo "CI fast passed"
# ==================== GitHub-hosted 标准链路 ====================
ci-standard:
if: always() && (vars.USE_SELF_HOSTED != 'true' || needs.ci-fast.result != 'success')
needs: [ci-fast]
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Detect changes
id: changes
uses: dorny/paths-filter@v3
with:
filters: |
code:
- 'src/**'
- 'e2e/**'
- 'packages/**'
- 'miniapps/**'
- uses: oven-sh/setup-bun@v2
- uses: pnpm/action-setup@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: pnpm
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Cache Playwright browsers
id: playwright-cache
uses: actions/cache@v4
with:
path: ~/.cache/ms-playwright
key: playwright-${{ runner.os }}-${{ hashFiles('pnpm-lock.yaml') }}
- name: Install Playwright deps
if: steps.playwright-cache.outputs.cache-hit != 'true'
run: pnpm exec playwright install --with-deps chromium webkit
- name: Ensure Playwright browsers
run: pnpm exec playwright install chromium webkit chromium-headless-shell
- name: Run all checks
env:
E2E_TEST_MNEMONIC: ${{ secrets.E2E_TEST_MNEMONIC }}
run: |
if [ "${{ steps.changes.outputs.code }}" == "true" ]; then
# 运行所有测试:lint + 单元测试 + Storybook 组件测试 + E2E 测试 + 主题检查
pnpm i18n:run
pnpm turbo run lint:run typecheck:run build i18n:run theme:run test:run test:storybook e2e:audit e2e:ci e2e:ci:mock e2e:ci:real
else
pnpm i18n:run
pnpm turbo run lint:run typecheck:run build i18n:run theme:run test:run test:storybook
fi
checks-standard:
if: always() && needs.ci-standard.result == 'success'
needs: ci-standard
runs-on: ubuntu-latest
steps:
- run: echo "CI standard passed"
# ==================== 聚合 Job(满足分支保护) ====================
checks:
if: always()
needs: [checks-fast, checks-standard]
runs-on: ubuntu-latest
steps:
- name: Check results
run: |
if [ "${{ needs.checks-fast.result }}" == "success" ] || [ "${{ needs.checks-standard.result }}" == "success" ]; then
echo "CI passed via $( [ '${{ needs.checks-fast.result }}' == 'success' ] && echo 'fast path' || echo 'standard path' )"
exit 0
fi
echo "CI failed: fast=${{ needs.checks-fast.result }}, standard=${{ needs.checks-standard.result }}"
exit 1