Skip to content

Commit 912c968

Browse files
authored
feat: run unit test in go workspace & check package coverage (#85)
1 parent c45d78c commit 912c968

File tree

4 files changed

+119
-52
lines changed

4 files changed

+119
-52
lines changed

.github/workflows/tests.yml

Lines changed: 78 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,87 +1,117 @@
1-
name: EinoExtTest
1+
name: EinoExt CI
22

3-
on: [ pull_request ]
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- main
48

59
jobs:
6-
unit_test:
7-
name: "eino ext unit test"
10+
unit-test:
811
runs-on: ubuntu-latest
12+
env:
13+
COVERAGE_FILE: coverage.out
14+
BREAKDOWN_FILE: base.coverage
915
steps:
1016
- uses: actions/checkout@v4
11-
- name: "Set up Go"
12-
uses: actions/setup-go@v5
17+
- uses: actions/setup-go@v5
1318
with:
1419
go-version: "1.22"
15-
- name: "GoTest"
20+
# - name: Go test for every module
21+
# run: |
22+
# modules=`find . -name "go.mod" -exec dirname {} \;`
23+
# echo "all the modules in eino-ext: "
24+
# echo "${modules}"
25+
26+
# coverprofiles=""
27+
# for module in $modules; do
28+
# echo "--------------------------------------------------"
29+
# echo "run unit test for ${module}"
30+
31+
# cd ${module}
32+
# go test -race -coverprofile=./${COVERAGE_FILE} -gcflags="all=-l -N" -coverpkg=./... ./...
33+
# cd -
34+
# coverprofiles="${module}/${COVERAGE_FILE},$coverprofiles"
35+
# done
36+
37+
# # Remove trailing comma from coverprofiles
38+
# coverprofiles=${coverprofiles%,}
39+
40+
# echo "COVERAGE_PROFILES=$coverprofiles" >> $GITHUB_ENV
41+
42+
- name: Go test in go workspace
1643
run: |
1744
modules=`find . -name "go.mod" -exec dirname {} \;`
18-
echo $modules
45+
echo "all the modules in eino-ext: "
46+
echo "${modules}"
47+
48+
if [[ ! -f "go.work" ]];then go work init;fi
49+
1950
list=""
2051
coverpkg=""
21-
if [[ ! -f "go.work" ]];then go work init;fi
22-
for module in $modules; do go work use $module; list=$module"/... "$list; coverpkg=$module"/...,"$coverpkg; done
52+
for module in $modules; do
53+
go work use ${module}
54+
list="${module}/... ${list}"
55+
coverpkg="${module}/...,${coverpkg}"
56+
done
57+
58+
# trim the last comma
59+
coverpkg=${coverpkg%,}
60+
2361
go work sync
62+
63+
coverprofiles=${COVERAGE_FILE}
64+
2465
go test -race -coverprofile=coverage.out -gcflags="all=-l -N" -coverpkg=$coverpkg $list
25-
# Download main (aka base) branch breakdown
26-
- name: Download Artifact (main.breakdown)
27-
id: download-main-breakdown
28-
uses: dawidd6/action-download-artifact@v6
66+
67+
echo "COVERAGE_PROFILES=$coverprofiles" >> $GITHUB_ENV
68+
69+
- name: Download base.coverage for diff coverage rate
70+
id: download-base-coverage
71+
uses: actions/download-artifact@v4
72+
continue-on-error: true
2973
with:
30-
branch: main
31-
workflow_conclusion: success
32-
name: main.breakdown
33-
if_no_artifact_found: warn
34-
- name: Ensure default.breakdown exists if download fails
35-
run: |
36-
if [ ! -f main.breakdown ]; then
37-
echo "main.breakdown not found. Creating an empty main.breakdown file."
38-
touch main.breakdown
39-
else
40-
echo "main.breakdown found."
41-
fi
42-
- name: "Test Coverage"
74+
name: ${{ env.BREAKDOWN_FILE }}
75+
76+
- name: Calculate coverage
77+
id: calculate-coverage
4378
uses: vladopajic/go-test-coverage@v2
4479
with:
80+
profile: ${{env.COVERAGE_PROFILES}}
4581
config: ./.testcoverage.yml
46-
# Save current coverage breakdown if current branch is main. It will be
47-
# uploaded as artifact in step below.
48-
breakdown-file-name: ${{ github.ref_name == 'main' && 'main.breakdown' || '' }}
49-
50-
# If this is not main branch we want to show report including
51-
# file coverage difference from main branch.
52-
diff-base-breakdown-file-name: ${{ steps.download-main-breakdown.outputs.found_artifact && 'main.breakdown' || 'main.breakdown' }}
53-
- name: Upload Artifact (main.breakdown)
82+
breakdown-file-name: ${{ github.ref_name == 'main' && env.BREAKDOWN_FILE || '' }}
83+
diff-base-breakdown-file-name: ${{ steps.download-base-coverage.download-path != '' && env.BREAKDOWN_FILE || '' }}
84+
85+
- name: Upload base.coverage of main branch
5486
uses: actions/upload-artifact@v4
5587
if: github.ref_name == 'main'
5688
with:
57-
name: main.breakdown
58-
path: main.breakdown # as specified via `breakdown-file-name`
89+
name: ${{env.BREAKDOWN_FILE}}
90+
path: ${{env.BREAKDOWN_FILE}}
5991
if-no-files-found: error
60-
- name: find if coverage report is already present
61-
if: ${{ github.event.pull_request.number != null }}
92+
- name: Find coverage report
93+
if: ${{ always() && github.event.pull_request.number != null }}
6294
uses: peter-evans/find-comment@v3
95+
continue-on-error: true
6396
id: find-comment
6497
with:
6598
issue-number: ${{ github.event.pull_request.number }}
6699
comment-author: 'github-actions[bot]'
67100
body-includes: 'go-test-coverage report:'
68-
- name: post coverage report
69-
if: ${{ github.event.pull_request.number != null }}
101+
- name: Post coverage report
102+
if: ${{ always() && github.event.pull_request.number != null }}
70103
uses: peter-evans/create-or-update-comment@v4
104+
continue-on-error: true
71105
with:
72-
token: ${{ secrets.GITHUB_TOKEN }}
73106
issue-number: ${{ github.event.pull_request.number }}
74107
comment-id: ${{ steps.find-comment.outputs.comment-id || '' }}
75108
edit-mode: replace
76109
body: |
77110
go-test-coverage report:
78111
```
79-
${{ steps.coverage.outputs.report && fromJSON(steps.coverage.outputs.report) || 'No coverage report available' }} ```
80-
81-
- name: "finally check coverage"
82-
if: steps.coverage.outcome == 'failure'
83-
shell: bash
84-
run: echo "coverage check failed" && exit 1
112+
${{ steps.calculate-coverage.outputs.report && fromJSON(steps.calculate-coverage.outputs.report) || 'No coverage report available' }} ```
113+
reactions: heart
114+
reactions-edit-mode: append
85115
unit-benchmark-test:
86116
runs-on: ubuntu-latest
87117
steps:

.testcoverage.yml

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,52 @@ profile: coverage.out
99

1010
# (optional; but recommended to set)
1111
# When specified reported file paths will not contain local prefix in the output.
12-
local-prefix: "github.com/cloudwego/eino"
12+
local-prefix: "github.com/cloudwego/eino-ext"
1313

1414
# Holds coverage thresholds percentages, values should be in range [0-100].
1515
threshold:
1616
# (optional; default 0)
1717
# Minimum overall project coverage percentage required.
18-
total: 68
18+
total: 66
19+
package: 70
20+
file: 0 # Set to 0 to effectively ignore file-level coverage checks
21+
22+
override:
23+
# Adjust coverage threshold to xx% for specific packages.
24+
- path: ^libs/acl/langfuse
25+
threshold: 0
26+
- path: ^callbacks/langfuse
27+
threshold: 0
28+
- path: ^components/document/loader/file
29+
threshold: 0
30+
- path: ^components/retriever/es8
31+
threshold: 0
32+
- path: ^components/indexer/es8
33+
threshold: 0
34+
- path: ^components/model/openai
35+
threshold: 0
36+
- path: ^libs/acl/openai
37+
threshold: 0
38+
- path: ^devops
39+
threshold: 0
40+
- path: ^components/model/gemini
41+
threshold: 0
42+
- path: ^components/model/qwen
43+
threshold: 0
44+
- path: ^components/retriever/volc_knowledge
45+
threshold: 0
46+
- path: ^components/model/claude
47+
threshold: 0
48+
- path: ^components/embedding/qianfan
49+
threshold: 0
50+
- path: ^components/indexer/redis
51+
threshold: 0
52+
- path: ^components/model/qianfan
53+
threshold: 0
54+
- path: ^components/tool/duckduckgo
55+
threshold: 0
56+
- path: ^components/retriever/volc_vikingdb
57+
threshold: 0
1958

2059
# Holds regexp rules which will exclude matched files or packages
2160
# from coverage statistics.

components/model/gemini/go.mod

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ module github.com/cloudwego/eino-ext/components/model/gemini
22

33
go 1.21
44

5-
toolchain go1.23.0
6-
75
require (
86
github.com/bytedance/mockey v1.2.13
97
github.com/bytedance/sonic v1.12.2
File renamed without changes.

0 commit comments

Comments
 (0)