title: How to reference GitHub Secrets in GitHub Actions workflow for .Renviron file
body: <p>Hi I'm just about finished up using GitHub actions to add CI / CD steps to deploy an R Shiny app I have.  The problem I'm having is there is a file in R called <code>.Renviron</code> that I use to store credentials to access a SQL DB of mine in the R script.  Normally I deploy my app locally and this file is included when I use the rsconnect package, but now that I'm using GitHub actions I believe I have to make this .Renviron file manually myself in a bash script step.</p>
  <p>Below is what my github workflow code looks like as of right now.  The problem I'm having issues with is the <code>Create and populate .Renviron file</code> part.</p>
  <pre><code># Triggered on push and pull request events
  on: [push, pull_request]
  
  # Name of the workflow =&gt; usethis::use_github_actions_badge(&quot;CI-CD&quot;)
  name: CI-CD
  
  jobs:
    CI-CD:
      runs-on: ${{ matrix.config.os }}
  
      name: ${{ matrix.config.os }} (${{ matrix.config.r }})
  
      strategy:
        # we keep a matrix for convenience, but we would typically just run on one
        # single OS and R version, aligned with the target deployment environment
        matrix:
          config:
            - {os: ubuntu-20.04, r: 'release', rspm: &quot;https://packagemanager.rstudio.com/cran/__linux__/focal/latest&quot;}
  
      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: Query R dependencies
          run: |
            install.packages('remotes')
            saveRDS(remotes::dev_package_deps(dependencies = TRUE), &quot;.github/depends.Rds&quot;, version = 2)
            writeLines(sprintf(&quot;R-%i.%i&quot;, getRversion()$major, getRversion()$minor), &quot;.github/R-version&quot;)
          shell: Rscript {0}
  
        - name: Cache R packages
          uses: actions/cache@v2
          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: Install system dependencies
          run: |
            while read -r cmd
            do
              eval sudo $cmd
            done &lt; &lt;(Rscript -e 'writeLines(remotes::system_requirements(&quot;ubuntu&quot;, &quot;20.04&quot;))')
  
        - name: Install R dependencies
          run: |
            remotes::install_deps(dependencies = TRUE)
            remotes::install_cran(&quot;rcmdcheck&quot;)
          shell: Rscript {0}
  
        - name: Create and populate .Renviron file
          run: |
            echo aws_host=&quot;$AWS_HOST&quot; &gt;&gt; ~/.Renviron
            echo aws_port=&quot;$AWS_PORT&quot; &gt;&gt; ~/.Renviron
            echo aws_pw=&quot;$AWS_PW&quot; &gt;&gt; ~/.Renviron
            echo aws_user=&quot;$AWS_USER&quot; &gt;&gt; ~/.Renviron
            echo dbname=&quot;$DBNAME&quot; &gt;&gt; ~/.Renviron
          shell: bash
  
        - name: Check package
          run: |
            options(crayon.enabled = TRUE) # enable colorful R CMD check output
            rcmdcheck::rcmdcheck(args = &quot;--no-manual&quot;, error_on = &quot;error&quot;)
          shell: Rscript {0}
  
        - 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
  
  </code></pre>
  <p><a href="https://i.stack.imgur.com/caU5q.png" rel="noreferrer"><img src="https://i.stack.imgur.com/caU5q.png" alt="enter image description here" /></a></p>
  <p>I have all of those variables stored in GitHub secrets, but I still can't get my Shiny app to access any of those credentials via the .Renviron file.  I believe the syntax of accessing those GitHub secrets is different than the normal ${{ secrets.my_secret }} because it's in a bash script.</p>
  <p>The file location of the .Renviron file is also important, it should be at root directory where everything else in the GitHub repository is located.  I'm not sure how to know / confirm if it's in the right location or not.</p>
  <p>If anyone has any advice on how to properly create this .Renviron file using GitHub secrets and place it at the root of my directory I'd appreciate it!</p>