Deploy to shinyapps.io #17
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Deploy to shinyapps.io | |
on: | |
# run on any tagged push | |
release: | |
types: [published] | |
# run on request (via button in actions menu) | |
workflow_dispatch: | |
inputs: | |
deploy_type: | |
description: Deploy to release or test | |
required: true | |
options: | |
- 'test' | |
- 'release' | |
default: 'test' | |
jobs: | |
deploy: | |
name: Deploy to shinyapps | |
# allow skipping deployment for commits containing '[automated]' or '[no-deploy]' in the commit message | |
if: "!contains(github.event.head_commit.message, '[automated]') && !contains(github.event.head_commit.message, '[no-deploy]')" | |
runs-on: ubuntu-22.04 | |
steps: | |
- name: Set deployment type | |
run: | | |
# Check if not triggered from worflow-dispatch (event input variable is empty) | |
if [ -z "${{github.event.inputs.deploy_type}}" ]; then | |
# Set deployment type to release as was not triggered by workflow_dispatch | |
DEPLOY_TYPE="release" | |
else | |
# Set deployment type to workflow_dispatch event input variable | |
DEPLOY_TYPE=${{github.event.inputs.deploy_type}} | |
fi | |
# Store the appName in environment variables based on deployment type | |
if [[ $DEPLOY_TYPE = "test" ]]; then | |
echo "appName=MetaInsight_test" >> $GITHUB_ENV | |
else | |
echo "appName=MetaInsight" >> $GITHUB_ENV | |
fi | |
- name: Print deployment type | |
run: | | |
echo "Deploying to: $appName" | |
- name: Install package system dependencies | |
run: | | |
sudo apt install libcurl4-openssl-dev jags libharfbuzz-dev libfribidi-dev libfreetype6-dev libpng-dev libtiff5-dev libjpeg-dev libglpk-dev -y | |
# Checkout the repo | |
- uses: actions/checkout@v4 | |
# Setup R (4.3.0) | |
- uses: r-lib/actions/setup-r@v2 | |
with: | |
r-version: '4.3.2' | |
# Capture dependencies | |
- name: Capture dependencies | |
run: | | |
# Install packages | |
source("global.R") | |
shell: Rscript {0} | |
env: | |
GITHUB_PAT: ${{ secrets.PAT }} | |
# Deploy using rsconnect | |
- name: Deploy | |
run: | | |
# Install rsconnect | |
install.packages("rsconnect") | |
# Set up account | |
cat("Checking account info...") | |
rsconnect::setAccountInfo( | |
Sys.getenv("accountName"), | |
Sys.getenv("accountToken"), | |
Sys.getenv("accountSecret") | |
) | |
cat(" [OK]\n") | |
cat(paste0("Deploying ", Sys.getenv("appName"), "\n")) | |
# Deploy application | |
rsconnect::deployApp( | |
appName = Sys.getenv("appName"), | |
account = Sys.getenv("accountName"), | |
forceUpdate = TRUE | |
) | |
shell: Rscript {0} | |
env: | |
accountName: crsu | |
# token and secret obtained from https://www.shinyapps.io/admin/#/tokens | |
accountToken: ${{ secrets.SHINYAPPS_TOKEN }} | |
accountSecret: ${{ secrets.SHINYAPPS_SECRET }} |