Include summary trees in pkgdown configuration #428
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
| on: | |
| push: | |
| branches: | |
| - main | |
| - master | |
| paths: | |
| - 'DESCRIPTION' | |
| - '**pkgdown.yml' | |
| - '*.md' | |
| - 'inst/CITATION' | |
| - 'inst/*.bib' | |
| - 'man/**.Rd' | |
| - 'vignettes/**.Rmd' | |
| release: | |
| types: [published] | |
| workflow_dispatch: | |
| name: pkgdown | |
| jobs: | |
| pkgdown: | |
| runs-on: ubuntu-latest | |
| env: | |
| GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} | |
| steps: | |
| # ── Build pkgdown site (no shinylive, no deploy) ────────────── | |
| - uses: ms609/actions/pkgdown@main | |
| with: | |
| extra-repositories: https://ms609.github.io/packages/ | |
| deploy: 'false' | |
| # ── Export Shinylive app ────────────────────────────────────── | |
| - name: Export Shinylive app | |
| shell: Rscript {0} | |
| run: | | |
| # ── Pin shiny to pre-otel version ── | |
| # otel (OpenTelemetry) became a hard Import of shiny in 1.12.0, | |
| # but otel is not yet available as a WebAssembly binary on | |
| # repo.r-wasm.org. shinylive resolves deps from the LOCAL | |
| # library, so the installed shiny's otel dep causes a download | |
| # failure. Pin to the last CRAN release without otel. | |
| # | |
| # TODO: Remove this pin once otel appears at | |
| # http://repo.r-wasm.org/bin/emscripten/contrib/4.4/PACKAGES | |
| install.packages( | |
| "https://cran.r-project.org/src/contrib/Archive/shiny/shiny_1.11.1.tar.gz", | |
| repos = NULL, type = "source" | |
| ) | |
| # ── Work around shinylive bug (coatless/quarto-webr#228) ── | |
| # shinylive resolves deps from the WASM repo's PACKAGES | |
| # database, which may reference packages not installed | |
| # locally (e.g. R.cache). packageDescription() returns NA | |
| # for these, and shinylive crashes on desc$Repository. | |
| # Patch packageDescription to return a stub instead of NA. | |
| # | |
| # TODO: Remove once shinylive handles missing packages. | |
| local({ | |
| real_pd <- utils::packageDescription | |
| ns <- asNamespace("utils") | |
| unlockBinding("packageDescription", ns) | |
| assign("packageDescription", function(pkg, lib.loc = NULL, | |
| fields = NULL, drop = TRUE, encoding = "") { | |
| result <- real_pd(pkg, lib.loc = lib.loc, fields = fields, | |
| drop = drop, encoding = encoding) | |
| if (identical(result, NA)) { | |
| message(" [shinylive patch] '", pkg, | |
| "' not installed locally; stub description used") | |
| result <- structure( | |
| list(Package = pkg, Version = "0.0.0", | |
| Repository = "CRAN"), | |
| class = "packageDescription" | |
| ) | |
| if (!is.null(fields)) { | |
| result <- result[fields] | |
| if (drop && length(fields) == 1L) | |
| return(result[[1L]]) | |
| } | |
| } | |
| result | |
| }, envir = ns) | |
| }) | |
| # ── Fall back to r-universe for missing WASM binaries ── | |
| # repo.r-wasm.org can lag days/weeks behind CRAN for new | |
| # releases. r-universe builds WASM per-commit, so we | |
| # re-install from there to make shinylive look at the | |
| # r-universe WASM endpoint instead. | |
| # This means the r-universe (dev) version is bundled, not | |
| # the CRAN release — acceptable as a temporary measure. | |
| local({ | |
| r_ver <- paste(R.version$major, | |
| sub("\\..*", "", R.version$minor), sep = ".") | |
| wasm_db <- tryCatch( | |
| available.packages(repos = paste0( | |
| "https://repo.r-wasm.org/bin/emscripten/contrib/", r_ver | |
| )), | |
| error = function(e) { | |
| message(" Could not reach repo.r-wasm.org") | |
| matrix(nrow = 0, ncol = 0, | |
| dimnames = list(NULL, character())) | |
| } | |
| ) | |
| # Packages to check (extend as needed) | |
| pkgs <- "TreeTools" | |
| for (pkg in pkgs) { | |
| inst_ver <- as.character(packageVersion(pkg)) | |
| wasm_ver <- if (pkg %in% rownames(wasm_db)) | |
| wasm_db[pkg, "Version"] else NA_character_ | |
| if (is.na(wasm_ver) || | |
| package_version(wasm_ver) < package_version(inst_ver)) { | |
| message(pkg, " ", inst_ver, | |
| " WASM not on repo.r-wasm.org (have: ", wasm_ver, | |
| "); installing from r-universe") | |
| install.packages(pkg, repos = c( | |
| "https://ms609.r-universe.dev", | |
| getOption("repos") | |
| )) | |
| } else { | |
| message(pkg, " ", wasm_ver, " WASM available on ", | |
| "repo.r-wasm.org; using CRAN version") | |
| } | |
| } | |
| }) | |
| # ── Locate app ── | |
| pkg_name <- read.dcf("DESCRIPTION")[, "Package"] | |
| app_dir <- system.file("treespace", package = pkg_name) | |
| if (!dir.exists(app_dir)) app_dir <- "inst/treespace" | |
| stopifnot( | |
| "app.R not found" = file.exists(file.path(app_dir, "app.R")) | |
| ) | |
| # ── Export ── | |
| if (!requireNamespace("shinylive", quietly = TRUE)) { | |
| install.packages("shinylive") | |
| } | |
| tryCatch( | |
| shinylive::export(appdir = app_dir, destdir = "docs/app"), | |
| error = function(e) { | |
| msg <- conditionMessage(e) | |
| message("\n===== shinylive::export() failed =====") | |
| message(msg) | |
| message("This is often caused by a dependency that is not") | |
| message("available as a WebAssembly binary. Check:") | |
| message(" http://repo.r-wasm.org/bin/emscripten/contrib/4.4/PACKAGES") | |
| stop(e) | |
| } | |
| ) | |
| file.create("docs/.nojekyll") | |
| # ── Deploy ──────────────────────────────────────────────────── | |
| - name: Deploy to GitHub Pages | |
| uses: JamesIves/github-pages-deploy-action@v4 | |
| with: | |
| folder: docs | |
| branch: gh-pages | |
| clean: false |