如何解决Github操作-R包R-CMD-Check“ PhantomJS not found”
我正在将GitHub操作用于我的R包的CI。我正在尝试在包中同时使用testthat
和shinytest
。我已经根据shinytest
文档正确设置了包结构。当我在RStudio中运行R-CMD-CHECK
时,我的程序包(包括testthat
和shinytest
测试都有效)。
我的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
项目的开发流程,
如果没有详细的日志,也没有关于在remotes
步骤中安装的依赖项(Query dependencies
)的信息,则很难进行调查。似乎根本没有安装PhantomJS依赖项。由于运行者has PhantomJS installed out-of-the-box,工作流在ubuntu-20.04
上成功完成。您可以在提供的运行程序类型here上查看所有已安装的软件。上面的工作流程中使用的其他运行器类型(windows-latest
和macOS-latest
)缺少PhantomJS。这就是为什么您的工作流程在Windows和MacOS上失败而在Ubuntu上成功的原因。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。