簡體   English   中英

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

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

我正在為我的 R 包的 CI 使用 GitHub 操作。 我正在嘗試在我的包中同時使用testthatshinytest 我根據shinytest文檔正確設置了包結構。 當我在 RStudio 中運行R-CMD-CHECK時,我的包(包括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項目管道,

如果沒有詳細的日志並且沒有關於在Query dependencies步驟中安裝了哪些依賴項( remotes )的信息,就很難調查這個問題。 似乎根本沒有安裝 PhantomJS 依賴項。 工作流在ubuntu-20.04上成功,因為運行程序安裝了開箱即用的 PhantomJS 您可以在此處查看提供的運行器類型上的所有已安裝軟件。 上面工作流中使用的其他運行器類型( windows-latestmacOS-latest )缺少 PhantomJS。 這就是您的工作流程在 Windows 和 MacOS 上失敗但在 Ubuntu 上成功的原因。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM