0

我正在尝试codecov.io使用codecov-bashCodecov 提供的脚本上传覆盖率报告。bash 脚本无法在运行 dockeralpine:edge映像的 Gitlab CI 上运行。

以下是错误:

$ /bin/bash <(curl -s https://codecov.io/bash)
/bin/sh: eval: line 107: syntax error: unexpected "("

这是我.gitlab-ci.yml文件的相关部分:

  after_script:
    - apk -U add git curl bash findutils
    - /bin/bash <(curl -s https://codecov.io/bash)

脚本的第 107 行在show_help()函数内部,就在下面This is non-exclusive, use -s "*.foo" to match specific paths.

show_help() {
cat << EOF

                Codecov Bash $VERSION

          Global report uploading tool for Codecov
       Documentation at https://docs.codecov.io/docs
    Contribute at https://github.com/codecov/codecov-bash


    -h          Display this help and exit
    -f FILE     Target file(s) to upload

                 -f "path/to/file"     only upload this file
                                       skips searching unless provided patterns below

                 -f '!*.bar'           ignore all files at pattern *.bar
                 -f '*.foo'            include all files at pattern *.foo
                 Must use single quotes.
                 This is non-exclusive, use -s "*.foo" to match specific paths.

    -s DIR       Directory to search for coverage reports.
                 Already searches project root and artifact folders.
    -t TOKEN     Set the private repository token
                 (option) set environment variable CODECOV_TOKEN=:uuid

                 -t @/path/to/token_file
                 -t uuid

    -n NAME      Custom defined name of the upload. Visible in Codecov UI

    -e ENV       Specify environment variables to be included with this build
                 Also accepting environment variables: CODECOV_ENV=VAR,VAR2

                 -e VAR,VAR2

    -X feature   Toggle functionalities

                 -X gcov          Disable gcov
                 -X coveragepy    Disable python coverage
                 -X fix           Disable report fixing
                 -X search        Disable searching for reports
                 -X xcode         Disable xcode processing
                 -X network       Disable uploading the file network
                 -X gcovout       Disable gcov output
                 -X html          Enable coverage for HTML files
                 -X recursesubs   Enable recurse submodules in git projects when searching for source files

    -N           The commit SHA of the parent for which you are uploading coverage. If not present,
                 the parent will be determined using the API of your repository provider.
                 When using the repository provider's API, the parent is determined via finding
                 the closest ancestor to the commit.

    -R root dir  Used when not in git/hg project to identify project root directory
    -F flag      Flag the upload to group coverage metrics

                 -F unittests        This upload is only unittests
                 -F integration      This upload is only integration tests
                 -F ui,chrome        This upload is Chrome - UI tests

    -c           Move discovered coverage reports to the trash
    -Z           Exit with 1 if not successful. Default will Exit with 0

    -- xcode --
    -D           Custom Derived Data Path for Coverage.profdata and gcov processing
                 Default '~/Library/Developer/Xcode/DerivedData'
    -J           Specify packages to build coverage. Uploader will only build these packages.
                 This can significantly reduces time to build coverage reports.

                 -J 'MyAppName'      Will match "MyAppName" and "MyAppNameTests"
                 -J '^ExampleApp$'   Will match only "ExampleApp" not "ExampleAppTests"

    -- gcov --
    -g GLOB      Paths to ignore during gcov gathering
    -G GLOB      Paths to include during gcov gathering
    -p dir       Project root directory
                 Also used when preparing gcov
    -k prefix    Prefix filepaths to help resolve path fixing: https://github.com/codecov/support/issues/472
    -x gcovexe   gcov executable to run. Defaults to 'gcov'
    -a gcovargs  extra arguments to pass to gcov

    -- Override CI Environment Variables --
       These variables are automatically detected by popular CI providers

    -B branch    Specify the branch name
    -C sha       Specify the commit sha
    -P pr        Specify the pull request number
    -b build     Specify the build number
    -T tag       Specify the git tag

    -- Enterprise --
    -u URL       Set the target url for Enterprise customers
                 Not required when retrieving the bash uploader from your CCE
                 (option) Set environment variable CODECOV_URL=https://my-hosted-codecov.com
    -r SLUG      owner/repo slug used instead of the private repo token in Enterprise
                 (option) set environment variable CODECOV_SLUG=:owner/:repo
                 (option) set in your codecov.yml "codecov.slug"
    -S PATH      File path to your cacert.pem file used to verify ssl with Codecov Enterprise (optional)
                 (option) Set environment variable: CODECOV_CA_BUNDLE="/path/to/ca.pem"
    -U curlargs  Extra curl arguments to communicate with Codecov. e.g., -U "--proxy http://http-proxy"
    -A curlargs  Extra curl arguments to communicate with AWS.

    -- Debugging --
    -d           Don't upload, but dump upload file to stdout
    -q PATH      Write upload file to path
    -K           Remove color from the output
    -v           Verbose mode

EOF
}

我已经尝试了很多方法来解决这个问题,但我找不到解决方案。在他们的 GitHub 存储库中,有一个似乎相关的问题,但建议的解决方案对我不起作用:在busybox 1.26 上失败,不正确的标志传递给find.

你可以在这里找到完整的工作日志,第 434 行:https ://gitlab.com/gaspacchio/back-to-the-future/-/jobs/788303704

4

1 回答 1

0

根据KamilCuk的评论,以下是将代码覆盖率报告正确上传到 codecov 所需的完整行:

bash -c '/bin/bash <(curl -s https://codecov.io/bash)'

正如 KamilCuk 所指出的,注意关闭'

-c标志在手册页中记录如下bash

-c 字符串

如果存在 -c 选项,则从字符串中读取命令。如果字符串后面有参数,则将它们分配给位置参数,从 $0 开始。

到今天为止,我不知道为什么会这样。如果您有任何线索,请随时编辑此答案。

于 2020-10-13T14:42:44.147 回答