Github操作-R包R-CMD-Check“ PhantomJS not found”

迪伦·罗素

我正在将GitHub操作用于我的R包的CI。我正在尝试同时使用testthatshinytest在我的包装中。我已经根据shinytest文档正确设置了包结构当我R-CMD-CHECK在RStudio中运行时,我的程序包(包括两者testthatshinytest测试作品)都可以。

我的GitHub Actions.yaml工作流程是:

on:
  push:
    branches:
      - main
      - master
  pull_request:
    branches:
      - main
      - 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, r: 'devel', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"}

    env:
      R_REMOTES_NO_ERRORS_FROM_WARNINGS: true
      RSPM: ${{ matrix.config.rspm }}

    steps:
      - uses: actions/checkout@v2

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

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

      - 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@v2
        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 'writeLines(remotes::system_requirements("ubuntu", "20.04"))')

      - 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

当我提交到存储库时,该检查在Windows和Mac OS上失败,但在Ubuntu上有效。

我在Windows和Mac OS上都遇到的错误是:

> test_check("mypackage")
-- 1. Error: application works (@test-appdir.R#6)  -----------------------------
PhantomJS not found.

我认为这与我的包装或测试无关。我认为我的产品配置有误.yaml如何在工作流程中使用PhantomJS解决此问题?

波尔卡斯

一个简单的解决方案是转到使用PhantomJS并打开Github Actions的项目。我们将去shiny项目,确切地去:https : //github.com/rstudio/shiny/blob/master/.github/workflows/R-CMD-check.yaml

我们可以发现:

      - name: Install system dependencies
        if: runner.os == 'Linux'
        env:
          RHUB_PLATFORM: linux-x86_64-ubuntu-gcc
        run: |
          Rscript -e "remotes::install_github('r-hub/sysreqs')"
          sysreqs=$(Rscript -e "cat(sysreqs::sysreq_commands('DESCRIPTION'))")
          sudo -s eval "$sysreqs"
      - name: Install dependencies
        run: |
          remotes::install_deps(dependencies = TRUE)
          remotes::install_cran("rcmdcheck")
        shell: Rscript {0}

      - name: Find PhantomJS path
        id: phantomjs
        run: |
          echo "::set-output name=path::$(Rscript -e 'cat(shinytest:::phantom_paths()[[1]])')"
      - name: Cache PhantomJS
        uses: actions/cache@v1
        with:
          path: ${{ steps.phantomjs.outputs.path }}
          key: ${{ runner.os }}-phantomjs
          restore-keys: ${{ runner.os }}-phantomjs
      - name: Install PhantomJS
        run: >
          Rscript
          -e "if (!shinytest::dependenciesInstalled()) shinytest::installDependencies()"

我们可以轻松地检查是否有单独的代码块,只是为了确保知道PhantomJS本地化或应该安装它。

您可以将这部分代码粘贴到yaml文件中。但是最好的方法可能是遵循shiny项目的流程

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章