-
Notifications
You must be signed in to change notification settings - Fork 20
162 lines (137 loc) · 5.96 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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
name: shiny-deploy
on:
pull_request:
branches:
- main
jobs:
shiny-deploy:
runs-on: ubuntu-latest
container: rocker/rstudio:4.1.2
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
DCA_SCHEMATIC_API_TYPE: rest
DCA_API_HOST: "https://schematic-dev.api.sagebionetworks.org"
steps:
- name: Install System Dependencies
run: |
sudo apt-get update
sudo apt-get install -y libcurl4-openssl-dev libpng-dev libxml2-dev
- uses: actions/checkout@v3
- uses: r-lib/actions/setup-pandoc@v2
- if: ${{env.DCA_SCHEMATIC_API_TYPE == 'reticulate' }}
name: Install python
run: |
sudo apt-get install -y pip python3.8-venv
- if: ${{env.DCA_SCHEMATIC_API_TYPE == 'reticulate' }}
name: Set up virtual environment
# When shinyapps.io supports python 3.9+ split this into two steps
# to install schematic from pypi or github
shell: bash
run: |
python3 -m venv .venv
chmod 755 .venv/bin/activate
source .venv/bin/activate
- if: ${{env.DCA_SCHEMATIC_API_TYPE == 'reticulate' }}
name: Install schematicpy
shell: bash
run: |
source .venv/bin/activate
pip install schematicpy==23.1.1
# https://github.com/actions/setup-python/blob/main/docs/advanced-usage.md#caching-packages
# For the future, look at poetry install
# - uses: actions/checkout@v3
# - name: Install poetry
# run: pipx install poetry
# - uses: actions/setup-python@v4
# with:
# python-version: '3.9'
# cache: 'poetry'
# - run: poetry install
# - run: poetry run pytest
#
- name: Set Configurations for Schematic
# write out configuration files using github secrets
if: ${{env.DCA_SCHEMATIC_API_TYPE == 'reticulate' }}
shell: bash
run: |
echo "${{ secrets.SCHEMATIC_SYNAPSE_CONFIG }}" > .synapseConfig
- name: Save service account credentials for Schematic
if: ${{env.DCA_SCHEMATIC_API_TYPE == 'reticulate' }}
id: create-json
uses: jsdaniell/[email protected]
with:
name: 'schematic_service_account_creds.json'
json: ${{ secrets.SCHEMATIC_SERVICE_ACCT_CREDS }}
- if: ${{env.DCA_SCHEMATIC_API_TYPE == 'reticulate' }}
name: Set Configurations for Data Model
shell: bash
run: |
source .venv/bin/activate
# download the data models and create config.json
python3 .github/config_schema.py \
-c schematic_config.yml \
--service_repo 'Sage-Bionetworks/schematic' \
--overwrite
- if: ${{env.DCA_SCHEMATIC_API_TYPE == 'reticulate' }}
name: zip virtual env
shell: bash
# ShinyApps has a limit of 7000 files, far exceeded by the many Python dependencies
# that this app' has. As a workaround we zip the virtual environment and later
# unzip it in 'global.R'
run: |
zip -rm .venv.zip .venv
- uses: r-lib/actions/setup-renv@v2
- name: shinyapps.io R pkg hack
# Delete files that makes shinyapps.io treat this like a golem app
shell: bash
run: |
cp R/* functions/
rm -r R/ DESCRIPTION NAMESPACE
- name: Write R environmental variables
shell: bash
run: |
echo 'DCA_CLIENT_ID="${{ secrets.OAUTH_CLIENT_ID }}"' >> .Renviron
echo 'DCA_CLIENT_SECRET="${{ secrets.OAUTH_CLIENT_SECRET }}"' >> .Renviron
echo 'DCA_SCHEMATIC_API_TYPE="${{ env.DCA_SCHEMATIC_API_TYPE }}"' >> .Renviron
echo 'DCA_API_HOST="${{ env.DCA_API_HOST }}"' >> .Renviron
echo 'DCA_SYNAPSE_PROJECT_API=TRUE' >> .Renviron
echo 'DCA_DCC_CONFIG="https://raw.githubusercontent.com/Sage-Bionetworks/data_curator_config/shinyapps-io/dcc_config.csv"' >> .Renviron
echo 'GITHUB_PAT="${{ secrets.GITHUB_TOKEN }}"' >> .Renviron
- name: Authorize and deploy app
shell: Rscript {0}
run: |
renv::restore()
install.packages("rsconnect")
repo <- Sys.getenv("GITHUB_REPOSITORY")
appName <- strsplit(repo, "/")[[1]][2]
refName <- Sys.getenv("GITHUB_REF_NAME")
# 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")
} else if (refName %in% c("main")) {
appName <- paste(appName, "staging", sep = "-")
message("Deploying staging version of app")
} else {
appName <- paste(appName, "testing1", sep = "-")
message("Deploying testing version of app")
}
message(sprintf("Deploying to %s instance.", appName))
rsConnectUser <- "${{ secrets.RSCONNECT_USER }}"
rsConnectToken <- "${{ secrets.RSCONNECT_TOKEN }}"
rsConnectSecret <- "${{ secrets.RSCONNECT_SECRET }}"
rsconnect::setAccountInfo(rsConnectUser, rsConnectToken, rsConnectSecret)
# Set app URL for OAuth
appUrl <- sprintf("https://%s.shinyapps.io/%s", rsConnectUser, appName)
renviron <- readLines(".Renviron")
renviron <- c(renviron, sprintf("DCA_APP_URL=%s", appUrl))
writeLines(renviron, ".Renviron")
# 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")
}