|
1 | | -name: EinoExtTest |
| 1 | +name: EinoExt CI |
2 | 2 |
|
3 | | -on: [ pull_request ] |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + push: |
| 6 | + branches: |
| 7 | + - main |
4 | 8 |
|
5 | 9 | jobs: |
6 | | - unit_test: |
7 | | - name: "eino ext unit test" |
| 10 | + unit-test: |
8 | 11 | runs-on: ubuntu-latest |
| 12 | + env: |
| 13 | + COVERAGE_FILE: coverage.out |
| 14 | + BREAKDOWN_FILE: base.coverage |
9 | 15 | steps: |
10 | 16 | - uses: actions/checkout@v4 |
11 | | - - name: "Set up Go" |
12 | | - uses: actions/setup-go@v5 |
| 17 | + - uses: actions/setup-go@v5 |
13 | 18 | with: |
14 | 19 | 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 |
16 | 43 | run: | |
17 | 44 | 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 | +
|
19 | 50 | list="" |
20 | 51 | 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 | +
|
23 | 61 | go work sync |
| 62 | +
|
| 63 | + coverprofiles=${COVERAGE_FILE} |
| 64 | +
|
24 | 65 | 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 |
29 | 73 | 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 |
43 | 78 | uses: vladopajic/go-test-coverage@v2 |
44 | 79 | with: |
| 80 | + profile: ${{env.COVERAGE_PROFILES}} |
45 | 81 | 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 |
54 | 86 | uses: actions/upload-artifact@v4 |
55 | 87 | if: github.ref_name == 'main' |
56 | 88 | 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}} |
59 | 91 | 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 }} |
62 | 94 | uses: peter-evans/find-comment@v3 |
| 95 | + continue-on-error: true |
63 | 96 | id: find-comment |
64 | 97 | with: |
65 | 98 | issue-number: ${{ github.event.pull_request.number }} |
66 | 99 | comment-author: 'github-actions[bot]' |
67 | 100 | 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 }} |
70 | 103 | uses: peter-evans/create-or-update-comment@v4 |
| 104 | + continue-on-error: true |
71 | 105 | with: |
72 | | - token: ${{ secrets.GITHUB_TOKEN }} |
73 | 106 | issue-number: ${{ github.event.pull_request.number }} |
74 | 107 | comment-id: ${{ steps.find-comment.outputs.comment-id || '' }} |
75 | 108 | edit-mode: replace |
76 | 109 | body: | |
77 | 110 | go-test-coverage report: |
78 | 111 | ``` |
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 |
85 | 115 | unit-benchmark-test: |
86 | 116 | runs-on: ubuntu-latest |
87 | 117 | steps: |
|
0 commit comments