Skip to content

Deploy Apps 🚀

Deploy Apps 🚀 #261

Workflow file for this run

---
name: Deploy Apps 🚀
on:
push:
branches:
- main
- dev
tags:
- "*"
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
jobs:
deploy:
defaults:
run:
shell: bash
name: Publish 🗞
runs-on: ubuntu-latest
container:
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: ["basic-teal"]
repository: ["https://insightsengineering.r-universe.dev"]
steps:
- name: Set CHANNEL
run: |
if [ "${{ matrix.repository }}" = "https://insightsengineering.r-universe.dev" ]; then
echo "CHANNEL=stable" >> $GITHUB_ENV
else
echo "CHANNEL=release" >> $GITHUB_ENV
fi
- name: Checkout repo 🛎
uses: actions/checkout@v3
with:
path: ${{ github.event.repository.name }}
- name: Install jq
run: sudo apt-get update && sudo apt-get install -y jq
- name: Extract R version from lockfile
run: printf 'R_VERSION=%s\n' "$(jq --raw-output .R.Version ${{ github.event.repository.name }}/${{ matrix.directory }}/renv.lock)" >> $GITHUB_ENV
- name: Check if cypress test exists
id: find-cypress
run: |
if [ -d ${{ github.event.repository.name }}/${{ 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
if: steps.find-cypress.outputs.has-cypress-tests == 'true'
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:
node-version: 16
- name: Setup npm packages
if: steps.find-cypress.outputs.has-cypress-tests == 'true'
shell: bash
working-directory: ${{ github.event.repository.name }}/${{ matrix.directory }}/js
run: |
npm i
- name: Restore renv from cache
uses: actions/cache@v2
env:
CACHE_KEY: renv-cache-${{ runner.arch }}-${{ runner.os }}-${{ env.R_VERSION }}-${{ matrix.directory }}-${{ env.CHANNEL }}
with:
path: ${{ github.event.repository.name }}/${{ matrix.directory }}/renv/library
key: ${{ env.CACHE_KEY }}-${{ hashFiles(format('{0}/{1}/renv.lock', github.event.repository.name, matrix.directory)) }}
restore-keys: ${{ env.CACHE_KEY }}-
- name: Update renv lock file with repo channel
shell: Rscript{0}
working-directory: ${{ github.event.repository.name }}
run: |
setwd("${{ matrix.directory }}")
repos <- renv::lockfile_read()$R$Repositories
repos$Pharmaverse <- "${{ matrix.repository }}"
renv::lockfile_modify(repos = repos) |> renv::lockfile_write()
- name: Install R packages using renv and update the renv snapshot
shell: Rscript {0}
working-directory: ${{ github.event.repository.name }}/${{ matrix.directory }}
run: |
options(renv.config.cache.symlinks = FALSE)
lockfile_packages <- renv::lockfile_read()$Packages |> names()
renv::update(lockfile_packages)
renv::snapshot(packages = lockfile_packages, update = TRUE)
- name: Print the new renv.lock file for ${{ matrix.directory }}
working-directory: ${{ github.event.repository.name }}/${{ 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@v2
with:
working-directory: ${{ github.event.repository.name }}/${{ matrix.directory }}/js
start: npm run run-app
wait-on: "http://localhost:3333"
wait-on-timeout: 500
project: ../tests
- name: Install deploy R package dependencies
shell: Rscript {0}
working-directory: ${{ github.event.repository.name }}/${{ matrix.directory }}
run: |
install.packages(c("BiocManager", "remotes"))
remotes::install_version("rsconnect", "0.8.29")
- name: Deploy 🖨 ${{ matrix.directory }} 🎨
shell: Rscript {0}
continue-on-error: true
working-directory: ${{ github.event.repository.name }}/${{ matrix.directory }}
run: |
options(
repos = c(
Pharmaverse = "${{ matrix.repository }}",
CRAN = "https://cloud.r-project.org",
BioC = BiocManager::repositories()
)
)
rsconnect::setAccountInfo(
name = "${{ env.SHINYAPPSIO_ACCOUNT }}",
token = "${{ secrets.SHINYAPPSIO_TOKEN }}",
secret = "${{ secrets.SHINYAPPSIO_SECRET }}",
server = "shinyapps.io"
)
rsconnect::deployApp(
appFiles = "app.R",
appName = rsconnect::generateAppName("${{ env.APP_PREFIX }}_${{ matrix.directory }}_${{ env.CHANNEL }}"),
appTitle = "${{ env.APP_PREFIX }}_${{ matrix.directory }}_${{ env.CHANNEL }}",
account = "${{ env.SHINYAPPSIO_ACCOUNT }}",
upload = TRUE,
logLevel = "normal",
lint = FALSE,
forceUpdate = TRUE
)
- name: Commit updated renv.lock file
if: ${{ env.CHANNEL == 'stable' }} #TODO: Will change this to release before merging
uses: stefanzweifel/git-auto-commit-action@v4
with:
repository: ${{ github.event.repository.name }}
branch: deploy-apps@main # TODO: switch to the release branch before merging.
commit_message: "[skip deploy] Update renv.lock file for ${{ matrix.directory }} app"
file_pattern: "${{ matrix.directory }}/renv.lock"
commit_user_name: insights-engineering-bot