-
-
Notifications
You must be signed in to change notification settings - Fork 7
224 lines (207 loc) · 7.45 KB
/
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
---
name: Deploy Apps 🚀
on:
push:
branches:
- main
- dev
- deploy
paths:
- RNA-seq/**
- basic-teal/**
- efficacy/**
- exploratory/**
- longitudinal/**
- early-dev/**
- patient-profile/**
- python/**
- safety/**
workflow_dispatch:
schedule:
- cron: "12 3 * * *"
env:
SHINYAPPSIO_ACCOUNT: genentech
APP_PREFIX: NEST
GITHUB_PAT: ${{ secrets.REPO_GITHUB_TOKEN }}
jobs:
deploy:
permissions:
contents: write
defaults:
run:
shell: bash
name: Publish 🗞
runs-on: ubuntu-latest
container:
image: ghcr.io/insightsengineering/rstudio:2024.03.05
if: >
!contains(github.event.commits[0].message, '[skip deploy]')
strategy:
fail-fast: false
matrix:
directory:
- RNA-seq
- basic-teal
- efficacy
- exploratory
- longitudinal
- early-dev
- patient-profile
- python
- safety
channel:
- stable
- dev
steps:
- name: Set channel related constants
run: |
echo "BRANCH_NAME=dev" >> $GITHUB_ENV
if [ "${{ matrix.channel }}" == "stable" ]; then
echo "BRANCH_NAME=main" >> $GITHUB_ENV
fi
- name: Setup job token 🔑
id: github-token
run: |
if [ "${{ secrets.REPO_GITHUB_TOKEN }}" == "" ]; then
echo "REPO_GITHUB_TOKEN is empty. Substituting it with GITHUB_TOKEN."
echo "token=${{ secrets.GITHUB_TOKEN }}" >> $GITHUB_OUTPUT
else
echo "Using REPO_GITHUB_TOKEN."
echo "token=${{ secrets.REPO_GITHUB_TOKEN }}" >> $GITHUB_OUTPUT
fi
shell: bash
- name: Checkout repo 🛎
uses: actions/checkout@v4
with:
ref: "${{ env.BRANCH_NAME }}"
token: "${{ steps.github-token.outputs.token }}"
- name: Add safe directory in git config
run: |
git config --global --add safe.directory $(pwd)
- name: Check if Cypress tests exist
id: find-cypress
run: |
if [ -d ${{ matrix.directory }}/tests/cypress ]; then
echo "has-cypress-tests=true" >> $GITHUB_OUTPUT
else
echo "Skipping frontend tests because cypress directory does not exist."
echo "has-cypress-tests=false" >> $GITHUB_OUTPUT
fi
- name: Install additional system dependencies
run: |
apt-get update
apt-get install --yes \
libgtk2.0-0 \
libgbm-dev \
libnotify-dev \
libgconf-2-4 \
xvfb
if [ " ${{ matrix.directory }}" == "python" ]
then {
apt-get install --yes python3.10-venv
}
fi
- name: Setup Node
uses: actions/setup-node@v4
if: steps.find-cypress.outputs.has-cypress-tests == 'true'
with:
node-version: 20
- name: Restore renv from cache
uses: actions/cache@v4
env:
CACHE_KEY: renv-${{ runner.arch }}-${{ runner.os }}-${{ matrix.directory }}-${{ matrix.channel }}
with:
path: ${{ matrix.directory }}/renv/library
key: ${{ env.CACHE_KEY }}-${{ hashFiles(format('{0}/renv.lock', matrix.directory)) }}
restore-keys: ${{ env.CACHE_KEY }}-
- name: Update renv.lock file with updated GitHub packages
shell: Rscript {0}
run: |
setwd("${{ matrix.directory }}")
lockfile <- renv::lockfile_read()
pkg_name_structure <- ifelse("${{ matrix.channel }}" == "stable", "%s/%s@*release", "%s/%s")
unreleased_packages <- c(
"osprey", "hermes", "goshawk", "teal.modules.general",
"teal.osprey", "teal.modules.hermes", "teal.goshawk", "nestcolor"
)
for (package in lockfile$Packages) {
if (package$Source == "GitHub") {
print(package$Package)
if (package$Package %in% unreleased_packages) {
print(paste0("Recording ", package$Package, " from main"))
renv::record(sprintf("%s/%s", package$RemoteUsername, package$Package))
} else {
print(paste0("Recording ", package$Package, " from stable"))
renv::record(sprintf(pkg_name_structure, package$RemoteUsername, package$Package))
}
}
}
- name: Install R packages using renv and update the renv snapshot
shell: Rscript {0}
working-directory: ${{ matrix.directory }}
run: |
options(renv.config.cache.symlinks = FALSE)
lockfile_pkgs <- renv::lockfile_read()$Package
github_pkgs <- names(lockfile_pkgs)[sapply(lockfile_pkgs, function(x) x$Source == "GitHub")]
renv::restore(clean = TRUE)
renv::update(exclude = github_pkgs)
renv::snapshot()
- name: Print the new renv.lock file for ${{ matrix.directory }}
working-directory: ${{ matrix.directory }}
run: cat renv.lock
- name: Front end test to check if the app works fine
if: steps.find-cypress.outputs.has-cypress-tests == 'true'
uses: cypress-io/github-action@v6
with:
build: npm install cypress --save-dev
working-directory: ${{ matrix.directory }}/tests
start: npm run run-app
wait-on: "http://localhost:3333"
wait-on-timeout: 500
- name: Install deployment-related R package dependencies
shell: Rscript {0}
working-directory: ${{ matrix.directory }}
run: |
install.packages(c("BiocManager", "rsconnect"))
- name: Deploy 🖨 ${{ matrix.directory }} 🎨
shell: Rscript {0}
working-directory: ${{ matrix.directory }}
run: |
rsconnect::setAccountInfo(
name = "${{ env.SHINYAPPSIO_ACCOUNT }}",
token = "${{ secrets.SHINYAPPSIO_TOKEN }}",
secret = "${{ secrets.SHINYAPPSIO_SECRET }}",
server = "shinyapps.io"
)
rsconnect::deployApp(
appFiles = c("app.R"),
appName = rsconnect::generateAppName("${{ env.APP_PREFIX }}_${{ matrix.directory }}_${{ matrix.channel }}"),
appTitle = "${{ env.APP_PREFIX }}_${{ matrix.directory }}_${{ matrix.channel }}",
account = "${{ env.SHINYAPPSIO_ACCOUNT }}",
upload = TRUE,
logLevel = "normal",
lint = FALSE,
forceUpdate = TRUE
)
- name: Commit and push changes 📌
run: |
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config --global user.name "github-actions"
git config --global --add safe.directory /__w/teal.gallery/teal.gallery
git fetch
git stash
git checkout ${{ env.BRANCH_NAME }}
git pull
if [ -n "$(git stash list)" ]; then
git stash apply
else
echo "No stash entries found."
fi
git add ${{ matrix.directory }}/renv.lock
git add ${{ matrix.directory }}/renv/activate.R
if [ -n "$(git diff --staged)" ]; then
git commit -m "[skip deploy] Update renv.lock file for ${{ matrix.directory }} app"
git push origin ${{ env.BRANCH_NAME }}
else
echo "renv.lock was not modified. Nothing to commit."
fi