-
Notifications
You must be signed in to change notification settings - Fork 344
131 lines (118 loc) · 4.63 KB
/
test-unit-pr.yml
File metadata and controls
131 lines (118 loc) · 4.63 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
name: Unit Test PR
run-name: Unit Test PR--${{ github.event.pull_request.title }}
on:
pull_request:
types: [opened, reopened, synchronize, edited]
concurrency:
group: ${{ github.workflow }}-${{ github.event.number || github.sha }}
cancel-in-progress: true
jobs:
parse-components:
name: Parse Affected Components
runs-on: ubuntu-latest
outputs:
testComponents: ${{ steps.parseTitle.outputs.testComponents }}
utilsModified: ${{ steps.check-utils-changes.outputs.modified }}
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Parse Title
id: parseTitle
uses: actions/github-script@v6
with:
script: |
const prTitle = context.payload.pull_request.title
const regex = /\[(.*?)\]/
const matches = prTitle.match(regex)
if (matches && matches.length > 1 && matches[1]) {
let components = matches[1]
.split(',')
.map((c) => c.trim())
.filter((c) => /^[a-z\-\/]+$/.test(c))
.map((c) => `${c}`)
components = [...new Set(components)].slice(0, 3).join(' ')
core.setOutput('testComponents', components)
} else {
const warningString =`**[unit-test-warn]**
The component to be tested is missing.
The title of the Pull request should look like "fix(vue-renderless): [action-menu, alert] fix xxx bug".
Please make sure you've read our [contributing guide](https://github.com/opentiny/tiny-vue/blob/dev/CONTRIBUTING.md)
`
core.setOutput('tip', warningString)
core.warning(warningString)
}
- name: Check Utils Changes
id: check-utils-changes
run: |
# 从远程仓库获取目标分支的最新代码
git fetch origin ${{ github.base_ref }}
# 获取当前PR分支相对于目标分支的所有变更文件列表
CHANGED_FILES=$(git diff --name-only origin/${{ github.base_ref }}..HEAD)
# 使用grep检查变更文件列表中是否包含utils包的改动
# ^packages/utils/ 表示以packages/utils/开头的文件路径
if echo "$CHANGED_FILES" | grep -q "^packages/utils/"; then
# 如果检测到utils包有改动,设置modified输出变量为true
echo "modified=true" >> $GITHUB_OUTPUT
echo "Utils package has been modified, utils tests will be executed"
else
# 如果没有检测到utils包的改动,设置modified输出变量为false
echo "modified=false" >> $GITHUB_OUTPUT
echo "No changes detected in utils package"
fi
- name: generate user-tip.txt
if: ${{ steps.parseTitle.outputs.tip }}
run: |
cat << EOF > user-tip.txt
${{ steps.parseTitle.outputs.tip }}
EOF
- name: Upload User Tip
if: ${{ steps.parseTitle.outputs.tip }}
uses: actions/upload-artifact@v4
with:
name: user-tip
path: user-tip.txt
retention-days: 1
- name: Save PR number
if: ${{ steps.parseTitle.outputs.tip }}
run: echo ${{ github.event.number }} > ./pr-id.txt
- name: Upload PR number
if: ${{ steps.parseTitle.outputs.tip }}
uses: actions/upload-artifact@v4
with:
name: pr
path: ./pr-id.txt
pr-test:
name: PR Unit Test
needs: parse-components
runs-on: ubuntu-latest
env:
TEST_COMPONENTS: ${{ needs.parse-components.outputs.testComponents }}
UTILS_MODIFIED: ${{ needs.parse-components.outputs.utilsModified }}
steps:
- uses: actions/checkout@v3
- name: Setup pnpm
uses: pnpm/action-setup@v2
- name: Setup node
uses: actions/setup-node@v3
with:
node-version: 20
- name: Get pnpm store directory
id: pnpm-cache
run: |
echo "pnpm_cache_dir=$(pnpm store path)" >> $GITHUB_OUTPUT
- uses: actions/cache@v3
name: Setup pnpm cache
with:
path: ${{ steps.pnpm-cache.outputs.pnpm_cache_dir }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Install dependencies
run: pnpm i --no-frozen-lockfile
- name: Unit Test for Components
if: ${{ env.TEST_COMPONENTS }}
run: pnpm test:unit3 ${{ env.TEST_COMPONENTS }}
- name: Utils Unit Test
if: ${{ env.UTILS_MODIFIED == 'true' }}
run: pnpm test:utils