Skip to content

Commit d33467e

Browse files
toph-allenkarawoo
andauthored
runtime version scanner: organize files like an r package (#279)
* reorganize files * update github action * migrate to connectapi’s built-in get_usage * Update extensions/runtime-version-scanner/.Rbuildignore Co-authored-by: Kara Woo <[email protected]> * Update extensions/runtime-version-scanner/DESCRIPTION Co-authored-by: Kara Woo <[email protected]> * Update DESCRIPTION * update packaging workflow --------- Co-authored-by: Kara Woo <[email protected]>
1 parent 7ad6f47 commit d33467e

File tree

14 files changed

+296
-459
lines changed

14 files changed

+296
-459
lines changed

.github/workflows/runtime-version-scanner.yml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ jobs:
4242
- run: Rscript -e 'install.packages(c("testthat", "httptest"))'
4343
working-directory: extensions/${{ env.EXTENSION_NAME }}
4444

45-
- run: Rscript -e 'testthat::test_dir("tests/testthat")'
45+
- run: Rscript -e 'testthat::test_local()'
4646
working-directory: extensions/${{ env.EXTENSION_NAME }}
4747

4848
# Now that the extension is built we need to upload an artifact to pass
@@ -57,13 +57,12 @@ jobs:
5757
# Replace the below with the files your content needs
5858
path: |
5959
extensions/${{ env.EXTENSION_NAME }}/app.R
60-
extensions/${{ env.EXTENSION_NAME }}/connect_module.R
61-
extensions/${{ env.EXTENSION_NAME }}/get_usage.R
62-
extensions/${{ env.EXTENSION_NAME }}/renv.lock
63-
extensions/${{ env.EXTENSION_NAME }}/version_ordering.R
64-
extensions/${{ env.EXTENSION_NAME }}/supported_versions.R
60+
extensions/${{ env.EXTENSION_NAME }}/R/connect_module.R
61+
extensions/${{ env.EXTENSION_NAME }}/R/supported_versions.R
62+
extensions/${{ env.EXTENSION_NAME }}/R/version_ordering.R
6563
extensions/${{ env.EXTENSION_NAME }}/www/styles.css
6664
extensions/${{ env.EXTENSION_NAME }}/manifest.json
65+
extensions/${{ env.EXTENSION_NAME }}/renv.lock
6766
6867
# Package up the extension into a TAR using the package-extension action
6968
- uses: ./.github/actions/package-extension
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
^renv$
2+
^renv\.lock$
3+
^app\.R$
4+
^Makefile$
5+
^manifest\.json$
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Changelog
2+
3+
All notable changes to the Usage Metrics Dashboard extension will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7+
8+
## [1.0.1]
9+
10+
### Added
11+
12+
- Added CHANGELOG.md to the repo.
13+
- Reorganized code to use an R package-like structure.
14+
15+
## [1.0.0]
16+
17+
### Added
18+
19+
- Initial release.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Package: runtime.version.scanner
2+
Title: Runtime Version Scanner
3+
Version: 1.0.1
4+
Authors@R: c(
5+
person("Toph", "Allen", , "[email protected]", role = c("aut", "cre")),
6+
person(given = "Posit, PBC", role = c("cph", "fnd")))
7+
Description: Functions to power the Runtime Version Scanner extension.
8+
License: MIT + file LICENSE

extensions/runtime-version-scanner/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
.PHONY: test update-manifest
22

33
test:
4-
Rscript -e 'testthat::test_dir("tests/testthat")'
4+
Rscript -e 'testthat::test_local()'
55

66
# This recipe updates the manifest, with a few helpful modifications:
77
# - Copies over `extension` and `environment` blocks from the old manifest to

extensions/runtime-version-scanner/connect_module.R renamed to extensions/runtime-version-scanner/R/connect_module.R

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ connectVisitorClient <- function(
9292
}
9393
)
9494

95-
# “Use the ‘…’ Integration” button logic
9695
observeEvent(input$auto_add_integration, {
9796
auto_add_integration(publisher_client, selected_integration_guid())
9897
runjs("window.top.location.reload(true);")

extensions/runtime-version-scanner/app.R

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,8 @@ ANY_VERSION <- "999.99.99"
1616

1717
plan(mirai_multisession)
1818

19-
source("get_usage.R")
20-
source("connect_module.R")
21-
source("version_ordering.R")
22-
source("supported_versions.R")
19+
files.sources = list.files("R", full.names = TRUE)
20+
sapply(files.sources, source)
2321

2422
options(
2523
spinner.type = 1,
@@ -48,6 +46,11 @@ app_mode_lookup <- with(
4846
setNames(as.character(ind), values)
4947
)
5048

49+
to_iso8601 <- function(x) {
50+
strftime(x, "%Y-%m-%dT%H:%M:%S%z") |>
51+
sub("([+-]\\d{2})(\\d{2})$", "\\1:\\2", x = _)
52+
}
53+
5154
# Shiny app definition
5255

5356
ui <- page_sidebar(
@@ -400,7 +403,15 @@ server <- function(input, output, session) {
400403

401404
usage_task <- ExtendedTask$new(function(window_days) {
402405
future({
403-
get_usage(client, from = today() - days(window_days), to = today()) |>
406+
from <- as.POSIXct(
407+
paste(today() - days(window_days), "00:00:00"),
408+
tz = ""
409+
)
410+
to <- as.POSIXct(paste(today(), "00:00:00"), tz = "")
411+
412+
usage_list <- get_usage(client, from = from, to = to)
413+
as_tibble(usage_list) |>
414+
select(content_guid) |>
404415
group_by(content_guid) |>
405416
summarize(views = n(), .groups = "drop")
406417
})

extensions/runtime-version-scanner/get_usage.R

Lines changed: 0 additions & 39 deletions
This file was deleted.

0 commit comments

Comments
 (0)