forked from cloudwego/eino-ext
-
Notifications
You must be signed in to change notification settings - Fork 0
317 lines (280 loc) · 11.8 KB
/
tests.yml
File metadata and controls
317 lines (280 loc) · 11.8 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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
name: EinoExt CI
on:
pull_request:
push:
branches:
- main
env:
COVERAGE_FILE: coverage.out
COVERAGE_PROFILES: coverage.out
BREAKDOWN_FILE: base.coverage
jobs:
unit-test:
runs-on: ubuntu-latest
env:
COVERAGE_FILE: coverage.out
BREAKDOWN_FILE: base.coverage
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: "1.22"
# - name: Go test for every module
# run: |
# modules=`find . -name "go.mod" -exec dirname {} \;`
# echo "all the modules in eino-ext: "
# echo "${modules}"
# coverprofiles=""
# for module in $modules; do
# echo "--------------------------------------------------"
# echo "run unit test for ${module}"
# cd ${module}
# go test -race -coverprofile=./${COVERAGE_FILE} -gcflags="all=-l -N" -coverpkg=./... ./...
# cd -
# coverprofiles="${module}/${COVERAGE_FILE},$coverprofiles"
# done
# # Remove trailing comma from coverprofiles
# coverprofiles=${coverprofiles%,}
# echo "COVERAGE_PROFILES=$coverprofiles" >> $GITHUB_ENV
- name: Go test in go workspace
run: |
modules=`find . -name "go.mod" -exec dirname {} \;`
echo "all the modules in eino-ext: "
echo "${modules}"
if [[ ! -f "go.work" ]];then go work init;fi
list=""
coverpkg=""
for module in $modules; do
go work use ${module}
list="${module}/... ${list}"
coverpkg="${module}/...,${coverpkg}"
done
# trim the last comma
coverpkg=${coverpkg%,}
go work sync
coverprofiles=${COVERAGE_FILE}
go test -race -coverprofile=coverage.out -gcflags="all=-l -N" -coverpkg=$coverpkg $list
echo "COVERAGE_PROFILES=$coverprofiles" >> $GITHUB_ENV
- name: Download base.coverage for diff coverage rate
id: download-base-coverage
uses: actions/download-artifact@v4
continue-on-error: true
with:
name: ${{ env.BREAKDOWN_FILE }}
- name: Calculate coverage
id: calculate-coverage
uses: vladopajic/go-test-coverage@v2.12.1
with:
profile: ${{env.COVERAGE_PROFILES}}
config: ./.testcoverage.yml
breakdown-file-name: ${{ github.ref_name == 'main' && env.BREAKDOWN_FILE || '' }}
diff-base-breakdown-file-name: ${{ steps.download-base-coverage.outcome == 'success' && env.BREAKDOWN_FILE || '' }}
- name: Upload base.coverage of main branch
uses: actions/upload-artifact@v4
if: github.ref_name == 'main'
with:
name: ${{env.BREAKDOWN_FILE}}
path: ${{env.BREAKDOWN_FILE}}
if-no-files-found: error
- name: Find coverage report
if: ${{ always() && github.event.pull_request.number != null }}
uses: peter-evans/find-comment@v3
continue-on-error: true
id: find-comment
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: 'github-actions[bot]'
body-includes: 'go-test-coverage report:'
- name: Post coverage report
if: ${{ always() && github.event.pull_request.number != null }}
uses: peter-evans/create-or-update-comment@v4
continue-on-error: true
with:
issue-number: ${{ github.event.pull_request.number }}
comment-id: ${{ steps.find-comment.outputs.comment-id || '' }}
edit-mode: replace
body: |
go-test-coverage report:
```
${{ steps.calculate-coverage.outputs.report && fromJSON(steps.calculate-coverage.outputs.report) || 'No coverage report available' }} ```
reactions: heart
reactions-edit-mode: append
unit-benchmark-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: stable
- name: Go BenchMark
run: |
modules=`find . -name "go.mod" -exec dirname {} \;`
echo $modules
list=""
coverpkg=""
if [[ ! -f "go.work" ]];then go work init;fi
for module in $modules; do go work use $module; list=$module"/... "$list; coverpkg=$module"/...,"$coverpkg; done
go work sync
go test -bench=. -run=none -gcflags="all=-N -l" $list
check-submodule-changes:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
repository-projects: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Check modified files in submodules
id: check-mods
run: |
# Get all directories containing go.mod
modules=$(find . -name "go.mod" -exec dirname {} \;)
# Get list of modified files
if [ "${{ github.event_name }}" == "pull_request" ]; then
changed_files=$(git diff --name-only origin/${{ github.base_ref }} HEAD)
else
changed_files=$(git diff --name-only HEAD^ HEAD)
fi
# Initialize messages
echo "### Need to create a new tag" > tag_message.txt
echo "The following modules have changes and may need version updates:" >> tag_message.txt
echo "### Documentation Updates" > readme_message.txt
echo "The following README files have been modified:" >> readme_message.txt
need_tag=false
has_readme_changes=false
# Check each module
for module in $modules; do
module_name=${module#./}
# Check for module changes
if echo "$changed_files" | grep -q "^$module_name/"; then
latest_tag=$(git tag -l "${module_name}/v*" | sort -V | tail -n 1)
if [ ! -z "$latest_tag" ]; then
need_tag=true
echo -e "- \`${module_name}\` (Current: ${latest_tag})\n" >> tag_message.txt
fi
# Check for README changes
if echo "$changed_files" | grep -q "^$module_name/README\(_zh\)\?\.md$"; then
has_readme_changes=true
echo -e "- \`${module_name}\` README has been updated\n" >> readme_message.txt
fi
fi
done
# Different message for PR and merge
if [ "${{ github.event_name }}" == "pull_request" ]; then
echo -e "\n⚠️ Please create and push new version tags for these modules after merging this PR." >> tag_message.txt
echo -e "\n⚠️ Please update the official documentation after merging this PR." >> readme_message.txt
else
echo -e "\n⚠️ Changes have been merged to main branch. \nPlease create new version tags for these modules." >> tag_message.txt
echo -e "\n⚠️ Changes have been merged to main branch. \nPlease update the official documentation." >> readme_message.txt
fi
# Save message and prepare webhook payloads
repo_url="https://github.com/${{ github.repository }}/commit/${{ github.sha }}"
if [ "$need_tag" = true ]; then
message="$(cat tag_message.txt)"
jq -n --arg title "Need to create a new tag" \
--arg content "$message" \
--arg repo_url "$repo_url" \
'{
"msg_type": "interactive",
"card": {
"elements": [
{
"tag": "markdown",
"content": $content
},
{
"tag": "action",
"actions": [
{
"tag": "button",
"text": {
"tag": "plain_text",
"content": "🔗 View on GitHub"
},
"url": $repo_url,
"type": "default"
}
]
}
],
"header": {
"title": {
"tag": "plain_text",
"content": "Need to create a new tag"
}
}
}
}' > tag_webhook_payload.json
fi
if [ "$has_readme_changes" = true ]; then
message="$(cat readme_message.txt)"
jq -n --arg title "Documentation Updates" \
--arg content "$message" \
--arg repo_url "$repo_url" \
'{
"msg_type": "interactive",
"card": {
"elements": [
{
"tag": "markdown",
"content": $content
},
{
"tag": "action",
"actions": [
{
"tag": "button",
"text": {
"tag": "plain_text",
"content": "🔗 View Changes on GitHub"
},
"url": $repo_url,
"type": "default"
}
]
}
],
"header": {
"title": {
"tag": "plain_text",
"content": "Documentation Updates Required"
}
}
}
}' > readme_webhook_payload.json
fi
echo "needs_tag=$need_tag" >> $GITHUB_OUTPUT
echo "has_readme_changes=$has_readme_changes" >> $GITHUB_OUTPUT
- name: Find existing comment
if: steps.check-mods.outputs.needs_tag == 'true' && github.event_name == 'pull_request'
uses: peter-evans/find-comment@v3
id: find-comment
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: 'github-actions[bot]'
body-includes: "### 🏷️ Tag Version Reminder"
- name: Post or update PR comment
if: steps.check-mods.outputs.needs_tag == 'true' && github.event_name == 'pull_request'
uses: peter-evans/create-or-update-comment@v4
with:
issue-number: ${{ github.event.pull_request.number }}
comment-id: ${{ steps.find-comment.outputs.comment-id }}
body-file: tag_message.txt
edit-mode: replace
- name: Send tag webhook notification
if: steps.check-mods.outputs.needs_tag == 'true' && github.event_name == 'push'
run: |
curl -X POST \
-H "Content-Type: application/json" \
-d @tag_webhook_payload.json \
"${{ secrets.FEISHU_WEBHOOK_URL }}"
- name: Send readme webhook notification
if: steps.check-mods.outputs.has_readme_changes == 'true' && github.event_name == 'push'
run: |
curl -X POST \
-H "Content-Type: application/json" \
-d @readme_webhook_payload.json \
"${{ secrets.FEISHU_WEBHOOK_URL }}"