GitHub中Codecov上传失败:本地生成.gcov但CI中无法找到
GitHub CI/CD中Codecov上传失败问题排查
背景
我正在尝试使用GitHub的CI/CD功能,但遇到了问题。我有一个极简仓库,设定为当develop分支推送至GitHub时,自动运行单元测试和覆盖率测试。
问题概述
单元测试已通过,但Codecov上传失败,报错如下:
['error'] None of the following appear to exist as files: ./build/gcov/*.gcov
但在本地Ubuntu环境中运行相同的Makefile时,./build/gcov/目录下确实会生成对应的.gcov文件。我漏了什么配置吗?
详细信息
你可以克隆该仓库自行测试,以下是关键文件和运行记录:
.github/workflows/ci.yml 配置文件
name: C/C++ CI on: push: branches: [ develop ] pull_request: branches: [ develop ] jobs: build_and_test: runs-on: ubuntu-latest steps: - name: Check out repository code uses: actions/checkout@v2 - name: Install dependencies run: sudo apt-get install -y gcc make lcov - name: Build and Test run: | make all make coverage - name: Upload coverage to Codecov uses: codecov/codecov-action@v2 with: files: ./build/gcov/*.gcov flags: unittests name: codecov-umbrella fail_ci_if_error: true
Codecov执行报告
Run codecov/codecov-action@v2 ==> linux OS detected https://uploader.codecov.io/latest/linux/codecov.SHA256SUM ==> SHASUM file signed by key id 806bb28aed779869 ==> Uploader SHASUM verified (e6aa8429d6ff91eddc7eced927e6ec936364a88fe755eed28b1f627a6499980d codecov) ==> Running version latest ==> Running version v0.6.3 /home/runner/work/_actions/codecov/codecov-action/v2/dist/codecov -n codecov-umbrella -Q github-action-2.1.0 -Z -f ./build/gcov/*.gcov -F unittests [2023-10-13T23:28:12.760Z] ['info'] _____ _ / ____| | | | | ___ __| | ___ ___ _____ __ | | / _ \ / _` |/ _ \ / __/ _ \ \ / / | |___| (_) | (_| | __/ (_| (_) \ V / \_____\___/ \__,_|\___|\___\___/ \_/ Codecov report uploader 0.6.3 [2023-10-13T23:28:12.768Z] ['info'] => Project root located at: /home/runner/work/basic-cicd/basic-cicd [2023-10-13T23:28:12.769Z] ['info'] -> No token specified or token is empty [2023-10-13T23:28:12.777Z] ['info'] Searching for coverage files... [2023-10-13T23:28:12.831Z] ['error'] None of the following appear to exist as files: ./build/gcov/*.gcov [2023-10-13T23:28:12.831Z] ['error'] There was an error running the uploader: Error while cleaning paths. No paths matched existing files! Error: Codecov: Failed to properly upload: The process '/home/runner/work/_actions/codecov/codecov-action/v2/dist/codecov' failed with exit code 255
本地运行make coverage的结果
以下是本地执行make all ; make coverage的完整记录:
./basic-cicd$ make all ; make coverage mkdir -p build/obj build/bin build/gcov gcc -Isrc -Itest -fprofile-arcs -ftest-coverage -c src/a.c -o build/obj/a.o gcc -Isrc -Itest -fprofile-arcs -ftest-coverage -c src/b.c -o build/obj/b.o gcc -Isrc -Itest -fprofile-arcs -ftest-coverage test/test_a.c build/obj/a.o test/unity.c -o build/bin/test_runner_a -fprofile-arcs -ftest-coverage gcc -Isrc -Itest -fprofile-arcs -ftest-coverage test/test_b.c build/obj/b.o test/unity.c -o build/bin/test_runner_b -fprofile-arcs -ftest-coverage ^[[Abuild/bin/test_runner_a test/test_a.c:38:test_a_init_sets_count_to_zero:PASS test/test_a.c:39:test_a_set_count_sets_count_correctly:PASS test/test_a.c:40:test_a_get_count_gets_count_correctly:PASS ----------------------- 3 Tests 0 Failures 0 Ignored OK build/bin/test_runner_b test/test_b.c:53:test_b_init:PASS test/test_b.c:54:test_b_increment_count:PASS test/test_b.c:55:test_b_get_count:PASS ----------------------- 3 Tests 0 Failures 0 Ignored OK mkdir -p build/obj build/bin build/gcov build/bin/test_runner_a test/test_a.c:38:test_a_init_sets_count_to_zero:PASS test/test_a.c:39:test_a_set_count_sets_count_correctly:PASS test/test_a.c:40:test_a_get_count_gets_count_correctly:PASS ----------------------- 3 Tests 0 Failures 0 Ignored OK build/bin/test_runner_b test/test_b.c:53:test_b_init:PASS test/test_b.c:54:test_b_increment_count:PASS test/test_b.c:55:test_b_get_count:PASS ----------------------- 3 Tests 0 Failures 0 Ignored OK mv build/obj/*.gcno build/gcov || true mv build/obj/*.gcda build/gcov || true gcov -o build/gcov -r build/obj/*.o || true File 'src/a.c' Lines executed:100.00% of 8 Creating 'a.c.gcov' File 'src/b.c' Lines executed:100.00% of 8 Creating 'b.c.gcov' Lines executed:100.00% of 16 mv *.gcov build/gcov || true ./basic-cicd$ ls ./build/gcov/*.gcov ./build/gcov/a.c.gcov ./build/gcov/b.c.gcov
可以看到,a.c.gcov和b.c.gcov都正常生成在./build/gcov/目录下。
(附言:我的Makefile确实需要优化——它会重复运行两次单元测试,一次用于校验结果,一次用于生成覆盖率数据。如果有修复方案,欢迎提交PR,我会及时更新!)
内容的提问来源于stack exchange,提问作者fearless_fool
相关产品推荐
相关产品推荐

