Skip to content

Deploy Apps 🚀

Deploy Apps 🚀 #180

Workflow file for this run

---
name: Deploy Apps 🚀
on:
push:
branches:
- main
- dev
paths:
- RNA-seq/**
- basic-teal/**
- efficacy/**
- exploratory/**
- longitudinal/**
- early-dev/**
- patient-profile/**
- python/**
- safety/**
workflow_dispatch:
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.REPO_GITHUB_TOKEN }}
jobs:
deploy:
permissions:
contents: write
defaults:
run:
shell: bash
name: Publish 🗞
runs-on: ubuntu-latest
container:
image: ghcr.io/insightsengineering/rstudio: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: 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@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: |
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") {
# TODO: After teal.slice is released we have to remove this change.
# This workaround is because update to {bslib} breaks current release of teal.slice
if (package$Package == "teal.slice" && "${{ matrix.channel }}" == "stable") {
renv::record("insightsengineering/teal.slice@103491c67e26a9a85d636bd105a806904a0111ec")
} else {
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'
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 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 📌
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: "[skip deploy] Update renv.lock file for ${{ matrix.directory }} app"
file_pattern: "${{ matrix.directory }}/renv/activate.R ${{ matrix.directory }}/renv.lock"
commit_user_name: github-actions
commit_user_email: >-
41898282+github-actions[bot]@users.noreply.github.com
continue-on-error: true