remove title and caption inputs, add Comments input for email #113
Workflow file for this run
This file contains hidden or 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
| # Deploy a PR to shinyapps.io when a PR is ready to be deployed (either because | |
| # the label was just added to it or because a new commit was made) | |
| # Workflow borrows from https://github.com/r-lib/actions/tree/v2/examples | |
| name: Shiny PR 2 Deploy | |
| on: | |
| pull_request_target: | |
| types: [labeled, synchronize] | |
| workflow_dispatch: | |
| jobs: | |
| deployment-pr: | |
| if: | | |
| github.event_name == 'workflow_dispatch' || | |
| (github.event.action == 'labeled' && github.event.label.name == 'DEPLOY') || | |
| (github.event.action == 'synchronize' && contains(github.event.pull_request.labels.*.name, 'DEPLOY')) | |
| runs-on: ubuntu-24.04 | |
| env: | |
| GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} | |
| SHINY_APP_NAME: ${{ vars.SHINY_APP_NAME }}_PR_${{ github.event.pull_request.number }} | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ github.event.pull_request.head.sha }} | |
| - name: Setup pandoc | |
| uses: r-lib/actions/setup-pandoc@v2 | |
| - name: Setup R | |
| uses: r-lib/actions/setup-r@v2 | |
| with: | |
| r-version: 'renv' | |
| use-public-rspm: true | |
| - name: Install system dependencies | |
| run: sudo apt-get update && sudo apt-get install -y libpng-dev | |
| - uses: r-lib/actions/setup-renv@v2 | |
| - name: Install stanpumpR from GitHub | |
| run: | | |
| pkg_ref <- paste0("${{ github.event.pull_request.head.repo.full_name }}@", "${{ github.event.pull_request.head.sha }}") | |
| remotes::install_github(pkg_ref, upgrade = "never", force = TRUE) | |
| find.package("stanpumpR") # force a failure if package didn't install so GHA won't continue | |
| shell: Rscript {0} | |
| - name: Remove renv lockfile | |
| run: sudo rm renv.lock # now that all pacakges have correct versions, remove lockfile | |
| # because deployApp() will fail if it sees this lockfile | |
| # see https://github.com/rstudio/rsconnect/issues/1315 | |
| - name: Authorize and deploy app | |
| env: | |
| PR_TITLE: ${{ github.event.pull_request.title }} | |
| run: | | |
| shinyConfig <- list( | |
| default = list( | |
| title = paste("PR #${{ github.event.pull_request.number }}:", Sys.getenv("PR_TITLE")), | |
| long_title = TRUE, | |
| email_username = "${{ secrets.SHINY_CONFIG_EMAIL_USERNAME }}", | |
| email_password = "${{ secrets.SHINY_CONFIG_EMAIL_PASSWORD }}", | |
| debug = 1 | |
| ) | |
| ) | |
| yaml::write_yaml(shinyConfig, "config.yml", fileEncoding = "UTF-8") | |
| rsconnect::setAccountInfo("${{ vars.SHINY_ACCOUNT }}", "${{ secrets.SHINY_TOKEN }}", "${{ secrets.SHINY_SECRET }}") | |
| rsconnect::deployApp( | |
| appName = "${{ env.SHINY_APP_NAME }}", account = "${{ vars.SHINY_ACCOUNT }}", | |
| appDir = ".", appFiles = c("app.R", "config.yml"), forceUpdate = TRUE | |
| ) | |
| shell: Rscript {0} | |
| - name: Comment PR with deployment URL | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| await github.rest.issues.createComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: context.issue.number, | |
| body: `**Preview Deployment**\n\nThis PR has been deployed to: https://${{ vars.SHINY_ACCOUNT }}.shinyapps.io/${{ env.SHINY_APP_NAME }}/\n\n_This deployment will be automatically cleaned up when the PR is closed._` | |
| }) |