Skip to content

Commit

Permalink
增量覆盖率从全量覆盖率的报告中去提取
Browse files Browse the repository at this point in the history
  • Loading branch information
代军 committed Sep 18, 2024
1 parent 5c4dfe5 commit 976b82a
Showing 1 changed file with 38 additions and 24 deletions.
62 changes: 38 additions & 24 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -223,30 +223,44 @@ jobs:
fi
- name: Run tests
run: |
echo $APPBUILDER_GO_TESTS
if [ "$APPBUILDER_GO_TESTS" = "False" ]; then
echo "环境变量APPBUILDER_GO_TESTS为False,没有检测到Go或Shell文件被更改,跳过Run tests部分。"
else
echo "检测到Go或Shell文件被更改(根据环境变量APPBUILDER_GO_TESTS),准备启动Run tests部分..."
cd cicd/app-builder/go/appbuilder
go test ./... -coverprofile=coverage.out -v -count=1
go tool cover -html=coverage.out -o coverage.html
echo "全量代码覆盖率为:"
go tool cover -func=coverage.out
echo "增量代码覆盖率:"
# 使用 diff-filter 和 grep 找出修改的 .go 文件
changed_files=$(git diff --name-only --diff-filter=ACMRT upstream/master | grep '.go' || true)
if [ -n "$changed_files" ]; then
# 直接对更改的文件进行测试
go test -coverprofile=incremental_coverage.out $changed_files
go tool cover -func=incremental_coverage.out
else
echo "没有增量Go文件被检测到。"
fi
fi
run: |
echo $APPBUILDER_GO_TESTS
if [ "$APPBUILDER_GO_TESTS" = "False" ]; then
echo "环境变量APPBUILDER_GO_TESTS为False,没有检测到Go文件被更改,跳过Run tests部分。"
else
echo "检测到Go文件被更改,准备启动Run tests部分..."
cd cicd/app-builder/go/appbuilder
# 运行全量测试并生成覆盖率报告
go test ./... -coverprofile=coverage.out -v -count=1
go tool cover -html=coverage.out -o coverage.html
echo "全量代码覆盖率为:"
go tool cover -func=coverage.out
echo "增量代码覆盖率:"
# 获取修改的 .go 文件列表(相对于当前目录)
changed_files=$(git diff --name-only --diff-filter=ACMRT upstream/master -- '*.go' || true)
echo "Changed files:"
echo "$changed_files"
if [ -n "$changed_files" ]; then
# 创建增量覆盖率报告文件,写入模式声明
echo "mode: set" > incremental_coverage.out
# 提取修改文件的覆盖率信息
for file in $changed_files; do
# 确保文件路径相对于当前目录
relative_file=$(realpath --relative-to=. "$file" || echo "$file")
echo "Processing file: $relative_file"
# 从全量覆盖率报告中提取对应文件的覆盖率信息
grep "$relative_file" coverage.out >> incremental_coverage.out || true
done
# 打印增量覆盖率结果
go tool cover -func=incremental_coverage.out
else
echo "没有增量Go文件被检测到。"
fi
fi
- name: Lint code
run: |
Expand Down

0 comments on commit 976b82a

Please sign in to comment.