Skip to content

Commit

Permalink
Post workshop changes (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
schloerke authored Mar 9, 2021
1 parent 1eb2975 commit f111182
Show file tree
Hide file tree
Showing 25 changed files with 1,739 additions and 1,593 deletions.
1 change: 1 addition & 0 deletions .Rprofile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
source("renv/activate.R")
12 changes: 11 additions & 1 deletion .github/workflows/rstudio-connect-main.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
name: Deploy main to Connect
on:
push:
branches: main
branches:
- main

jobs:
deploy:
Expand All @@ -11,6 +12,13 @@ jobs:
- name: Check out the repo
uses: actions/checkout@v2

# Connect does not like `renv`'s `./.Rprofile`
# Removing from deployment as Connect listens to the `./manifest.json` file
- name: Remove `.Rprofile`
shell: bash
run: |
rm .Rprofile
- name: Publish the app
uses: rstudio/actions/connect-publish@main
with:
Expand All @@ -20,5 +28,7 @@ jobs:
show-logs: true
# for more on app identifiers or multiple app deployments, see
# https://github.com/rstudio/actions/tree/main/connect-publish#dir
# Deploy app located at `./` to `shinytest-example-app`
# with vanity url `/shinytest-example-app`
dir: |
.:/shinytest-example-app
13 changes: 11 additions & 2 deletions .github/workflows/rstudio-connect-pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,23 @@ jobs:
- name: Check out the repo
uses: actions/checkout@v2

# Connect does not like `renv`'s `./.Rprofile`
# Removing from deployment as Connect listens to the `./manifest.json` file
- name: Remove `.Rprofile`
shell: bash
run: |
rm .Rprofile
- name: Publish the PR
uses: rstudio/actions/connect-publish@main
with:
url: https://colorado.rstudio.com/rsc/
api-key: ${{ secrets.CONNECT_API_KEY }}
access-type: all
show-logs: true
# for more on app identifiers or multiple app deployments, see
# For more on app identifiers or multiple app deployments, see
# https://github.com/rstudio/actions/tree/main/connect-publish#dir
# Deploy app located at `./` to `prshinytest-example-app1234`
# with vanity url `/pr/shinytest-example-app/1234`
dir: |
./:/pr/shinytest-example-app/${{ github.head_ref }}
./:/pr/shinytest-example-app/${{ github.event.number }}
65 changes: 33 additions & 32 deletions .github/workflows/run-shinytest.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
# from: https://github.com/rstudio/shiny-testing-gha-example/blob/single_platform_snapshot/.github/workflows/run-tests.yaml
on:
push:
branches:
- main
pull_request:
branches:
- main

name: Run shinytest

Expand All @@ -19,7 +23,8 @@ jobs:
#- {os: windows-latest, r: 'release'}
# disabled due to race conditions / parallelism
#- {os: macOS-latest, r: 'release'}
- {os: ubuntu-18.04, r: 'release', rspm: "https://packagemanager.rstudio.com/cran/__linux__/bionic/latest"}
# Match your manifest file R version
- {os: ubuntu-18.04, r: '4.0.2', rspm: "https://packagemanager.rstudio.com/cran/__linux__/bionic/latest"}

env:
R_REMOTES_NO_ERRORS_FROM_WARNINGS: true
Expand All @@ -35,47 +40,56 @@ jobs:
- uses: actions/checkout@v2

- uses: r-lib/actions/setup-r@master
id: install-r
with:
r-version: ${{ matrix.config.r }}

- uses: r-lib/actions/setup-pandoc@master

- name: Query dependencies
run: |
install.packages('remotes')
writeLines(sprintf("R-%i.%i", getRversion()$major, getRversion()$minor), ".github/R-version")
- name: Cache R packages
uses: actions/cache@v1
with:
path: renv/library
key: ${{ matrix.config.os }}-${{ steps.install-r.outputs.installed-r-version }}-1-${{ hashFiles('renv.lock') }}
restore-keys: ${{ matrix.config.os }}-${{ steps.install-r.outputs.installed-r-version }}-1-

- name: Make sure renv exists
shell: Rscript {0}
run: |
if (system.file(package = "renv") == "") install.packages("renv")
#- 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
# restore-keys: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-
- name: Verify R version matches
shell: Rscript {0}
run: |
renv::restore(packages = "jsonlite")
# Assert that R versions match
stopifnot(
compareVersion(
paste0(R.version$major, ".", R.version$minor),
jsonlite::read_json("renv.lock")$R$Version
) == 0
)
- name: Install system dependencies
if: runner.os == 'Linux'
# do not record `pak` activity
shell: Rscript {0}
run: |
# do not activate
remotes::install_cran("renv")
install.packages("pak", repos = "https://r-lib.github.io/p/pak/dev/")
lapply(unique(renv::dependencies()$Package), function(pkg) {
lapply(names(jsonlite::read_json("renv.lock")$Packages), function(pkg) {
pak::pkg_system_requirements(pkg, execute = TRUE)
})
remove.packages("pak")
- name: Install dependencies
- name: Restore renv packages
shell: Rscript {0}
run: |
remotes::install_cran("renv")
source("renv/activate.R")
renv::restore()
- name: Find PhantomJS path
id: phantomjs
run: |
echo "::set-output name=path::$(Rscript -e 'renv::activate(); cat(shinytest:::phantom_paths()[[1]])')"
echo "::set-output name=path::$(Rscript -e 'cat(shinytest:::phantom_paths()[[1]])')"
- name: Cache PhantomJS
uses: actions/cache@v2
with:
Expand All @@ -85,26 +99,13 @@ jobs:
- name: Install PhantomJS
shell: Rscript {0}
run: |
renv::activate()
if (!shinytest::dependenciesInstalled()) shinytest::installDependencies()
- name: Run tests
shell: Rscript {0}
run: |
renv::activate()
shiny::runTests(".", assert = TRUE)
- name: Check test results
shell: Rscript {0}
run: |
renv::activate()
results <- shinytest::textTestDiff()
clean_results <- attr(results, "status")
if (any(clean_results == "reject")) {
cat(results)
stop("Failing tests on differences")
}
- name: Upload test results
if: failure()
uses: actions/upload-artifact@master
Expand Down
95 changes: 95 additions & 0 deletions .github/workflows/sync-manifest.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# from: https://github.com/rstudio/shiny-testing-gha-example/blob/single_platform_snapshot/.github/workflows/run-tests.yaml
on:
push:
paths:
- 'renv.lock'

name: Update `manifest.json`

jobs:
manifest:
runs-on: ${{ matrix.config.os }}

name: Sync manifest.json with renv.lock

strategy:
fail-fast: false
matrix:
config:
# Match your manifest file R version
- {os: ubuntu-18.04, r: '4.0.2', rspm: "https://packagemanager.rstudio.com/cran/__linux__/bionic/latest"}

env:
R_REMOTES_NO_ERRORS_FROM_WARNINGS: true
RSPM: ${{ matrix.config.rspm }}

steps:

- uses: actions/checkout@v2

- uses: r-lib/actions/setup-r@master
id: install-r
with:
r-version: ${{ matrix.config.r }}

- uses: r-lib/actions/setup-pandoc@master

- name: Cache R packages
uses: actions/cache@v1
with:
path: renv/library
key: ${{ matrix.config.os }}-${{ steps.install-r.outputs.installed-r-version }}-1-${{ hashFiles('renv.lock') }}
restore-keys: ${{ matrix.config.os }}-${{ steps.install-r.outputs.installed-r-version }}-1-

- name: Make sure renv exists
shell: Rscript {0}
run: |
if (system.file(package = "renv") == "") install.packages("renv")
- name: Verify R version matches
shell: Rscript {0}
run: |
renv::restore(packages = "jsonlite")
# Assert that R versions match
stopifnot(
compareVersion(
paste0(R.version$major, ".", R.version$minor),
jsonlite::read_json("renv.lock")$R$Version
) == 0
)
- name: Install system dependencies
if: runner.os == 'Linux'
# do not record `pak` activity
shell: Rscript {0}
run: |
install.packages("pak", repos = "https://r-lib.github.io/p/pak/dev/")
lapply(names(jsonlite::read_json("renv.lock")$Packages), function(pkg) {
pak::pkg_system_requirements(pkg, execute = TRUE)
})
remove.packages("pak")
- name: Restore renv packages
shell: Rscript {0}
run: |
renv::restore()
- name: Sync manifest.json
shell: Rscript {0}
run: |
if (system.file(package = "rsconnect") == "") install.packages("rsconnect")
# Connect does not like `renv`'s `./.Rprofile`
# Removing file as Connect listens to the `./manifest.json` files
unlink(".Rprofile")
rsconnect::writeManifest(appDir = "./")
- name: Git Config
run: |
git config user.name "${GITHUB_ACTOR}"
git config user.email "${GITHUB_ACTOR}@users.noreply.github.com"
git add manifest.json && git commit -m 'manifest.json (GitHub Actions)' || echo "No manifest.json changes to commit"
- name: Git Push
if: github.event_name == 'push'
run: |
git push https://${{github.actor}}:${{secrets.GITHUB_TOKEN}}@github.com/${{github.repository}}.git HEAD:${{ github.ref }} || echo "No changes to push"
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@
.Rhistory
.RData
.Ruserdata
.Rprofile*
.Renviron*
Loading

0 comments on commit f111182

Please sign in to comment.