How to change GitHub Actions OS from MacOs to Windows or Ubuntu? - r

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).

Related

Error using GitHub actions with R markdown

I'm new to using GitHub actions, so please be gentle with me! I'm trying to automate a script that I'm currently running using Windows Task Scheduler. I've written the yml code below and its stored (privately) on GitHub at jeremy-horne/Client/.github/workflows/
The RMD code is 900 lines long and works when run in R studio. It is stored on GitHub at jeremy-horne/Client
`
name: my_project
on:
schedule:
- cron: "18 17 */1 * *" # Every day at 18:17
jobs:
render-rmarkdown:
runs-on: ubuntu-latest
# optionally use a convenient Ubuntu LTS + DVC + CML image
#container: docker://dvcorg/cml:latest
steps:
- uses: actions/checkout#v3
- name: Setup R
uses: r-lib/actions/setup-r#v2
#- name: Setup Pandoc
# uses: r-lib/actions/setup-pandoc#v2
- name: Setup dependencies
run: |
R -e 'install.packages("renv")'
R -e 'renv::restore()'
- name: Identify and email articles
#env:
# repo_token: ${{ secrets.GITHUB_TOKEN }}
run: |
Rscript -e 'rmarkdown::render(input = "My_Markdown_Code.Rmd")'
if [[ "$(git status --porcelain)" != "" ]]; then
git config --local user.name "$GITHUB_ACTOR"
git config --local user.email "$GITHUB_ACTOR#users.noreply.github.com"
git add *
git commit -m "Auto update Report"
git push origin
fi
`
The error I get says "render-rmarkdown
there is no package called ‘rmarkdown’"
Any help much appreciated!

Deploying firebase cloud functions using github actions

I'm trying to deploy my firebase cloud functions app using github actions:
name: Deploy
'on':
push:
branches:
- main
jobs:
deploy_to_production:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- name: install dependencies
run: cd functions/ && npm install
- name: deploy to production
uses: w9jds/firebase-action#master
with:
args: deploy --only functions
env:
FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }}
The step "deploy to production" is not successful. I activate debug mode and I don't actually receive any useful information:
##[debug]Evaluating: secrets.FIREBASE_TOKEN
##[debug]Evaluating Index:
##[debug]..Evaluating secrets:
##[debug]..=> Object
##[debug]..Evaluating String:
##[debug]..=> 'FIREBASE_TOKEN'
##[debug]=> '***'
##[debug]Result: '***'
##[debug]Evaluating condition for step: 'deploy to production'
##[debug]Evaluating: success()
##[debug]Evaluating success:
##[debug]=> true
##[debug]Result: true
##[debug]Starting: deploy to production
##[debug]Loading inputs
##[debug]Loading env
Run w9jds/firebase-action#master
with:
args: deploy --only functions
env:
FIREBASE_TOKEN: ***
/usr/bin/docker run --name w9jdsfirebaseactionv212_2c5197 --label 08450d --workdir /github/workspace --rm -e FIREBASE_TOKEN -e INPUT_ARGS -e HOME -e GITHUB_JOB -e GITHUB_REF -e GITHUB_SHA -e GITHUB_REPOSITORY -e GITHUB_REPOSITORY_OWNER -e GITHUB_RUN_ID -e GITHUB_RUN_NUMBER -e GITHUB_RETENTION_DAYS -e GITHUB_RUN_ATTEMPT -e GITHUB_ACTOR -e GITHUB_WORKFLOW -e GITHUB_HEAD_REF -e GITHUB_BASE_REF -e GITHUB_EVENT_NAME -e GITHUB_SERVER_URL -e GITHUB_API_URL -e GITHUB_GRAPHQL_URL -e GITHUB_REF_NAME -e GITHUB_REF_PROTECTED -e GITHUB_REF_TYPE -e GITHUB_WORKSPACE -e GITHUB_ACTION -e GITHUB_EVENT_PATH -e GITHUB_ACTION_REPOSITORY -e GITHUB_ACTION_REF -e GITHUB_PATH -e GITHUB_ENV -e GITHUB_STEP_SUMMARY -e RUNNER_DEBUG -e RUNNER_OS -e RUNNER_ARCH -e RUNNER_NAME -e RUNNER_TOOL_CACHE -e RUNNER_TEMP -e RUNNER_WORKSPACE -e ACTIONS_RUNTIME_URL -e ACTIONS_RUNTIME_TOKEN -e ACTIONS_CACHE_URL -e GITHUB_ACTIONS=true -e CI=true -v "/var/run/docker.sock":"/var/run/docker.sock" -v "/home/runner/work/_temp/_github_home":"/github/home" -v "/home/runner/work/_temp/_github_workflow":"/github/workflow" -v "/home/runner/work/_temp/_runner_file_commands":"/github/file_commands" -v "/home/runner/work/personalsite-backend/personalsite-backend":"/github/workspace" w9jds/firebase-action:v2.1.2 deploy --only functions
##[debug]Docker Action run completed with exit code 2
##[debug]Finishing: deploy to production
Am I missing something?
Note: Locally I can deploy without any problem.
By using w9jds/firebase-action, there's a known issue wherein if you use uses: w9jds/firebase-action#master, it tries to store what the CLI spits out and if it errors out and ends the action before it can echo it this might stop it from printing out the response. More information from the repository owner here.
Starting with version v2.1.2, you must replace this line:
uses: w9jds/firebase-action#master
to this:
uses: docker://w9jds/firebase-action:master
More information here.
Moreover, there is also an alternate solution to this by using actions/checkout instead. See yaml configuration below:
name: Deploy to Firebase Functions via github action
"on":
push:
branches:
- main
env:
CI: false
jobs:
build_and_deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- name: Download deps
working-directory: functions
run: npm install
- name: Deploy
run: npx firebase-tools deploy
env:
FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }}
Note: I've used actions/checkout#v2 on the sample yaml above, but v3 is now available.

pkgdown workflow fails to deploy gh pages

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.

Testing an R package against a Julia package on github actions - works on all OS but fails on windows

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

Github Action is not Running on Push, only on schedule

Based on this article, I am trying to generate a repo that runs everytime y push, but also every 4 or 8 hours. as seen by the action history, only one of them was successful, and only on a Mac Machine:
But my goal is to run it on at ubuntu-latest, windows-latest and macos-latest to check the code in all OS. One final goal is to make it so that the message of the scheduled pushs is updated in xxx date. This is my latest code EDITED on sept 23 which can be seen in this repo:
name: render readme
on:
push:
paths:
- README.Rmd
schedule:
- cron: 0 */4 * * *
jobs:
render:
runs-on: macOS-latest
steps:
- uses: actions/checkout#v2
- uses: r-lib/actions/setup-r#v1
- uses: r-lib/actions/setup-pandoc#v1
- name: "[Custom block] [macOS] Install spatial libraries"
if: runner.os == 'macOS'
run: |
# conflicts with gfortran from r-lib/actions when linking gcc
rm '/usr/local/bin/gfortran'
brew install pkg-config gdal proj geos
- name: "[Stage] [macOS] Install libgit2"
if: runner.os == 'macOS'
run: brew install libgit2
- name: Install packages
run: Rscript -e 'install.packages(c("rmarkdown", "pacman", "rgeos"))'
- name: install rgdal
run: Rscript -e 'install.packages("rgdal", configure.args = c("--with-proj-lib=/usr/local/lib/", "--with-proj-include=/usr/local/include/"))'
- name: Render README
run: Rscript -e 'rmarkdown::render("README.Rmd", output_format = "md_document")'
- name: Commit results
run: |
git add README.md man/figures/README-*
git commit README.md -am 'Re-build README.md' || echo "No changes to commit"
git push origin main || echo "No changes to commit"
Now it runs and it actually gives me a tick, but the md is not updated, within the runs in the task called commit results we can see the following error
Run git add README.md man/figures/README-*
git add README.md man/figures/README-*
git commit README.md -am 'Re-build README.md' || echo "No changes to commit"
git push origin main || echo "No changes to commit"
shell: /bin/bash -e {0}
env:
R_LIBS_USER: /Users/runner/work/_temp/Library
TZ: UTC
_R_CHECK_SYSTEM_CLOCK_: FALSE
NOT_CRAN: true
fatal: paths 'README.md ...' with -a does not make sense
No changes to commit
Everything up-to-date
So the commit or push is not working, thank you #krzysztof-madej, you catched one mistake which was the branch name, but I still can make the results update the README, even though it runs smoothly
Your issue seems to be with git, not github actions. The -a arg will stage all files, so adding README.md seems to make the command invalid. Try changing:
git commit README.md -am 'Re-build README.md' || echo "No changes to commit"
to
git commit -am 'Re-build README.md' || echo "No changes to commit"
Objective: To run it on at ubuntu-latest, windows-latest and macos-latest to check the code in all OS:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os:
- ubuntu-latest
- macos-latest
- windows-latest

Resources