【问题标题】:Github Actions how to set to fail when there's annotations?Github Actions 有注释时如何设置失败?
【发布时间】:2021-02-07 22:16:26
【问题描述】:

我已经使用 GitHub Actions 设置了 lintr 包:

on:
  push:
    branches:
      - master
  pull_request:
    branches:
      - master

name: lint

jobs:
  lint:
    runs-on: macOS-latest
    env:
      GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
    steps:
      - uses: actions/checkout@v2

      - uses: r-lib/actions/setup-r@master

      - uses: actions/cache@v1
        with:
          path: ~/Library/Application Support/renv
          key: ${{ runner.os }}-renv-${{ hashFiles('**/renv.lock') }}
          restore-keys: |
            ${{ runner.os }}-renv-

      - name: Install lintr
        run: install.packages("lintr")
        shell: Rscript {0}

      - name: Lint
        run: lintr::lint_dir(linters = lintr::with_defaults(assignment_linter = NULL, line_length_linter = NULL, spaces_left_parentheses_linter = NULL), pattern = '[.]R$|[.]Rmd')
        shell: Rscript {0}

格式错误显示为注释:

但是,这些注释不会通过 PR 检查,这实际上是您在 lint 代码时想要的。

我想在警告上设置一个exit 1。这是正确的做法吗?

【问题讨论】:

  • 我不熟悉 lintr,但这里的问题可能是它将问题视为警告而不是错误。 C# 开发人员面临类似的情况,StyleCop linter 使用一些警告并且不会使构建失败,除非更改配置。也许 lintr 可以类似地配置为将所有警告视为错误并返回错误代码。
  • 我试试看!
  • @AlbersonMiranda,你有没有成功在这里抛出错误?我尝试复制顶部评论的答案,但我仍然得到注释,而不是错误。 error_on_lint 似乎没有改变我的操作

标签: r github-actions


【解决方案1】:

在运行 lint_dir 的代码之前,您可以添加 options(error_on_lint=TRUE)

run: "options(error_on_lint=TRUE); lintr::lint_dir(linters = lintr ..."

将 lintr 设置放入运行 lintr 的目录中的 .lintr 文件中可能会很有用:

.lintr

linters: with_defaults(
    assignment_linter = NULL, line_length_linter = NULL, spaces_left_parentheses_linter = NULL
  )
error_on_lint: TRUE

那么您的 GHA 中的 lint_dir 代码将如下所示:

run: lintr::lint_dir(pattern=....)

【讨论】:

    猜你喜欢
    • 2020-01-14
    • 2020-09-25
    • 1970-01-01
    • 2020-01-01
    • 2020-12-19
    • 1970-01-01
    • 2020-09-29
    • 2020-07-19
    • 2021-08-11
    相关资源
    最近更新 更多