From c767eb6ac71e3e780f15dda4bb493c5d4430b51a Mon Sep 17 00:00:00 2001 From: Rich Bielby Date: Fri, 10 Nov 2023 13:32:48 +0000 Subject: [PATCH 1/2] Added development deploy to deploy script --- .github/workflows/deploy-shiny.yaml | 119 ++++++++++++++++++++++------ 1 file changed, 93 insertions(+), 26 deletions(-) diff --git a/.github/workflows/deploy-shiny.yaml b/.github/workflows/deploy-shiny.yaml index 33a317f..7df5fcf 100644 --- a/.github/workflows/deploy-shiny.yaml +++ b/.github/workflows/deploy-shiny.yaml @@ -2,33 +2,10 @@ on: push: branches: - master + - development name: deploy-shiny -# jobs: -# deploy-shiny: -# runs-on: ubuntu-latest -# steps: -# - uses: actions/checkout@v2 -# - uses: r-lib/actions/setup-r@v2 -# with: -# r-version: 4.2.1 -# use-public-rspm: true -# -# - name: Install Curl -# run: sudo apt install libcurl4-openssl-dev libssl-dev -# - name: Restore renv snapshot -# shell: Rscript {0} -# run: | -# if (!require('renv')) install.packages('renv') -# renv::restore() -# - name: Push to shiny.io -# run: > -# Rscript -# -e "rsconnect::setAccountInfo(name='department-for-education', token='${{secrets.SHINYAPPS_TOKEN}}', secret='${{secrets.SHINYAPPS_SECRET}}')" -# -e "rsconnect::deployApp()" -# - jobs: deployShiny: runs-on: ${{ matrix.config.os }} @@ -55,6 +32,56 @@ jobs: r-version: 4.2.1 use-public-rspm: true + - name: Set env vars (dev) + if: endsWith(github.ref, '/development') + run: | + echo "SHINYAPP_NAME='dev-pupil-attendance-in-schools'" >> $GITHUB_ENV + echo "SHINYAPP_OVERFLOW_NAME='dev-pupil-attendance-in-schools-overflow'">> $GITHUB_ENV + - name: Set env vars (prod) + if: endsWith(github.ref, '/main') + run: | + echo "SHINYAPP_NAME='on: + push: + branches: + - main + - development + +name: deploy-shiny + +jobs: + deployShiny: + runs-on: ${{ matrix.config.os }} + + name: ${{ matrix.config.os }} (${{ matrix.config.r }}) + + strategy: + fail-fast: false + matrix: + config: + # Running on mac as it's quicker to build + - {os: macOS-latest, r: 'release'} + + env: + R_REMOTES_NO_ERRORS_FROM_WARNINGS: true + RSPM: ${{ matrix.config.rspm }} + RENV_PATHS_ROOT: ~/.local/share/renv + + steps: + - uses: actions/checkout@v2 + + - uses: r-lib/actions/setup-r@v2 + with: + r-version: 4.2.1 + use-public-rspm: true + + - name: Set env vars (dev) + if: endsWith(github.ref, '/development') + run: | + echo "SHINYAPP_NAME='dev-ks5-transition-matrices'" >> $GITHUB_ENV + - name: Set env vars (prod) + if: endsWith(github.ref, '/main') + run: | + echo "SHINYAPP_NAME='ks5-transition-matrices'">> $GITHUB_ENV - name: Cache R packages if: runner.os != 'Windows' uses: actions/cache@v1 @@ -82,7 +109,46 @@ jobs: run: | if (!requireNamespace("renv", quietly = TRUE)) install.packages("renv") renv::install("rsconnect@0.8.29") + +# Tokens are stored as secrets in GitHub to make sure only DfE analysts can publish apps in our shiny.io area +# Navigate to Settings > Secrets to add and view secrets. These can also be things like admin login and passwords for SQL databases. +# Get in touch with the Stats Development team if you need to add the below secrets to publish to shinyapps.io + + - name: Push to shiny.io + run: > + Rscript + -e "rsconnect::setAccountInfo(name = 'department-for-education', token = '${{secrets.SHINYAPPS_TOKEN}}', secret = '${{secrets.SHINYAPPS_SECRET}}')" + -e "rsconnect::deployApp(appName=${{env.SHINYAPP_NAME}})" + -e "rsconnect::deployApp(appName=${{env.SHINYAPP_OVERFLOW_NAME}})"'">> $GITHUB_ENV + echo "SHINYAPP_OVERFLOW_NAME='pupil-attendance-in-schools-overflow'">> $GITHUB_ENV + - name: Cache R packages + if: runner.os != 'Windows' + uses: actions/cache@v1 + with: + path: ${{ env.R_LIBS_USER }} + key: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-${{ hashFiles('.github/depends.Rds') }} + restore-keys: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1- + + - name: Cache renv packages + uses: actions/cache@v1 + with: + path: ${{ env.RENV_PATHS_ROOT }} + key: ${{ runner.os }}-renv-${{ hashFiles('**/renv.lock') }} + restore-keys: | + ${{ runner.os }}-renv- + + - name: Restore renv snapshot + shell: Rscript {0} + run: | + if (!requireNamespace("renv", quietly = TRUE)) install.packages("renv") + renv::restore() + - name: Install rsconnect + shell: Rscript {0} + run: | + if (!requireNamespace("renv", quietly = TRUE)) install.packages("renv") + renv::install("rsconnect@0.8.29") + # Tokens are stored as secrets in GitHub to make sure only DfE analysts can publish apps in our shiny.io area # Navigate to Settings > Secrets to add and view secrets. These can also be things like admin login and passwords for SQL databases. # Get in touch with the Stats Development team if you need to add the below secrets to publish to shinyapps.io @@ -90,5 +156,6 @@ jobs: - name: Push to shiny.io run: > Rscript - -e "rsconnect::setAccountInfo(name='department-for-education', token='${{secrets.SHINYAPPS_TOKEN}}', secret='${{secrets.SHINYAPPS_SECRET}}')" - -e "rsconnect::deployApp()" + -e "rsconnect::setAccountInfo(name = 'department-for-education', token = '${{secrets.SHINYAPPS_TOKEN}}', secret = '${{secrets.SHINYAPPS_SECRET}}')" + -e "rsconnect::deployApp(appName=${{env.SHINYAPP_NAME}})" + \ No newline at end of file From 67c6d05dbd1f601150d6e0d9f25ab92635872e19 Mon Sep 17 00:00:00 2001 From: Rich Bielby Date: Fri, 10 Nov 2023 13:34:56 +0000 Subject: [PATCH 2/2] Removed accidental double-paste --- .github/workflows/deploy-shiny.yaml | 81 ----------------------------- 1 file changed, 81 deletions(-) diff --git a/.github/workflows/deploy-shiny.yaml b/.github/workflows/deploy-shiny.yaml index 7df5fcf..3fd9814 100644 --- a/.github/workflows/deploy-shiny.yaml +++ b/.github/workflows/deploy-shiny.yaml @@ -6,48 +6,6 @@ on: name: deploy-shiny -jobs: - deployShiny: - runs-on: ${{ matrix.config.os }} - - name: ${{ matrix.config.os }} (${{ matrix.config.r }}) - - strategy: - fail-fast: false - matrix: - config: - # Running on mac as it's quicker to build - - {os: macOS-latest, r: 'release'} - - env: - R_REMOTES_NO_ERRORS_FROM_WARNINGS: true - RSPM: ${{ matrix.config.rspm }} - RENV_PATHS_ROOT: ~/.local/share/renv - - steps: - - uses: actions/checkout@v2 - - - uses: r-lib/actions/setup-r@v2 - with: - r-version: 4.2.1 - use-public-rspm: true - - - name: Set env vars (dev) - if: endsWith(github.ref, '/development') - run: | - echo "SHINYAPP_NAME='dev-pupil-attendance-in-schools'" >> $GITHUB_ENV - echo "SHINYAPP_OVERFLOW_NAME='dev-pupil-attendance-in-schools-overflow'">> $GITHUB_ENV - - name: Set env vars (prod) - if: endsWith(github.ref, '/main') - run: | - echo "SHINYAPP_NAME='on: - push: - branches: - - main - - development - -name: deploy-shiny - jobs: deployShiny: runs-on: ${{ matrix.config.os }} @@ -119,43 +77,4 @@ jobs: Rscript -e "rsconnect::setAccountInfo(name = 'department-for-education', token = '${{secrets.SHINYAPPS_TOKEN}}', secret = '${{secrets.SHINYAPPS_SECRET}}')" -e "rsconnect::deployApp(appName=${{env.SHINYAPP_NAME}})" - -e "rsconnect::deployApp(appName=${{env.SHINYAPP_OVERFLOW_NAME}})"'">> $GITHUB_ENV - echo "SHINYAPP_OVERFLOW_NAME='pupil-attendance-in-schools-overflow'">> $GITHUB_ENV - - name: Cache R packages - if: runner.os != 'Windows' - uses: actions/cache@v1 - with: - path: ${{ env.R_LIBS_USER }} - key: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-${{ hashFiles('.github/depends.Rds') }} - restore-keys: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1- - - name: Cache renv packages - uses: actions/cache@v1 - with: - path: ${{ env.RENV_PATHS_ROOT }} - key: ${{ runner.os }}-renv-${{ hashFiles('**/renv.lock') }} - restore-keys: | - ${{ runner.os }}-renv- - - - name: Restore renv snapshot - shell: Rscript {0} - run: | - if (!requireNamespace("renv", quietly = TRUE)) install.packages("renv") - renv::restore() - - - name: Install rsconnect - shell: Rscript {0} - run: | - if (!requireNamespace("renv", quietly = TRUE)) install.packages("renv") - renv::install("rsconnect@0.8.29") - -# Tokens are stored as secrets in GitHub to make sure only DfE analysts can publish apps in our shiny.io area -# Navigate to Settings > Secrets to add and view secrets. These can also be things like admin login and passwords for SQL databases. -# Get in touch with the Stats Development team if you need to add the below secrets to publish to shinyapps.io - - - name: Push to shiny.io - run: > - Rscript - -e "rsconnect::setAccountInfo(name = 'department-for-education', token = '${{secrets.SHINYAPPS_TOKEN}}', secret = '${{secrets.SHINYAPPS_SECRET}}')" - -e "rsconnect::deployApp(appName=${{env.SHINYAPP_NAME}})" - \ No newline at end of file