简体   繁体   English

Github Actions - R 包 R-CMD-Check "PhantomJS not found"

[英]Github Actions - R package R-CMD-Check "PhantomJS not found"

I am using GitHub actions for CI of my R package.我正在为我的 R 包的 CI 使用 GitHub 操作。 I am trying using both testthat and shinytest in my package.我正在尝试在我的包中同时使用testthatshinytest I have the package structure set up correctly according to the shinytest documentation.我根据shinytest文档正确设置了包结构。 When I run R-CMD-CHECK in RStudio, my package (including both testthat and shinytest testing works).当我在 RStudio 中运行R-CMD-CHECK时,我的包(包括testthatshinytest测试都有效)。

My GitHub Actions .yaml workflow is:我的 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

When I commit to the repository, the check fails on Windows and Mac OS but works on Ubuntu.当我提交到存储库时,检查在 Windows 和 Mac OS 上失败,但在 Ubuntu 上有效。

The error that I am I am getting on both Windows and Mac OS is:我在 Windows 和 Mac OS 上遇到的错误是:

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

I don't think this is a problem with my package or tests.我不认为这是我的包或测试的问题。 I think there is something misconfigured about my .yaml .我认为我的.yaml配置错误。 How can I resolve this issue with PhantomJS in my workflow?如何在我的工作流程中使用 PhantomJS 解决此问题?

The easy solution will be to go to the project where there is used PhantomJS and the Github Actions is turned on.简单的解决方案是转到使用 PhantomJS 并打开 Github Actions 的项目。 We will go to shiny project and precisely to: https://github.com/rstudio/shiny/blob/master/.github/workflows/R-CMD-check.yaml我们将转到shiny项目,并精确到: https : //github.com/rstudio/shiny/blob/master/.github/workflows/R-CMD-check.yaml

We could find out there that:我们可以在那里发现:

      - 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()"

We easily could check that there is separate chunk of code only to be sure that PhantomJS localization is known or if it should be installed.我们可以很容易地检查是否有单独的代码块,以确保 PhantomJS 本地化是已知的或者是否应该安装。

You could paste this part of code to your yaml file.您可以将这部分代码粘贴到您的 yaml 文件中。 However the best way might to be follow the pipeline of shiny project,然而最好的方法可能是跟随shiny项目管道,

It's hard to investigate the issue without detailed logs and no information about what dependencies ( remotes ) are being installed in Query dependencies step.如果没有详细的日志并且没有关于在Query dependencies步骤中安装了哪些依赖项( remotes )的信息,就很难调查这个问题。 It seems the PhantomJS dependency is not being installed at all.似乎根本没有安装 PhantomJS 依赖项。 The workflow succeeds on ubuntu-20.04 because the runner has PhantomJS installed out-of-the-box .工作流在ubuntu-20.04上成功,因为运行程序安装了开箱即用的 PhantomJS You can see all the installed software on provided runner types here .您可以在此处查看提供的运行器类型上的所有已安装软件。 The other runner types used in the workflow above ( windows-latest and macOS-latest ) are missing PhantomJS.上面工作流中使用的其他运行器类型( windows-latestmacOS-latest )缺少 PhantomJS。 That's why your workflow fails on Windows and MacOS but succeeds on Ubuntu.这就是您的工作流程在 Windows 和 MacOS 上失败但在 Ubuntu 上成功的原因。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM