Coveralls GitHub Action – 错误: 找不到 Lcov 文件

huangapple go评论113阅读模式
英文:

Coveralls GitHub Action - Error: Lcov file not found

问题

我正在使用 GitHub Action 配置 Coveralls。

我搜索了,但是我找不到应该如何生成 ./coverage/lcov.info 文件的方法。
当操作运行时,由于我没有这个文件,我会得到:

使用 lcov 文件:./coverage/lcov.info
错误:找不到 Lcov 文件。

我尝试使用 IntelliJ 进行覆盖测试,但是我能够生成的唯一导出格式是 HTML 格式。

我如何生成 lcov.info 文件?

编辑 - 根据评论添加我的工作流程以供参考

# 对于大多数项目,此工作流文件不需要更改;您只需将其提交到您的存储库。
#
# 您可能希望修改此文件以覆盖要分析的语言集,
# 或提供自定义查询或构建逻辑。

name: "CodeQL"

on:
  push:
    branches: [master]
  pull_request:
    # 下面的分支必须是上面的分支的子集
    branches: [master]
  schedule:
    - cron: '0 14 * * 4'

jobs:
  analyze:
    name: Analyze
    runs-on: ubuntu-latest

    strategy:
      fail-fast: false
      matrix:
        # 通过更改以下列表来覆盖自动语言检测
        # 支持的选项有 ['csharp', 'cpp', 'go', 'java', 'javascript', 'python']
        language: ['java']
        # 了解更多...
        # https://docs.github.com/en/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#overriding-automatic-language-detection
        java: [11]

    steps:
    - name: Checkout repository
      uses: actions/checkout@v2
      with:
        # 我们必须至少获取直接父级,以便如果这是一个拉取请求,我们可以检出头部。
        fetch-depth: 2

    # 如果此运行是由拉取请求事件触发的,则检出
    # 拉取请求的头部,而不是合并提交。
    - run: git checkout HEAD^2
      if: ${{ github.event_name == 'pull_request' }}

    - name: Set up Java JDK
      uses: actions/setup-java@v1
      with:
        java-version: ${{ matrix.java }}

    # 初始化用于扫描的 CodeQL 工具。
    - name: Initialize CodeQL
      uses: github/codeql-action/init@v1
      with:
        languages: ${{ matrix.language }}
        # 如果您想指定自定义查询,可以在此处或配置文件中执行。
        # 默认情况下,此处列出的查询将覆盖在配置文件中指定的任何查询。
        # queries: ./path/to/local/query, your-org/your-repo/queries@main

    # Autobuild 尝试构建任何编译语言(C/C++、C# 或 Java)。
    # 如果此步骤失败,则应删除它并手动运行构建(见下文)
    - name: Autobuild
      uses: github/codeql-action/autobuild@v1

    # ℹ️ 使用操作系统 shell 运行的命令行程序。
    # 📚 https://git.io/JvXDl

    # ✏️ 如果上面的 Autobuild 失败,请删除它,并取消下面三行的注释
    #    并修改它们(或添加更多)以构建您的代码,如果您的项目
    #    使用编译语言

    #- run: |
    #   make bootstrap
    #   make release

    - name: 执行 CodeQL 分析
      uses: github/codeql-action/analyze@v1
英文:

I am configuring Coveralls using a GitHub Action.

I searched but I cannot find how I should be able to generate the ./coverage/lcov.info file.
When the action runs, since I don't have such file, I get:

Using lcov file: ./coverage/lcov.info  
Error: Lcov file not found.

I tried running test with Coverage via IntelliJ but the only export I can produce is in HTML format.

How can I generate the lcov.info file?

Edit - Adding my workflow for reference, as requested in comments

# For most projects, this workflow file will not need changing; you simply need
# to commit it to your repository.
#
# You may wish to alter this file to override the set of languages analyzed,
# or to provide custom queries or build logic.
name: "CodeQL"
on:
push:
branches: [master]
pull_request:
# The branches below must be a subset of the branches above
branches: [master]
schedule:
- cron: '0 14 * * 4'
jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
# Override automatic language detection by changing the below list
# Supported options are ['csharp', 'cpp', 'go', 'java', 'javascript', 'python']
language: ['java']
# Learn more...
# https://docs.github.com/en/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#overriding-automatic-language-detection
java: [11]
steps:
- name: Checkout repository
uses: actions/checkout@v2
with:
# We must fetch at least the immediate parents so that if this is
# a pull request then we can checkout the head.
fetch-depth: 2
# If this run was triggered by a pull request event, then checkout
# the head of the pull request instead of the merge commit.
- run: git checkout HEAD^2
if: ${{ github.event_name == 'pull_request' }}
- name: Set up Java JDK
uses: actions/setup-java@v1
with:
java-version: ${{ matrix.java }}
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file. 
# Prefix the list here with "+" to use these queries and those in the config file.
# queries: ./path/to/local/query, your-org/your-repo/queries@main
# Autobuild attempts to build any compiled languages  (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v1
# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
#    and modify them (or add more) to build your code if your project
#    uses a compiled language
#- run: |
#   make bootstrap
#   make release
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1

答案1

得分: 1

在GitHub Actions上,我遇到了相同的错误(请参阅此构建日志),但我有一个略微不同的GitHub Action workflow.yml(在Java / Maven设置中可能更加“默认”):

name: build

on: [push]

jobs:
  coverage:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v2
      - uses: actions/setup-java@v1
        with:
          java-version: 15
      - run: mvn -B test -P coverage --no-transfer-progress

      - uses: coverallsapp/github-action@master
        with:
          github-token: ${{ secrets.GITHUB_TOKEN }}

并且在我的pom.xml中有以下配置,用于jacoco-maven-plugincoveralls-maven-plugin

<profiles>
    <profile>
        <id>coverage</id>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.jacoco</groupId>
                    <artifactId>jacoco-maven-plugin</artifactId>
                    <version>${build-plugin.jacoco.version}</version>
                    <executions>
                        <!-- Prepares the property pointing to the JaCoCo
                        runtime agent which is passed as VM argument when Maven the Surefire plugin
                        is executed. -->
                        <execution>
                            <id>pre-unit-test</id>
                            <goals>
                                <goal>prepare-agent</goal>
                            </goals>
                        </execution>
                        <!-- Ensures that the code coverage report for
                        unit tests is created after unit tests have been run. -->
                        <execution>
                            <id>post-unit-test</id>
                            <phase>test</phase>
                            <goals>
                                <goal>report</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                    <groupId>org.eluder.coveralls</groupId>
                    <artifactId>coveralls-maven-plugin</artifactId>
                    <version>${build-plugin.coveralls.version}</version>
                </plugin>
            </plugins>
        </build>
    </profile>
</profiles>

经过一些调查,我发现了这个问题,其中提到 基本上目前coverallsapp/github-action不支持使用JaCoCo进行Coveralls操作。

因此,我别无选择,只能切换到https://codecov.io 并使用匹配的https://github.com/codecov/codecov-action(就像cucumber-jvm团队也这样做了)。我们可以从pom.xml中删除coveralls-maven-plugin。我的workflow.yml现在如下所示:

name: build

on: [push]

jobs:
  coverage:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v2
      - uses: actions/setup-java@v1
        with:
          java-version: 15
      - run: mvn -B test -P coverage --no-transfer-progress

      - uses: codecov/codecov-action@v1
        with:
          file: ./**/target/site/jacoco/jacoco.xml
          name: codecov

这里还有一个完整的示例项目:https://github.com/codecentric/cxf-spring-boot-starter/blob/master/.github/workflows/build.yml,在这个项目中我已经成功使用了codegov。

英文:

I had the same error on GitHub Actions (see this build log), but I had a slightly different GitHub Action workflow.yml (which is maybe a bit more "default" in a Java / Maven setup):

name: build
on: [push]
jobs:
coverage:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-java@v1
with:
java-version: 15
- run: mvn -B test -P coverage --no-transfer-progress
- uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}

And given the following configuration inside my pom.xml for the jacoco-maven-plugin and coveralls-maven-plugin:

&lt;profiles&gt;
&lt;profile&gt;
&lt;id&gt;coverage&lt;/id&gt;
&lt;build&gt;
&lt;plugins&gt;
&lt;plugin&gt;
&lt;groupId&gt;org.jacoco&lt;/groupId&gt;
&lt;artifactId&gt;jacoco-maven-plugin&lt;/artifactId&gt;
&lt;version&gt;${build-plugin.jacoco.version}&lt;/version&gt;
&lt;executions&gt;
&lt;!-- Prepares the property pointing to the JaCoCo
runtime agent which is passed as VM argument when Maven the Surefire plugin
is executed. --&gt;
&lt;execution&gt;
&lt;id&gt;pre-unit-test&lt;/id&gt;
&lt;goals&gt;
&lt;goal&gt;prepare-agent&lt;/goal&gt;
&lt;/goals&gt;
&lt;/execution&gt;
&lt;!-- Ensures that the code coverage report for
unit tests is created after unit tests have been run. --&gt;
&lt;execution&gt;
&lt;id&gt;post-unit-test&lt;/id&gt;
&lt;phase&gt;test&lt;/phase&gt;
&lt;goals&gt;
&lt;goal&gt;report&lt;/goal&gt;
&lt;/goals&gt;
&lt;/execution&gt;
&lt;/executions&gt;
&lt;/plugin&gt;
&lt;plugin&gt;
&lt;groupId&gt;org.eluder.coveralls&lt;/groupId&gt;
&lt;artifactId&gt;coveralls-maven-plugin&lt;/artifactId&gt;
&lt;version&gt;${build-plugin.coveralls.version}&lt;/version&gt;
&lt;/plugin&gt;
&lt;/plugins&gt;
&lt;/build&gt;
&lt;/profile&gt;
&lt;/profiles&gt;

After some digging into the topic I found this issue of the coverallsapp/github-action which says basically that there's no support for JaCoCo with the Coveralls Action right now.

Therefore I saw no other option than to switch to https://codecov.io and the matching https://github.com/codecov/codecov-action (like the cucumber-jvm Team also did). We can remove the coveralls-maven-plugin from our pom.xml. My workflow.yml now looks like this:

name: build
on: [push]
jobs:
coverage:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-java@v1
with:
java-version: 15
- run: mvn -B test -P coverage --no-transfer-progress
- uses: codecov/codecov-action@v1
with:
file: ./**/target/site/jacoco/jacoco.xml
name: codecov

Here's also the a fully comprehensible example project: https://github.com/codecentric/cxf-spring-boot-starter/blob/master/.github/workflows/build.yml where I use codegov successfully now.

答案2

得分: 0

相同的配置今天可以正常工作,我猜在 GitHub 的一侧做了一些更改。

英文:

The same identical configuration works today, I guess some changes were done on the GitHub side.

huangapple
  • 本文由 发表于 2020年10月5日 21:29:47
  • 转载请务必保留本文链接:https://go.coder-hub.com/64209601.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定