-
Notifications
You must be signed in to change notification settings - Fork 6
162 lines (150 loc) · 6.36 KB
/
pkgdown.yml
File metadata and controls
162 lines (150 loc) · 6.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
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