Skip to content

Commit

Permalink
Fix the app deployments (#41)
Browse files Browse the repository at this point in the history
### Changes made

1. Removes `renv` from all the nine apps
2. Adds front-end tests for these seven apps (all except `early-dev` and
`python`):
`RNA-seq`, `basic-teal`, `efficacy`, `exploratory`, `longitudinal`,
`patient-profile`, `safety`
3. Updates the `deploy.yaml` workflow:
    1. Runs the cypress tests when they are present in the app directory
2. Deploy two versions of apps to RSConnect. `NEST_<APPNAME>_main` and
`NEST_<APPNAME>_release`. The `_main` suffix apps install the teal
packages from https://insightsengineering.r-universe.dev while the
`_release` suffix apps install the teal packages from
https://pharmaverse.r-universe.dev
4. Updates to the `_internal/utils/sourceme.R` to install the packages
from r-universe instead of `renv.lock`.
5. Changes to the appropriate readme files.

---------
  • Loading branch information
vedhav authored Oct 11, 2023
1 parent 6e3e424 commit dd77baf
Show file tree
Hide file tree
Showing 95 changed files with 36,956 additions and 5,815 deletions.
172 changes: 134 additions & 38 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,18 @@ name: Deploy Apps 🚀

on:
push:
branches:
- main
tags:
- "*"
workflow_dispatch:
#schedule:
# - cron: '12 3 * * *'
schedule:
- cron: "12 3 * * *"

concurrency:
group: publish-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

env:
SHINYAPPSIO_ACCOUNT: genentech
APP_PREFIX: NEST
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}

jobs:
deploy:
Expand All @@ -29,45 +27,143 @@ jobs:
image: ghcr.io/insightsengineering/rstudio_4.3.1_bioc_3.17:latest
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: Checkout repo 🛎
uses: actions/checkout@v3

- name: Set channel related constants
run: |
if [ "${{ matrix.channel }}" = "stable" ]; then
echo "BRANCH_NAME=main" >> $GITHUB_ENV # TODO: Change the branch name to main
else
echo "BRANCH_NAME=dev" >> $GITHUB_ENV # TODO: Change the branch name to deval
fi
- name: Check if cypress test exists
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: Setup system dependencies for cypress and python app
run: >
apt-get update && apt-get install --yes
libgtk2.0-0 libgbm-dev libnotify-dev libgconf-2-4 xvfb python3.10-venv
- name: Setup Node
uses: actions/setup-node@v3
if: steps.find-cypress.outputs.has-cypress-tests == 'true'
with:
path: ${{ github.event.repository.name }}
node-version: 16

- name: Overwrite the global Rprofile ✍️
- name: Restore renv from cache
uses: actions/cache@v3
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: |
cat > /usr/local/lib/R/etc/Rprofile.site <<RPROFILE
options(
repos = c(
Pharmaverse = "https://pharmaverse.r-universe.dev",
CRAN = "https://cloud.r-project.org",
BioC = BiocManager::repositories()
),
download.file.method = 'libcurl',
HTTPUserAgent = sprintf(
"R/%s R (%s)",
getRversion(),
paste(getRversion(), R.version["platform"], R.version["arch"], R.version["os"])
)
)
RPROFILE
setwd("${{ matrix.directory }}")
lockfile <- renv::lockfile_read()
pkg_name_structure <- ifelse("${{ matrix.channel }}" == "stable", "%s/%s@*release", "%s/%s")
for (package in lockfile$Packages) {
if (package$Source == "GitHub") {
renv::record(sprintf(pkg_name_structure, package$RemoteUsername, package$Package))
}
}
- name: Deploy apps 🖨 ${{ github.event.repository.name }} 🎨
- name: Install R packages using renv and update the renv snapshot
shell: Rscript {0}
working-directory: ${{ matrix.directory }}
run: |
Sys.setenv(GITHUB_PAT="${{ secrets.GITHUB_TOKEN }}")
devtools::install_local(
".",
upgrade = "never",
dependencies = TRUE
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'
continue-on-error: 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 deploy 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"
)
teal.gallery::deploy_all_apps(
api_key = "${{ secrets.SHINYAPPSIO_TOKEN }}",
api_secret = "${{ secrets.SHINYAPPSIO_SECRET }}",
title_prefix = "NEST",
title_suffix = "${{ github.ref_name }}",
server = "https://${{ env.SHINYAPPSIO_ACCOUNT }}.shinyapps.io",
create_manifest = TRUE
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
)
working-directory: ${{ github.event.repository.name }}
shell: Rscript {0}
- name: Commit updated renv.lock file
run: |
git config --global user.email "[email protected]"
git config --global user.name "GitHub Action"
git config --global --add safe.directory /__w/teal.gallery/teal.gallery
git fetch
git stash
git checkout ${{ env.BRANCH_NAME }}
git stash apply
git pull
if [ -n "$(git diff --staged)" ]; then
git add ${{ matrix.directory }}/renv.lock
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
43 changes: 28 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,34 @@ A gallery of sample apps based on the [`teal`](https://github.com/insightsengine

### Development version

- [basic-teal](https://genentech.shinyapps.io/NEST_basic-teal_main/)
- [exploratory](https://genentech.shinyapps.io/NEST_exploratory_main/)
- [safety](https://genentech.shinyapps.io/NEST_safety_main/)
- [efficacy](https://genentech.shinyapps.io/NEST_efficacy_main/)
- [patient-profile](https://genentech.shinyapps.io/NEST_patient-profile_main/)
- [early-dev](https://genentech.shinyapps.io/NEST_early-dev_main/)
- [longitudinal](https://genentech.shinyapps.io/NEST_longitudinal_main/)
- [RNA-seq](https://genentech.shinyapps.io/NEST_RNA-seq_main/)
- [python](https://genentech.shinyapps.io/NEST_python_main/)
- [basic-teal](https://genentech.shinyapps.io/NEST_basic-teal_stable/)
- [exploratory](https://genentech.shinyapps.io/NEST_exploratory_stable/)
- [safety](https://genentech.shinyapps.io/NEST_safety_stable/)
- [efficacy](https://genentech.shinyapps.io/NEST_efficacy_stable/)
- [patient-profile](https://genentech.shinyapps.io/NEST_patient-profile_stable/)
- [early-dev](https://genentech.shinyapps.io/NEST_early-dev_stable/)
- [longitudinal](https://genentech.shinyapps.io/NEST_longitudinal_stable/)
- [RNA-seq](https://genentech.shinyapps.io/NEST_RNA-seq_stable/)
- [python](https://genentech.shinyapps.io/NEST_python_stable/)

## Running the apps

You can run any of these apps by just executing these two lines of code in your R console.

By sourcing the [sourceme.R](https://github.com/insightsengineering/teal.gallery/blob/main/utils/sourceme.R) file you make sure that you have access to the `restore_and_run()`

Note: Make sure to install [renv](https://rstudio.github.io/renv/index.html) before you do this. Also, it is recommended that you create and use a Github PAT. Once you have the PAT, run the following:

```R
Sys.setenv(GITHUB_PAT = "your_access_token_here")
```

Running the `restore_and_run("APP_NAME")` will run the `APP_NAME` by restoring the packages using [renv](https://rstudio.github.io/renv/)

```R
source("https://raw.github.com/insightsengineering/teal.gallery/main/_internal/utils/sourceme.R")
# Assuming you want to run the "basic-teal" app. Refer to the list above to know which apps are possible

# Run the basic-teal app
restore_and_run("basic-teal")
```

Expand All @@ -47,8 +54,14 @@ All `teal` sample apps are wrapped into this package for the sake of portability

Adding a sample app involves the following steps:

1. Copy each sample app into a file named `app.R` into a sensible folder name inside it's own directory. The directory is also the `APP_NAME`.
2. Make sure that `{renv}` is used for the teal app.
3. Create a GIF recording ([KAP](https://getkap.co/) is a good tool for this). Make sure that the dimensions of the GIF is 970x555 px and the size is about 1 MB. (It can be done by recording using KAP in 1470x840 px and rendering 5fps and downsizing 33%). Place the GIF inside the `_internal/quarto/assets/img` directory. Also, make sure that the name of the GIF is `APP_NAME.gif`. Also, make sure to place a static image with the name dimention called `APP_NAME.png` that will be displayed in the demo page when the card is not hovered.
4. Update the `_internal/quarto/demo-apps.yml` with a new `app/title`. This should be the `APP_NAME`.
5. Run the `_internal/utils/generate_app_readme.R` to generate the readme for the app inside it's own directory.
#### Hard requirements

1. Copy each sample app into a file named `app.R` into a sensible folder name inside it's own directory. The directory has to be named with the `APP_NAME`.
2. Update the `_internal/quarto/demo-apps.yml` with a new `app/title`. This should be the `APP_NAME`.
3. Run the `_internal/utils/generate_app_readme.R` to generate the readme for the app inside it's own directory.

#### Optional/Soft requirements

1. You can snapshot the teal app dependencies using `{renv}` but make sure to snapshot using GitHub references to the teal packages.
2. Create a GIF recording ([KAP](https://getkap.co/) is a good tool for this). Make sure that the dimensions of the GIF is 970x555 px and the size is about 1 MB. (It can be done by recording using KAP in 1470x840 px and rendering 5fps and downsizing 33%). Place the GIF inside the `_internal/quarto/assets/img` directory. Also, make sure that the name of the GIF is `APP_NAME.gif`. Also, make sure to place a static image with the name dimention called `APP_NAME.png` that will be displayed in the demo page when the card is not hovered.
3. Add front-end tests with the help of cypress. Copy the contents of the `js` directory within some other app's directory inside your app directory to get the node dependencies. Place the cypress tests inside the `tests/cypress` inside your app's directory. Please refer to an existing app's tests so that the `.github/deploy.yaml` will automaticall run the cypress tests.
6 changes: 4 additions & 2 deletions RNA-seq/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
### Run the app yourself

source("https://raw.github.com/insightsengineering/teal.gallery/main/_internal/utils/sourceme.R")
restore_and_run("RNA-seq")

# Run the app
restore_and_run("RNA-seq", package_repo = "https://insightsengineering.r-universe.dev")

### View the deployed app

Deployed app: <https://genentech.shinyapps.io/NEST_RNA-seq_main>
Deployed app: <https://genentech.shinyapps.io/NEST_RNA-seq_stable>

### Preview the app

Expand Down
Loading

0 comments on commit dd77baf

Please sign in to comment.