Skip to content

Commit

Permalink
feat: fix workflow's coverage report (#20)
Browse files Browse the repository at this point in the history
* feat: fix workflow's coverage report

* chore: adjust typos

* chore: trigger unit test when merge main
  • Loading branch information
hi-pender authored Dec 30, 2024
1 parent 92e033c commit 19e6f5c
Show file tree
Hide file tree
Showing 9 changed files with 114 additions and 64 deletions.
103 changes: 60 additions & 43 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,30 @@
name: EinoTests

on: [ pull_request ]
on:
pull_request:
push:
branches:
- main

env:
DEFAULT_GO_VERSION: "1.18"

jobs:
unit_test:
name: "eino unit test"
unit-test:
name: eino-unit-test
runs-on: ubuntu-latest
env:
COVERAGE_FILE: coverage.out
BREAKDOWN_FILE: main.breakdown

steps:
- uses: actions/checkout@v4
- name: "Set up Go"
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: "1.18"
- name: "GoTest"
go-version: ${{ env.DEFAULT_GO_VERSION }}

- name: Exec Go Test
run: |
modules=`find . -name "go.mod" -exec dirname {} \;`
echo $modules
Expand All @@ -21,51 +33,54 @@ jobs:
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 -race -coverprofile=coverage.out -gcflags="all=-l -N" -coverpkg=$coverpkg $list
# Download main (aka base) branch breakdown
go test -race -v -coverprofile=${{ env.COVERAGE_FILE }} -gcflags="all=-l -N" -coverpkg=$coverpkg $list
- name: Download Artifact (main.breakdown)
id: download-main-breakdown
uses: dawidd6/action-download-artifact@v6
uses: actions/download-artifact@v4
continue-on-error: true
with:
branch: main
workflow_conclusion: success
name: main.breakdown
if_no_artifact_found: warn
- name: Ensure default.breakdown exists if download fails
name: ${{ env.BREAKDOWN_FILE }}
fail-not-found: false

- name: Create main.breakdown If Not Exist
run: |
if [ ! -f main.breakdown ]; then
echo "main.breakdown not found. Creating an empty main.breakdown file."
touch main.breakdown
if [ ! -f ${{ env.BREAKDOWN_FILE }} ]; then
echo "${{ env.BREAKDOWN_FILE }} not found. Creating an empty file."
touch ${{ env.BREAKDOWN_FILE }}
else
echo "main.breakdown found."
echo "${{ env.BREAKDOWN_FILE }} found."
fi
- name: "Test Coverage"
- name: Calculate Coverage
id: coverage
uses: vladopajic/go-test-coverage@v2
with:
config: ./.testcoverage.yml
# Save current coverage breakdown if current branch is main. It will be
# uploaded as artifact in step below.
breakdown-file-name: ${{ github.ref_name == 'main' && 'main.breakdown' || '' }}
profile: ${{ env.COVERAGE_FILE}}
breakdown-file-name: ${{ github.ref_name == 'main' && env.BREAKDOWN_FILE || '' }}
diff-base-breakdown-file-name: ${{ env.BREAKDOWN_FILE }}

# If this is not main branch we want to show report including
# file coverage difference from main branch.
diff-base-breakdown-file-name: ${{ steps.download-main-breakdown.outputs.found_artifact && 'main.breakdown' || 'main.breakdown' }}
# to generate and embed coverage badges in markdown files
git-token: ${{ github.ref_name == 'main' && secrets.GITHUB_TOKEN || '' }}
git-branch: badges

- name: Upload Artifact (main.breakdown)
uses: actions/upload-artifact@v4
if: github.ref_name == 'main'
with:
name: main.breakdown
path: main.breakdown # as specified via `breakdown-file-name`
name: ${{ env.BREAKDOWN_FILE }}
path: ${{ env.BREAKDOWN_FILE }}
if-no-files-found: error
- name: find if coverage report is already present
- name: Find If coverage Report Exist
if: ${{ github.event.pull_request.number != null }}
uses: peter-evans/find-comment@v3
id: fc
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: 'github-actions[bot]'
body-includes: 'go-test-coverage report:'
- name: post coverage report
body-includes: '📊 Coverage Report'
- name: Send Coverage Report
if: ${{ github.event.pull_request.number != null }}
uses: peter-evans/create-or-update-comment@v4
with:
Expand All @@ -74,40 +89,42 @@ jobs:
comment-id: ${{ steps.fc.outputs.comment-id || '' }}
edit-mode: replace
body: |
go-test-coverage report:
## 📊 Coverage Report:
```
${{ steps.coverage.outputs.report && fromJSON(steps.coverage.outputs.report) || 'No coverage report available' }}
```
${{ steps.coverage.outputs.report && fromJSON(steps.coverage.outputs.report) || 'No coverage report available' }} ```
- name: "finally check coverage"
- name: Check Coverage
if: steps.coverage.outcome == 'failure'
shell: bash
run: echo "coverage check failed" && exit 1
unit-benchmark-test:
benchmark-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: stable
go-version: ${{ env.DEFAULT_GO_VERSION }}

- name: Unit Test
run: go test -race -covermode=atomic -coverprofile=coverage.out ./...

- name: Benchmark
- name: Run Benchmark Tests
run: go test -bench=. -benchmem -run=none ./...

compatibility-test:
strategy:
matrix:
go: [ "1.18", "1.19", "1.20", "1.21", "1.22" ]
go: [ "1.19", "1.20", "1.21", "1.22" ]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go }}
cache: true # don't use cache for self-hosted runners
- name: Unit Test
run: go test -race -covermode=atomic ./...
cache: true

- name: Compatibility Test
run: |
# just basic unit test, no coverage report
go test -race ./...
17 changes: 17 additions & 0 deletions .licenserc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,23 @@ header:
spdx-id: Apache-2.0
copyright-owner: CloudWeGo Authors

template: |
/*
* Copyright {{ .Year }} CloudWeGo Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
paths:
- '**/*.go'
- '**/*.s'
Expand Down
38 changes: 27 additions & 11 deletions .testcoverage.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
# (mandatory)
# Path to coverage profile file (output of `go test -coverprofile` command).
#
# For cases where there are many coverage profiles, such as when running
# unit tests and integration tests separately, you can combine all those
# profiles into one. In this case, the profile should have a comma-separated list
# of profile files, e.g., 'cover_unit.out,cover_integration.out'.
profile: coverage.out

# (optional; but recommended to set)
# When specified reported file paths will not contain local prefix in the output.
local-prefix: "github.com/cloudwego/eino"
Expand All @@ -17,11 +8,36 @@ threshold:
# Minimum overall project coverage percentage required.
total: 75

package: 30

# (optional; default 0)
# Minimum coverage percentage required for individual files.
file: 20

by-package:
threshold: 30
show-all: false
top-n: 5
bottom-n: 5

by-file:
threshold: 20
show-all: false
top-n: 5
bottom-n: 5

diff:
threshold: 80
show-all: true
new-code: true
modified-code: true

# Holds regexp rules which will exclude matched files or packages
# from coverage statistics.
exclude:
# Exclude files or packages matching their paths
paths:
- "tests"
- "examples/"
- "mock/"
- "mock/"
- "callbacks/interface.go"
- "utils/safe"
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Eino

![coverage](https://raw.githubusercontent.com/cloudwego/eino/badges/.badges/main/coverage.svg)

English | [中文](README.zh_CN.md)

## Overview
Expand Down
2 changes: 2 additions & 0 deletions README.zh_CN.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Eino

![coverage](https://raw.githubusercontent.com/cloudwego/eino/badges/.badges/main/coverage.svg)

[English](README.md) | 中文


Expand Down
4 changes: 0 additions & 4 deletions _typos.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ Invokable = "Invokable"
invokable = "invokable"
InvokableLambda = "InvokableLambda"
InvokableRun = "InvokableRun"
outter = "outter"
Opion = "Opion"
TOpion = "TOpion"
renderring = "renderring"

[files]
extend-exclude = ["go.mod", "go.sum", "check_branch_name.sh"]
6 changes: 3 additions & 3 deletions compose/chain_branch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ func TestChainBranch(t *testing.T) {
return in + in + in, nil
})))

outter := NewChain[string, string]()
outter.AppendGraph(inner)
_, err := outter.Compile(context.Background())
outer := NewChain[string, string]()
outer.AppendGraph(inner)
_, err := outer.Compile(context.Background())
assert.Error(t, err)
})

Expand Down
4 changes: 2 additions & 2 deletions compose/runnable.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,8 +314,8 @@ func streamByInvoke[I, O, TOption any](i Invoke[I, O, TOption]) Stream[I, O, TOp
}
}

func streamByCollect[I, O, TOpion any](c Collect[I, O, TOpion]) Stream[I, O, TOpion] {
return func(ctx context.Context, input I, opts ...TOpion) (output *schema.StreamReader[O], err error) {
func streamByCollect[I, O, TOption any](c Collect[I, O, TOption]) Stream[I, O, TOption] {
return func(ctx context.Context, input I, opts ...TOption) (output *schema.StreamReader[O], err error) {
action := actionStreamByCollect

srInput := schema.StreamReaderFromArray([]I{input})
Expand Down
2 changes: 1 addition & 1 deletion schema/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ func formatContent(content string, vs map[string]any, formatType FormatType) (st
}
}

// Format returns the messages after renderring by the given formatType.
// Format returns the messages after rendering by the given formatType.
// e.g.
//
// msg := schema.UserMessage("hello world, {name}")
Expand Down

0 comments on commit 19e6f5c

Please sign in to comment.