Skip to content

Commit

Permalink
Add Codecov tool to show the code coverages (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
sulenn authored Jul 9, 2020
1 parent 365a10c commit b9eb818
Show file tree
Hide file tree
Showing 12 changed files with 809 additions and 384 deletions.
9 changes: 0 additions & 9 deletions .ci/ci_check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,10 @@ function stop_nodes()
execute_cmd "./nodes/127.0.0.1/stop_all.sh"
}

# test the common jsonRPC interface
function test_rpc_connection()
{
LOG_INFO "## test commonRPCInterface..."
# rpc client testing
execute_cmd "go test -v -count=1 ./client"
}

function main()
{
build_blockchain
start_nodes
test_rpc_connection
}

main
63 changes: 63 additions & 0 deletions .ci/generate_coverage.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/bin/bash

GOPATH_BIN=$(go env GOPATH)/bin

LOG_ERROR() {
content=${1}
echo -e "\033[31m${content}\033[0m"
}

LOG_INFO() {
content=${1}
echo -e "\033[32m${content}\033[0m"
}

execute_cmd() {
command="${1}"
eval "${command}"
ret=$?
if [ $ret -ne 0 ]; then
LOG_ERROR "FAILED of command: ${command}"
exit 1
else
LOG_INFO "SUCCESS of command: ${command}"
fi
}

generate_hello() {
local struct="${1}"
local output="${2}"
go get -u github.com/sqs/goreturns # to format code style
cat << EOF >> "${output}"
func main() {
configs := conf.ParseConfig("config.toml")
client, err := client.Dial(&configs[0])
if err != nil {
fmt.Printf("Dial Client failed, err:%v", err)
return
}
address, tx, _, err := Deploy${struct}(client.GetTransactOpts(), client)
if err != nil {
fmt.Printf("Deploy failed, err:%v", err)
return
}
fmt.Println(address.Hex()) // the address should be saved
fmt.Println(tx.Hash().Hex())
}
EOF
"${GOPATH_BIN}"/goreturns -w "${output}"
}

calculate_coverage() {
# start blockchain demo
curl -LO https://raw.githubusercontent.com/FISCO-BCOS/FISCO-BCOS/master/tools/build_chain.sh && chmod u+x build_chain.sh
bash build_chain.sh -l 127.0.0.1:4 -o nodes
cp nodes/127.0.0.1/sdk/* ./
bash nodes/127.0.0.1/start_all.sh

# generate code coverage report
go test ./... -race -coverprofile=coverage.txt -covermode=atomic
}

calculate_coverage
237 changes: 237 additions & 0 deletions .ci/hello/HelloWorld.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Calculate Code Coverage
on:
push:
paths-ignore:
- "Changelog.md"
- "README.md"
pull_request:

jobs:
coverage:
name: coverage
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 1
- uses: actions/setup-go@v2
with:
go-version: 1.14
- name: generate code coverage report
run: bash .ci/generate_coverage.sh
- name: upload code coverage to Codecov
uses: codecov/codecov-action@v1
with:
file: ./coverage.txt
name: go-sdk code coverage
fail_ci_if_error: true
4 changes: 1 addition & 3 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,4 @@ jobs:
- name: check commit
run: bash .ci/check-commit.sh
- name: test
run: bash .ci/integration_test.sh
# - name: generate code coverage
# run:
run: bash .ci/integration_test.sh
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ ca.crt
# Test binary, built with `go test -c`
*.test

# code coverage file
coverage.txt

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

Expand Down
Loading

0 comments on commit b9eb818

Please sign in to comment.