Github 操作 - R 包 R-CMD-检查 "PhantomJS not found"
Github Actions - R package R-CMD-Check "PhantomJS not found"
我正在对我的 R 包的 CI 使用 GitHub 操作。我正在尝试在我的包中同时使用 testthat
和 shinytest
。我根据 shinytest
文档正确设置了包结构。当我在 RStudio 中 运行 R-CMD-CHECK
时,我的包(包括 testthat
和 shinytest
测试有效)。
我的 GitHub 操作 .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 的这个问题?
如果没有详细的日志并且没有关于在 Query dependencies
步骤中安装了哪些依赖项 (remotes
) 的信息,很难调查该问题。似乎根本没有安装 PhantomJS 依赖项。工作流在 ubuntu-20.04
上成功,因为运行器 has PhantomJS installed out-of-the-box. 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
) 缺少 PhantomJS。这就是为什么您的工作流程在 Windows 和 MacOS 上失败但在 Ubuntu.
上成功的原因
简单的解决方案是转到使用 PhantomJS 并打开 Github 操作的项目。我们将转到 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
项目的流程,
我正在对我的 R 包的 CI 使用 GitHub 操作。我正在尝试在我的包中同时使用 testthat
和 shinytest
。我根据 shinytest
文档正确设置了包结构。当我在 RStudio 中 运行 R-CMD-CHECK
时,我的包(包括 testthat
和 shinytest
测试有效)。
我的 GitHub 操作 .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 的这个问题?
如果没有详细的日志并且没有关于在 Query dependencies
步骤中安装了哪些依赖项 (remotes
) 的信息,很难调查该问题。似乎根本没有安装 PhantomJS 依赖项。工作流在 ubuntu-20.04
上成功,因为运行器 has PhantomJS installed out-of-the-box. 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
) 缺少 PhantomJS。这就是为什么您的工作流程在 Windows 和 MacOS 上失败但在 Ubuntu.
简单的解决方案是转到使用 PhantomJS 并打开 Github 操作的项目。我们将转到 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
项目的流程,