Hi, I'm finishing up working on some CI/CD stuff for a Shiny app of mine. I'm using GitHub actions to build & deploy my app to shinyapps anytime I push code to the master branch. Everything works, but I have a remote DB i want to connect to and I need to store some credentials in a .Renviron file. Obviously I don't want that just hanging around in a git repo, so I thought I could store all of the actual credentials with GitHub secrets and then write the .Renviron file in the GitHub Actions yaml script by referencing the secrets.
I believe this idea can work, but i don't think the .Renviron file is ever in the right directory? So when I call rsconnect to build & deploy the app it never has a .Renviron file there in the first place, and then my Shiny app doesn't have any of those env variables.
Below is my code, the step I'm having difficulty on is the create and populate .Renviron file.
on: [push, pull_request]
name: CI-CD
jobs:
CI-CD:
runs-on: ${{ matrix.config.os }}
name: ${{ matrix.config.os }} (${{ matrix.config.r }})
strategy:
matrix:
config:
- {os: ubuntu-20.04, r: 'release', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"}
env:
# Enable RStudio Package Manager to speed up package installation
RSPM: ${{ matrix.config.rspm }}
# Access token for GitHub
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: Checkout repo
uses: actions/checkout@v2
- name: Setup R
uses: r-lib/actions/setup-r@v1
with:
r-version: ${{ matrix.config.r }}
- name: Install system dependencies
run: |
while read -r cmd
do
eval sudo $cmd
done < <(Rscript -e 'writeLines(remotes::system_requirements("ubuntu", "20.04"))')
- name: Install R dependencies
run: |
remotes::install_deps(dependencies = TRUE)
remotes::install_cran("rcmdcheck")
shell: Rscript {0}
- name: Create and populate .Renviron file
env:
AWS_HOST: ${{ secrets.AWS_HOST }}
AWS_PORT: ${{ secrets.AWS_PORT }}
AWS_PW: ${{ secrets.AWS_PW }}
AWS_USER: ${{ secrets.AWS_USER }}
DBNAME: ${{ secrets.DBNAME }}
run: |
touch .Renviron
echo aws_host="$AWS_HOST" >> .Renviron
echo aws_port="$AWS_PORT" >> .Renviron
echo aws_pw="$AWS_PW" >> .Renviron
echo aws_user="$AWS_USER" >> .Renviron
echo dbname="$DBNAME" >> .Renviron
ls ${{ github.workspace }}
shell: bash
- name: Deploy to shinyapps.io
# continuous deployment only for pushes to the main / master branch
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master'
env:
SHINYAPPS_ACCOUNT: ${{ secrets.SHINYAPPS_ACCOUNT }}
SHINYAPPS_TOKEN: ${{ secrets.SHINYAPPS_TOKEN }}
SHINYAPPS_SECRET: ${{ secrets.SHINYAPPS_SECRET }}
run: Rscript deploy/deploy-shinyapps.R
I've tried a whole bunch of file paths and I always run ls {{ github.workspace }} afterwards to check if the .Renviron got written there because that's where I want it saved to, but it never gets listed. I'm not sure if i'm screwing up the file paths, or if it's getting saved somewhere else, or maybe it's not persisting for some reason? I thought gitignore was interfering but it doesn't appear so. If anyone has any ideas I'd appreciate it!