Browse Source

fea(ci): support codecov for ekuiper (#1684)

* fix(ci): add code coverage

Signed-off-by: Jianxiang Ran <rxan_embedded@163.com>
superxan 2 years ago
parent
commit
e369cd7666
5 changed files with 112 additions and 13 deletions
  1. 87 0
      .github/workflows/run_test_coverage.yaml
  2. 1 0
      README-CN.md
  3. 1 0
      README.md
  4. 9 0
      codecov.yaml
  5. 14 13
      internal/topo/topotest/plugin_rule_test.go

+ 87 - 0
.github/workflows/run_test_coverage.yaml

@@ -0,0 +1,87 @@
+name: Run test coverage
+
+concurrency:
+  group: code-coverage-${{ github.event_name }}-${{ github.ref }}
+  cancel-in-progress: true
+
+on:
+  push:
+    tags:
+      - "*"
+    ## For update codecov.io
+    branches:
+      - master**
+  pull_request:
+  release:
+    types:
+      - published
+
+jobs:
+  run_test_coverage:
+    runs-on: ubuntu-latest
+
+    steps:
+    - uses: actions/checkout@v3
+    - uses: actions/setup-go@v3
+      with:
+        go-version: '1.20'
+    - uses: actions/setup-python@v4
+      with:
+        python-version: '3.x'
+        architecture: 'x64'
+    - run: pip3 install pynng
+    - name: install lib
+      run: sudo apt-get update && sudo apt-get install libzmq3-dev -y
+    - name: run test coverage
+      run: |
+        curl -sSf https://raw.githubusercontent.com/WasmEdge/WasmEdge/master/utils/install.sh | bash > /dev/null && source $HOME/.wasmedge/env
+        mkdir -p plugins/wasm
+        set -e -u -x
+        mkdir -p data
+        mkdir -p log
+        mkdir -p plugins/sinks
+        sed -i -r "s/debug: .*/debug: true/1" etc/kuiper.yaml
+        go build --buildmode=plugin -o plugins/sources/Random@v2.0.0.so extensions/sources/random/random.go
+        cp extensions/sources/random/random.yaml etc/sources/random.yaml
+        go build --buildmode=plugin -o plugins/functions/Echo.so extensions/functions/echo/echo.go
+        go build --buildmode=plugin -o plugins/functions/CountPlusOne@v1.0.0.so extensions/functions/countPlusOne/countPlusOne.go
+        go build --buildmode=plugin -o plugins/functions/AccumulateWordCount@v1.0.0.so extensions/functions/accumulateWordCount/accumulateWordCount.go
+        go build --buildmode=plugin -o data/test/helloworld.so internal/converter/protobuf/test/*.go
+        go build --buildmode=plugin -o data/test/myFormat.so internal/converter/custom/test/*.go
+        mkdir -p plugins/portable/mirror
+        cd sdk/go/example/mirror
+        go build -o ../../../../plugins/portable/mirror/mirror .
+        cp mirror.json ../../../../plugins/portable/mirror
+        cd ../../../../
+        cp -r sdk/python/example/pysam plugins/portable/pysam
+        cp -r sdk/python/ekuiper plugins/portable/pysam/
+        go test --tags="edgex script test" -cover $(go list ./... | grep -v "github.com/lf-edge/ekuiper/internal/service/test" | grep -v "github.com/lf-edge/ekuiper/internal/converter/protobuf/test" | grep -v "github.com/lf-edge/ekuiper/test" | grep -v "github.com/lf-edge/ekuiper/tools" | grep -v "github.com/lf-edge/ekuiper/internal/topo/topotest/plugin") -coverprofile coverage.out -coverpkg  ./...
+        go tool cover -func coverage.out -o coverage.out
+    - uses: actions/upload-artifact@v3
+      with:
+        name: coverprofile
+        path: | 
+          *.out
+
+  codecov:
+    runs-on: ubuntu-latest
+    needs:
+      - run_test_coverage
+    steps:
+    - uses: actions/download-artifact@v3
+      with:
+        name: coverprofile
+    - name: Get cover files
+      id: files
+      run: |
+        files="$(find -maxdepth 1 -name '*.out' -exec readlink -f '{}' ';' | tr '\n' ',' | sed 's/,$//g')"
+        echo "files=$files" >> $GITHUB_OUTPUT
+    - uses: codecov/codecov-action@v3
+      with:
+        token: ${{ secrets.CODECOV_TOKEN }}
+        files: ${{ steps.files.outputs.files }} # optional
+        fail_ci_if_error: true # optional (default = false)
+        verbose: true # optional (default = false)
+    - uses: geekyeggo/delete-artifact@v2
+      with:
+        name: coverprofile

+ 1 - 0
README-CN.md

@@ -1,6 +1,7 @@
 # LF Edge eKuiper - 超轻量物联网边缘数据分析软件
 [![GitHub Release](https://img.shields.io/github/release/lf-edge/ekuiper?color=brightgreen)](https://github.com/lf-edge/ekuiper/releases)
 [![Docker Pulls](https://img.shields.io/docker/pulls/emqx/kuiper)](https://hub.docker.com/r/lfedge/ekuiper)
+[![codecov](https://codecov.io/gh/lf-edge/ekuiper/branch/master/graph/badge.svg?token=24E9Q3C0M0)](https://codecov.io/gh/lf-edge/ekuiper)
 [![Go Report Card](https://goreportcard.com/badge/github.com/lf-edge/ekuiper)](https://goreportcard.com/report/github.com/lf-edge/ekuiper)
 [![Slack](https://img.shields.io/badge/Slack-LF%20Edge-39AE85?logo=slack)](https://slack.lfedge.org/)
 [![Twitter](https://img.shields.io/badge/Follow-EMQ-1DA1F2?logo=twitter)](https://twitter.com/EMQTech)

+ 1 - 0
README.md

@@ -2,6 +2,7 @@
 
 [![GitHub Release](https://img.shields.io/github/release/lf-edge/ekuiper?color=brightgreen)](https://github.com/lf-edge/ekuiper/releases)
 [![Docker Pulls](https://img.shields.io/docker/pulls/emqx/kuiper)](https://hub.docker.com/r/lfedge/ekuiper)
+[![codecov](https://codecov.io/gh/lf-edge/ekuiper/branch/master/graph/badge.svg?token=24E9Q3C0M0)](https://codecov.io/gh/lf-edge/ekuiper)
 [![Go Report Card](https://goreportcard.com/badge/github.com/lf-edge/ekuiper)](https://goreportcard.com/report/github.com/lf-edge/ekuiper)
 [![Slack](https://img.shields.io/badge/Slack-LF%20Edge-39AE85?logo=slack)](https://slack.lfedge.org/)
 [![Twitter](https://img.shields.io/badge/Follow-EMQ-1DA1F2?logo=twitter)](https://twitter.com/EMQTech)

+ 9 - 0
codecov.yaml

@@ -0,0 +1,9 @@
+codecov:
+  disable_default_path_fixes: true
+
+fixes:
+  - "github.com/lf-edge/ekuiper::"
+
+ignore:
+  - "**/main.go"
+  - "main.go"

+ 14 - 13
internal/topo/topotest/plugin_rule_test.go

@@ -12,7 +12,7 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-package topotest
+package plugin
 
 import (
 	"bufio"
@@ -24,6 +24,7 @@ import (
 	"github.com/lf-edge/ekuiper/internal/conf"
 	"github.com/lf-edge/ekuiper/internal/plugin/native"
 	"github.com/lf-edge/ekuiper/internal/topo/planner"
+	"github.com/lf-edge/ekuiper/internal/topo/topotest"
 	"github.com/lf-edge/ekuiper/internal/topo/topotest/mockclock"
 	"github.com/lf-edge/ekuiper/pkg/api"
 	"os"
@@ -57,7 +58,7 @@ func TestExtensions(t *testing.T) {
 	log := conf.Log
 	//Reset
 	streamList := []string{"ext", "ext2"}
-	HandleStream(false, streamList, t)
+	topotest.HandleStream(false, streamList, t)
 	os.Remove(CACHE_FILE)
 	os.Create(CACHE_FILE)
 	var tests = []struct {
@@ -76,12 +77,12 @@ func TestExtensions(t *testing.T) {
 			maxLength: 2,
 		},
 	}
-	HandleStream(true, streamList, t)
+	topotest.HandleStream(true, streamList, t)
 	fmt.Printf("The test bucket size is %d.\n\n", len(tests))
 	for i, tt := range tests {
 		mockclock.ResetClock(1541152486000)
 		// Create rule
-		rs, err := CreateRule(tt.name, tt.rj)
+		rs, err := topotest.CreateRule(tt.name, tt.rj)
 		if err != nil {
 			t.Errorf("failed to create rule: %s.", err)
 			continue
@@ -175,9 +176,9 @@ func getResults() []string {
 func TestFuncState(t *testing.T) {
 	//Reset
 	streamList := []string{"text"}
-	HandleStream(false, streamList, t)
+	topotest.HandleStream(false, streamList, t)
 	//Data setup
-	var tests = []RuleTest{
+	var tests = []topotest.RuleTest{
 		{
 			Name: `TestFuncStateRule1`,
 			Sql:  `SELECT accumulateWordCount(slogan, " ") as wc FROM text`,
@@ -223,8 +224,8 @@ func TestFuncState(t *testing.T) {
 			},
 		},
 	}
-	HandleStream(true, streamList, t)
-	DoRuleTest(t, tests, 0, &api.RuleOption{
+	topotest.HandleStream(true, streamList, t)
+	topotest.DoRuleTest(t, tests, 0, &api.RuleOption{
 		BufferLength: 100,
 		SendError:    true,
 	}, 0)
@@ -232,10 +233,10 @@ func TestFuncState(t *testing.T) {
 
 func TestFuncStateCheckpoint(t *testing.T) {
 	streamList := []string{"text"}
-	HandleStream(false, streamList, t)
-	var tests = []RuleCheckpointTest{
+	topotest.HandleStream(false, streamList, t)
+	var tests = []topotest.RuleCheckpointTest{
 		{
-			RuleTest: RuleTest{
+			RuleTest: topotest.RuleTest{
 				Name: `TestFuncStateCheckpointRule1`,
 				Sql:  `SELECT accumulateWordCount(slogan, " ") as wc FROM text`,
 				R: [][]map[string]interface{}{
@@ -300,8 +301,8 @@ func TestFuncStateCheckpoint(t *testing.T) {
 			},
 		},
 	}
-	HandleStream(true, streamList, t)
-	DoCheckpointRuleTest(t, tests, 0, &api.RuleOption{
+	topotest.HandleStream(true, streamList, t)
+	topotest.DoCheckpointRuleTest(t, tests, 0, &api.RuleOption{
 		BufferLength:       100,
 		Qos:                api.AtLeastOnce,
 		CheckpointInterval: 2000,