Skip to content

Update model source in config #98

Update model source in config

Update model source in config #98

# Pushes to production
# \__#1 deploy w/ SCHEMATIC_PIN --> NF_data_curator (prod)
#
# Pushes to staging
# \__#2 deploy w/ SCHEMATIC_PIN --> NF_data_curator-staging
# Staging deploys are for staging of regular releases of data model
#
# Pushes to edge
# \__#3 deploy w/ schematic `develop` on GH --> NF_data_curator-edge
# Edge deploys for testing schematic development branch or simply the *next* version of schematic
name: custom-shiny-deploy
on:
push:
branches:
- production
- staging
- edge-*
paths-ignore:
- '.github/ISSUE_TEMPLATE/**'
- '**/*.md'
- '**/.gitignore'
env:
# PIN=known stable and tested version of schematic used with prod and staging DCA
SCHEMATIC_PIN: 23.6.3
SCHEMATIC_NEXT: 24.1.1
jobs:
shiny-deploy:
runs-on: ubuntu-latest
# This image seems to be based on rocker/r-ver which in turn is based on debian
container: rocker/rstudio:4.3
env:
# This should not be necessary for installing from public repo's however remotes::install_github() fails without it.
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
steps:
# https://docs.posit.co/connect/admin/r/dependencies/
- name: Install System Dependencies
run: |
sudo apt-get update
sudo apt-get install -y tcl tk tk-dev tk-table default-jdk cmake git libpng-dev libjpeg-dev make imagemagick libmagick++-dev gsfonts libssl-dev libfreetype6-dev libfribidi-dev libharfbuzz-dev libfontconfig1-dev libsodium-dev libglu1-mesa-dev libgl1-mesa-dev zlib1g-dev libcairo2-dev libssh2-1-dev libudunits2-dev unixodbc-dev libxml2-dev libmysqlclient-dev libcurl4-openssl-dev libtiff-dev libicu-dev libgdal-dev gdal-bin libgeos-dev libproj-dev libsqlite3-dev python3 libnode-dev libglpk-dev
- uses: actions/checkout@v4
- name: Authorize and deploy app
shell: Rscript {0}
run: |
install.packages(c("rsconnect", "shiny"))
# if there is a tag, 'refName' will be tag name
repo <- Sys.getenv("GITHUB_REPOSITORY")
appName <- strsplit(repo, "/")[[1]][2]
refName <- Sys.getenv("GITHUB_REF_NAME")
if (refName == "production" || grepl("v[0-9]+.[0-9]+.[0-9]+", refName)) {
message("Deploying production instance: ", appName)
} else if (refName == "staging") {
appName <- paste(appName, "staging", sep = "-")
message("Deploying staging instance: ", appName)
} else {
appName <- paste(appName, "edge", sep = "-")
message("Deploying edge instance: ", appName)
}
rsConnectUser <- "${{ secrets.RSCONNECT_USER }}"
rsConnectToken <- "${{ secrets.RSCONNECT_TOKEN }}"
rsConnectSecret <- "${{ secrets.RSCONNECT_SECRET }}"
# create config file
config <- "CLIENT_ID: ${{ secrets.OAUTH_CLIENT_ID }}"
config <- c(config, "CLIENT_SECRET: ${{ secrets.OAUTH_CLIENT_SECRET }}")
appUrl <- sprintf("https://%s.shinyapps.io/%s", rsConnectUser, appName)
config <- c(config, sprintf("APP_URL: %s", appUrl))
configFileConn <- file("oauth_config.yml")
tryCatch(
writeLines(config, configFileConn),
finally=close(configFileConn)
)
rsconnect::setAccountInfo(rsConnectUser, rsConnectToken, rsConnectSecret)
rsconnect::deployApp(appName = appName, appFiles = c("global.R", "ui.R", "server.R"), forceUpdate = TRUE)