-
Notifications
You must be signed in to change notification settings - Fork 3
124 lines (103 loc) · 4.73 KB
/
shinyapps_deploy.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# 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
name: shiny-deploy
on:
# on push to branches labeled main and dev* or commits tagged as VYY.MM.n deploy
push:
branches:
- main
- dev*
tags:
- v[0-9]+.[0-9]+.[0-9]+
paths-ignore:
- '.github/ISSUE_TEMPLATE/**'
- '**/*.md'
- '**/.gitignore'
jobs:
shiny-deploy:
runs-on: ubuntu-latest
container: rocker/rstudio:4.1.2
env:
SCHEMATIC_URL_DEV: https://schematic-dev.api.sagebionetworks.org
SCHEMATIC_URL_STAGING: https://schematic-staging.api.sagebionetworks.org
SCHEMATIC_URL_PROD: https://schematic.api.sagebionetworks.org
# This should not be necessary for installing from public repo's however remotes::install_github() fails without it.
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: Install System Dependencies
run: |
sudo apt-get update
sudo apt-get install -y pip libcurl4-openssl-dev libpng-dev libfontconfig1-dev libharfbuzz-dev libfribidi-dev libtiff-dev libxml2-dev
# this action checks out the $GITHUB_WORKSPACE repository so that the workflow can access it
- uses: actions/checkout@v3
# this action sets up pandoc
- uses: r-lib/actions/setup-pandoc@v2
- uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true
r-version: 'renv'
# install packages
- name: Install rsconnect
run: |
install.packages("renv")
renv::upgrade(version = "0.17.3")
renv::install("[email protected]")
shell: Rscript {0}
# this action activates renv
- uses: r-lib/actions/setup-renv@v2
- name: Write R environmental variables
shell: bash
run: |
echo 'DFA_CLIENT_ID="${{ secrets.OAUTH_CLIENT_ID }}"' >> .Renviron
echo 'DFA_CLIENT_SECRET="${{ secrets.OAUTH_CLIENT_SECRET }}"' >> .Renviron
echo 'DFA_DCC_CONFIG="https://raw.githubusercontent.com/Sage-Bionetworks/data_flow_config/dev/tenants.json"' >> .Renviron
echo 'GITHUB_PAT="${{ secrets.GITHUB_TOKEN }}"' >> .Renviron
echo 'DFA_REF="${{ github.ref }}"' >> .Renviron
# deploy app using rsconnect
- name: Authorize and deploy app
run: |
renv::restore(packages = "renv")
# set variables
refName <- Sys.getenv("GITHUB_REF_NAME")
repo <- Sys.getenv("GITHUB_REPOSITORY")
appName <- strsplit(repo, "/")[[1]][2]
rsConnectUser <-"${{ secrets.RSCONNECT_USER }}"
rsConnectToken <- "${{ secrets.RSCONNECT_TOKEN }}"
rsConnectSecret <- "${{ secrets.RSCONNECT_SECRET }}"
# read in .Renviron
renviron <- readLines(".Renviron")
# if tag is v*.*.*, deploy to prod
# if main to staging
# otherwise to test
if (grepl("v[0-9]+.[0-9]+.[0-9]+", refName)) {
message("Deploying release version of app using schematic API production instance")
renviron <- c(renviron, "DFA_SCHEMATIC_API_URL = '${{ env.SCHEMATIC_URL_PROD }}'")
} else if (refName == "main") {
appName <- paste(appName, "staging", sep = "-")
renviron <- c(renviron, "DFA_SCHEMATIC_API_URL = '${{ env.SCHEMATIC_URL_STAGING }}'")
message("Deploying staging version of app using schematic API staging instance")
} else {
appName <- paste(appName, "testing", sep = "-")
renviron <- c(renviron, "DFA_SCHEMATIC_API_URL = '${{ env.SCHEMATIC_URL_DEV }}'")
message("Deploying testing version of app using schematic API dev instance")
}
# add oauth configuration to .renviron
appUrl <- sprintf("https://%s.shinyapps.io/%s", rsConnectUser, appName)
renviron <- c(renviron, sprintf("DFA_APP_URL=%s", appUrl))
# write .Renviron
writeLines(renviron, ".Renviron")
# deploy
message(sprintf("Deploying to %s instance.", appName))
# set account info
rsconnect::setAccountInfo(rsConnectUser, rsConnectToken, rsConnectSecret)
# get app names. If app exists, configure then deploy. Otherwise
# deploy then configure.
apps <- rsconnect::applications()$name
if (appName %in% apps) {
rsconnect::configureApp(appName = appName, size = "xxxlarge", logLevel = "verbose")
rsconnect::deployApp(appName = appName)
} else {
rsconnect::deployApp(appName = appName)
rsconnect::configureApp(appName = appName, size = "xxxlarge", logLevel = "verbose")
}
shell: Rscript {0}