R测试GitHub Actions快照

问题描述

我正在使用GitHub Actions进行R CMD检查(请参阅https://github.com/r-lib/actions)。

我想在snapshot_file脚本中使用testthat

save_png <- function(code,width = 1000,height = 600) {
  path <- tempfile(fileext = ".png")
  Grdevices::png(path,width = width,height = height)
  on.exit(dev.off())
  code
  
  path
}

set.seed(123)
df <- data.frame(y=rnorm(20),x=rnorm(20))

test_that("graphs are correct",{
  expect_snapshot_file(path = save_png(plot(df$y,df$x)),name = "plot1.png")
}

此刻,错误将始终是: Adding new file snapshot "_snaps/gets-test1-example/plot1.png"。另外,如果我在笔记本电脑上上传生成的图,我会得到一个错误,即它们不一样(甚至略有不同)...

因为我知道快照测试非常脆弱,所以我想到了两个选择:

  • 删除_snaps文件夹中所有已生成的快照文件,例如在我的笔记本电脑上,然后使用某种形式的上载伪像(https://github.com/actions/upload-artifact)第一次上载快照-然后GitHub操作具有同一台计算机生成内容以对其进行测试(我在想什么)例如每个操作系统的专用存储位置,先将现有文件加载到工作流计算机,然后再检查)
  • 跳过GitHub Actions上的所有snapshot_files(使用skip_on_ci())。

下面是我的工作流程文件,也许您对如何帮助我有所了解:

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

name: R-CMD-check

jobs:
  R-CMD-check:
    runs-on: ${{ matrix.config.os }}

    name: ${{ matrix.config.os }} (${{ matrix.config.r }})

    strategy:
      fail-fast: false
      matrix:
        config:
          - {os: windows-latest,r: 'release'}
          - {os: macOS-latest,r: 'release'}
          - {os: ubuntu-20.04,r: 'release',rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"}
          - {os: ubuntu-20.04,rspm: "https://packagemanager.rstudio.com/cran/__linux__/xenial/latest"}
          - {os: ubuntu-20.04,r: 'devel',rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"}
          - {os: ubuntu-16.04,rspm: "https://packagemanager.rstudio.com/cran/__linux__/xenial/latest"}

    env:
      R_REMOTES_NO_ERRORS_FROM_WARNINGS: true
      RSPM: ${{ matrix.config.rspm }}
    
    defaults:
      run:
        working-directory: gets
    
    steps:
      - uses: actions/checkout@v2

      - uses: r-lib/actions/setup-r@master
        with:
          r-version: ${{ matrix.config.r }}

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

      - name: Query dependencies
        run: |
          install.packages('remotes')
          saveRDS(remotes::dev_package_deps(dependencies = TRUE),"../.github/depends.Rds",version = 2)
          writeLines(sprintf("R-%i.%i",getRversion()$major,getRversion()$minor),"../.github/R-version")
        shell: Rscript {0}

      - name: Cache R packages
        if: runner.os != 'Windows'
        uses: actions/cache@v1
        with:
          path: ${{ env.R_LIBS_USER }}
          key: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-${{ hashFiles('../.github/depends.Rds') }}
          restore-keys: ${{ runner.os }}-${{ hashFiles('../.github/R-version') }}-1-

      - name: Install system dependencies
        if: runner.os == 'Linux'
        run: |
          while read -r cmd
          do
            eval sudo $cmd
          done < <(Rscript -e 'cat(remotes::system_requirements("ubuntu","20.04","gets"),sep = "\n")')
      - name: Install dependencies
        run: |
          remotes::install_deps(dependencies = TRUE)
          remotes::install_cran("rcmdcheck")
        shell: Rscript {0}

      - name: Check
        env:
          _R_CHECK_CRAN_INCOMING_REMOTE_: false
        run: rcmdcheck::rcmdcheck(args = c("--no-manual","--as-cran"),error_on = "warning",check_dir = "check")
        shell: Rscript {0}

      - name: Upload check results
        if: failure()
        uses: actions/upload-artifact@main
        with:
          name: ${{ runner.os }}-r${{ matrix.config.r }}-results
          path: check

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...