forked from Sage-Bionetworks/data_curator
-
Notifications
You must be signed in to change notification settings - Fork 1
134 lines (122 loc) · 5.18 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
# 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:
push:
branches:
- main
- develop*
- include-setup
tags:
- v[0-9]+.[0-9]+.[0-9]+
paths-ignore:
- '.github/ISSUE_TEMPLATE/**'
- '**/*.md'
- '**/.gitignore'
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.1.2
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:
- name: Install System Dependencies
run: |
sudo apt-get update
sudo apt-get install -y pip python3.8-venv libcurl4-openssl-dev
- uses: actions/checkout@v2
- uses: r-lib/actions/setup-pandoc@v1
- name: Create and Activate Python Virtual Environment
shell: bash
run: |
python3 -m venv .venv
chmod 755 .venv/bin/activate
source .venv/bin/activate
- name: Install R Packages Dependencies
run: |
R -f install-pkgs.R
- name: Install Schematic
shell: bash
run: |
# has to activate each bash step
source .venv/bin/activate
# use 'poetry' to install schematic dev schematic
# If commit is tagged for release or in main branch, install schematic from pypi
if [[ $GITHUB_REF_NAME == v*.*.* ]] || [[ $GITHUB_REF_NAME == main ]]; then
echo Installing pypi version of schematic
git clone --single-branch --branch main https://github.com/Sage-Bionetworks/schematic.git
cp schematic_config.yml schematic/config.yml
cd schematic
pip3 install schematicpy
else
pip3 install poetry
echo Installing develop branch of schematic from github
git clone --single-branch --branch develop https://github.com/Sage-Bionetworks/schematic.git
cp schematic_config.yml schematic/config.yml
cd schematic
poetry build
pip3 install dist/schematicpy-1.0.0-py3-none-any.whl
fi
- name: Set Configurations for Schematic
shell: bash
run: |
# write out configuration files using github secrets
echo "${{ secrets.SCHEMATIC_SYNAPSE_CONFIG }}" > .synapseConfig
echo "${{ secrets.SCHEMATIC_CREDS_PATH }}" > credentials.json
echo "${{ secrets.SCHEMATIC_TOKEN_PICKLE }}" | base64 -d > token.pickle
- name: Save service account credentials for Schematic
id: create-json
uses: jsdaniell/[email protected]
with:
name: 'schematic_service_account_creds.json'
json: ${{ secrets.SCHEMATIC_SERVICE_ACCT_CREDS }}
- 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'
- 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
- name: Authorize and deploy app
shell: Rscript {0}
run: |
# if there is a tag, 'refName' will be tag name
repo <- Sys.getenv("GITHUB_REPOSITORY")
appName <- "include-dcc-data-curator"
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 == "main") {
appName <- paste(appName, "staging", sep = "-")
message("Deploying staging version of app")
} else {
appName <- paste(appName, "testing", 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 }}"
# 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)