Skip to content

Deploy Apps 🚀

Deploy Apps 🚀 #253

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: ["RNA-seq", "basic-teal"]
repository:
[
"https://insightsengineering.r-universe.dev",
"https://pharmaverse.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: Overwrite the global Rprofile ✍️
run: |
cat > /usr/local/lib/R/etc/Rprofile.site <<RPROFILE
options(
repos = c(
Pharmaverse = "${{ matrix.repository }}",
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
- 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: Remove renv
shell: Rscript {0}
run: |
setwd("${{ github.event.repository.name }}/${{ matrix.directory }}")
remotes::install_version("renv", "1.0.0")
renv::deactivate()
unlink(c("renv", "renv.lock", ".Rprofile"), force = TRUE, recursive = TRUE)
- name: Install packages without renv
shell: Rscript {0}
working-directory: ${{ github.event.repository.name }}/${{ matrix.directory }}
run: |
install.packages(renv::dependencies()$Package)
renv::snapshot()
- 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'
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: Deploy 🖨 ${{ matrix.directory }} 🎨
shell: Rscript {0}
working-directory: ${{ github.event.repository.name }}/${{ matrix.directory }}
run: |
install.packages('remotes')
remotes::install_version("rsconnect", "0.8.29")
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
continue-on-error: true
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