I am using GitHub actions for CI of my R package. I am trying using both testthat and shinytest in my package. I have the package structure set up correctly according to the shinytest documentation. When I run R-CMD-CHECK in RStudio, my package (including both testthat and shinytest testing works).
My GitHub Actions .yaml workflow is:
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.
The error that I am I am getting on both Windows and Mac OS is:
> 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. How can I resolve this issue with PhantomJS in my workflow?
The easy solution will be to go to the project where there is used PhantomJS and the Github Actions is turned on. We will go to shiny project and precisely to:
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.
You could paste this part of code to your yaml file. However the best way might to be follow the pipeline of shiny project,
It's hard to investigate the issue without detailed logs and no information about what dependencies (remotes) are being installed in Query dependencies step. It seems the PhantomJS dependency is not being installed at all. The workflow succeeds on ubuntu-20.04 because the runner 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) are missing PhantomJS. That's why your workflow fails on Windows and MacOS but succeeds on Ubuntu.
Related
I'm currently using the macOs os version for my Github Actions but it's very consuming on my minutes thresholds as it has a 10x cost on the monthly limit
I would like to switch to Ubuntu or Windows but I'm not quite sure about how to change my YML file.
Here is my actual YML file of one of my workflow:
# Hourly scraping
name: amazonR Polite Price Checker
# Controls when the action will run.
on:
schedule:
- cron: '0 0 * * 1,4'
jobs:
autoscrape:
# The type of runner that the job will run on
runs-on: macos-latest
# Load repo and install R
steps:
- uses: actions/checkout#master
- uses: r-lib/actions/setup-r#master
# Set-up R
- name: Install packages
run: |
R -e 'install.packages("tidyverse")'
R -e 'install.packages("tibble")'
R -e 'install.packages("openxlsx")'
R -e 'install.packages("gdata")'
R -e 'install.packages("lubridate")'
R -e 'install.packages("rvest")'
R -e 'install.packages("stringr")'
R -e 'install.packages("dplyr")'
R -e 'install.packages("purrr")'
R -e 'install.packages("plyr")'
R -e 'install.packages("polite")'
R -e 'install.packages("xml2")'
R -e 'install.packages("gt")'
R -e 'install.packages("blastula")'
# Run R script
- name: Scrape with the polite package
env:
EMAIL_SENDER: ${{ secrets.EMAIL_SENDER }}
EMAIL_PASSWORD: ${{ secrets.EMAIL_PASSWORD }}
EMAIL_RECIPIENT: ${{ secrets.EMAIL_RECIPIENT }}
EMAIL_CC_1: ${{ secrets.EMAIL_CC_1 }}
EMAIL_CC_2: ${{ secrets.EMAIL_CC_2 }}
EMAIL_CC_3: ${{ secrets.EMAIL_CC_3 }}
run: Rscript polite_price_checker.R
# Add new files in data folder, commit along with other modified files, push
- name: Commit files
run: |
git config --local user.name github-actions
git config --local user.email "actions#github.com"
git add polite_price/*
git commit -am "GH ACTION Autorun POLITE PRICE $(date)"
git push origin main --force
env:
REPO_KEY: ${{secrets.GITHUB_TOKEN}}
username: github-actions
The runner is configured by the runs-on for each job.
It can be a GitHub hosted runner or a self-hosted runner according to your context.
Examples with GitHub hosted runner:
jobs:
job1:
runs-on: ubuntu-latest
steps:
[ ... ]
job2:
runs-on: macos-latest
steps:
[ ... ]
job3:
runs-on: windows-latest
steps:
[ ... ]
The available GitHub runner images (with the pre-installed tools) can be found here for more details.
Be aware that each runner use a specific shell by default, for example ubuntu and macos use bash, where windows use powershell.
Therefore, in your case, you just need to update the runs-on: macos-latest to runs-on: ubuntu-latest or runs-on: windows-latest (supposing you want to use the latest, and not a specific version).
Note that you can also use matrix to run the same job on different runners if necessary (without duplicating code).
https://github.com/KillerJoke623/Practic
I've got a problem with my University practic, can you help me please
name: Jupyter
on:
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout#v3
- name: Setup Python
uses: actions/setup-python#v4.0.0
with:
cache: pip
python-version: '3.7'
- name: Install Dependencies
run: pip install -r requirements.txt
- name: Exeute Notebook
run: jupyter-nbconvert --to html practic.ipynb
- name: Upload a Build Artifact
uses: actions/upload-artifact#v3.1.0
with:
name: Artifact
path: practic.html
I setup for my R package repository a pkgdown workflow.
The .github/workflows/pkgdown.yaml file:
on:
push:
branches: [main, master]
release:
types: [published]
workflow_dispatch:
name: pkgdown
jobs:
pkgdown:
runs-on: ubuntu-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout#v2
- uses: r-lib/actions/setup-pandoc#v1
- uses: r-lib/actions/setup-r#v1
with:
use-public-rspm: true
- uses: r-lib/actions/setup-r-dependencies#v1
with:
extra-packages: pkgdown
needs: website
- name: Deploy package
if: contains(env.isPush, 'true')
run: |
git config --local user.email "actions#github.com"
git config --local user.name "GitHub Actions"
Rscript -e 'pkgdown::deploy_to_branch(new_process = FALSE)'
The pkgdown workflow works fine, but it fails to update the GitHub pages.
I setup the gh-pages branch as explained in the GitHub documentation, so the workflow pages-build-deployment is present, but when I push on main branch it doesn't run.
I realized the problem was in the if: contains(env.isPush, 'true') line. The condition is never true nor false, since there is no attribute isPush under env, hence the lines
run: |
git config --local user.email "actions#github.com"
git config --local user.name "GitHub Actions"
Rscript -e 'pkgdown::deploy_to_branch(new_process = FALSE)'
were never executed.
To solve the problem, either modify the env part:
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
isPush: ${{ github.event_name == 'push' }}
or remove the if condition before the run command.
This is a cross-post from the rstudio forum.
I have been working towards continuous integration testing of an algorithm wrapped in an R package against a Julia implementation, which I have also packaged in an R package via JuliaConnectoR.
I create a standard cmd-check workflow via usethis::use_github_actions(), but additionally install Julia, the required Julia package (WildBootTests.jl) and link R and Julia (the 'JULIA_BINDIR' part).
The code below successfully deploys the cmd check on github actions for Max and Ubuntu but fails for windows. The part that fails is run: julia -e 'using Pkg; Pkg.add("WildBootTests")', which installs the WildBootTests.jl package via the shell.
Does anyone have an idea why the installation of WildBootTests.jl fails on windows, but not on Mac and Ubuntu?
You can find more information on the workflow here: https://github.com/s3alfisc/fwildclusterboot/actions/runs/1583895387
Thanks for your help!
# Workflow derived from https://github.com/r-lib/actions/tree/master/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
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: macOS-latest, r: 'release'}
- {os: windows-latest, r: 'release'}
- {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'}
- {os: ubuntu-latest, r: 'release'}
- {os: ubuntu-latest, r: 'oldrel-1'}
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
R_KEEP_PKG_SOURCE: yes
steps:
- uses: actions/checkout#v2
- uses: r-lib/actions/setup-pandoc#v1
- uses: r-lib/actions/setup-r#v1
with:
r-version: ${{ matrix.config.r }}
http-user-agent: ${{ matrix.config.http-user-agent }}
use-public-rspm: true
- uses: r-lib/actions/setup-r-dependencies#v1
with:
extra-packages: rcmdcheck
# custom code starts here
# install julia
- uses: julia-actions/setup-julia#v1
# add julia to renviron
- name: Create and populate .Renviron file
run: echo JULIA_BINDIR= "${{ env.juliaLocation }}" >> ~/.Renviron
# install WildBootTests.jl
- name: install WildBootTests.jl
run: julia -e 'using Pkg; Pkg.add("WildBootTests")'
# custom code ends here
- uses: r-lib/actions/check-r-package#v1
- name: Show testthat output
if: always()
run: find check -name 'testthat.Rout*' -exec cat '{}' \; || true
shell: bash
- name: Upload check results
if: failure()
uses: actions/upload-artifact#main
with:
name: ${{ runner.os }}-r${{ matrix.config.r }}-results
path: check
Update: If I include the line shell: bash under the run: julia -e statements, package installation does not fail on windows.
Hence, the added part needs to look like this:
# custom code starts here
# install julia
- uses: julia-actions/setup-julia#v1
# add julia to renviron
- name: Create and populate .Renviron file
run: echo JULIA_BINDIR= "${{ env.juliaLocation }}" >> ~/.Renviron
shell: bash
# install WildBootTests.jl
- name: install WildBootTests.jl
run: julia -e 'using Pkg; Pkg.add("WildBootTests")'
shell: bash
# custom code ends here
I want to adapt the boilerplate code in the r-lib/actions repo to add a linting check to my (fake) package. I have my workflow yaml as follows:
on:
push:
branches:
- main
- master
pull_request:
branches:
- main
- master
name: lint
jobs:
lint:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./mystarwars
steps:
- uses: actions/checkout#v2
- uses: r-lib/actions/setup-r#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: Restore R package cache
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 dependencies
run: |
install.packages(c("remotes"))
remotes::install_deps(dependencies = TRUE)
install.packages(c("lintr"))
shell: Rscript {0}
- name: Install package
run: R CMD INSTALL .
- name: Lint
run: lintr::lint_package()
shell: Rscript {0}
However, I get errors when trying to install lintr in the "Install dependencies". This step fails (silently), so then when it reaches the "Lint" step it fails with Error: Error in loadNamespace(x) : there is no package called ‘lintr’.
This remains the case whether I use install.packages(c("lintr")) or remotes::install_cran("lintr").
HERE is the full log of the "Install dependencies" step on GitHub Actions.