Skip to content

Commit

Permalink
Major refresh of CI-CD workflow and deployment setup
Browse files Browse the repository at this point in the history
  • Loading branch information
riccardoporreca committed Jan 24, 2024
1 parent 53b2d17 commit 7949c0c
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 45 deletions.
9 changes: 6 additions & 3 deletions .Rbuildignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
^rTRhexNG\.Rproj$
^.*\.Rproj$
^\.Rproj\.user$
^app\.R$
^\.travis\.yml$
^\.github$
^app\.R$
^R/_disable_autoload\.R$
^deploy$
^rsconnect$
^\.rscignore$
68 changes: 26 additions & 42 deletions .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
@@ -1,59 +1,43 @@
on: [push, pull_request]

name: CI-CD

on:
# Triggered on push and pull request events
push:
pull_request:
# Allow manual runs
workflow_dispatch:
# Monthly runs on the 1st day of the month at midnight
schedule:
- cron: '0 0 1 * *'

jobs:
CI-CD:
runs-on: ubuntu-latest
steps:

- uses: actions/checkout@v2
env:
# Access token for GitHub
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
# Preserve package sources for informative references in case of errors
R_KEEP_PKG_SOURCE: yes

steps:

- uses: r-lib/actions/setup-r@master
- uses: actions/checkout@v3

- name: Query dependencies
run: |
install.packages("remotes")
saveRDS(remotes::dev_package_deps(dependencies = TRUE), "depends.Rds", version = 2)
shell: Rscript {0}
- uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true

- name: Cache R packages
uses: actions/cache@v1
- uses: r-lib/actions/setup-r-dependencies@v2
with:
path: ${{ env.R_LIBS_USER }}
key: ${{ runner.os }}-r-${{ hashFiles('depends.Rds') }}
restore-keys: ${{ runner.os }}-r-
extra-packages: any::rcmdcheck, any::rsconnect

- name: Install system dependencies
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"
# rsconnect dependencies
sudo apt-get update && sudo apt-get install -y --no-install-recommends \
libxml2-dev libcurl4-openssl-dev
- name: Install dependencies
run: |
remotes::install_deps(dependencies = TRUE)
remotes::install_cran(c("rcmdcheck", "rsconnect"))
shell: Rscript {0}

- name: Check
run: rcmdcheck::rcmdcheck(args = "--no-manual", error_on = "warning", check_dir = "check")
shell: Rscript {0}
- uses: r-lib/actions/check-r-package@v2

- name: Deploy to shinyapps.io
if: github.ref == 'refs/heads/master'
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master'
env:
SHINYAPPS_ACCOUNT: ${{ secrets.SHINYAPPS_ACCOUNT }}
SHINYAPPS_TOKEN: ${{ secrets.SHINYAPPS_TOKEN }}
SHINYAPPS_SECRET: ${{ secrets.SHINYAPPS_SECRET }}
run: |
account_info <- lapply(paste0("SHINYAPPS_", c("ACCOUNT", "TOKEN", "SECRET")), Sys.getenv)
do.call(rsconnect::setAccountInfo, account_info)
rsconnect::deployApp(appName = "rTRhexNG")
shell: Rscript {0}

run: Rscript deploy/deploy-shinyapps.R
3 changes: 3 additions & 0 deletions R/_disable_autoload.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Disabling shiny autoload

# See ?shiny::loadSupport for more information
14 changes: 14 additions & 0 deletions deploy/deploy-shinyapps.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# deploy/deploy-shinyapps.R
# usethis::use_build_ignore("deploy")
if (!interactive()) {
rsconnect::setAccountInfo(
Sys.getenv("SHINYAPPS_ACCOUNT"),
Sys.getenv("SHINYAPPS_TOKEN"),
Sys.getenv("SHINYAPPS_SECRET")
)
}
# Add here any additional files/directories the app needs
app_files = c("app.R", "DESCRIPTION", "NAMESPACE", "R/", "inst/")
rsconnect::deployApp(
appName = "rTRhexNG", appFiles = app_files, forceUpdate = TRUE
)

0 comments on commit 7949c0c

Please sign in to comment.