Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run integration tests against many versions; remove warnings unless outside of that range #244

Merged
merged 11 commits into from
Apr 18, 2024
Merged
4 changes: 2 additions & 2 deletions .github/local/test-connect-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ services:

connect1:
hostname: connect1
image: rstudio/rstudio-connect:${RSC_VERSION}
image: rstudio/rstudio-connect:${CONNECT_VERSION}
ports:
- 3939
privileged: true
environment:
- RSC_LICENSE
connect2:
hostname: connect2
image: rstudio/rstudio-connect:${RSC_VERSION}
image: rstudio/rstudio-connect:${CONNECT_VERSION}
ports:
- 3939
privileged: true
Expand Down
16 changes: 14 additions & 2 deletions .github/workflows/integration-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,20 @@ name: integration-tests
jobs:
integration-tests:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
version:
- "2024.03.0" # jammy
- "2023.09.0" # jammy
- "2023.03.0" # bionic
- "2022.09.0" # bionic
- "2022.03.2"
- "2021.09.0"
- "1.8.8.2"

env:
RSC_VERSION: 2022.09.0
CONNECT_VERSION: ${{ matrix.version }}
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
RSC_LICENSE: ${{ secrets.RSC_LICENSE }}
CONNECT_LICENSE_FILE: ${{ secrets.CONNECT_LICENSE_FILE }}
Expand Down Expand Up @@ -58,5 +70,5 @@ jobs:
if: failure()
uses: actions/upload-artifact@main
with:
name: ${{ runner.os }}-r${{ matrix.config.r }}-results
name: ${{ runner.os }}-${{ matrix.version }}-results
path: check
2 changes: 1 addition & 1 deletion .github/workflows/pkgdown.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
runs-on: ubuntu-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
RSC_VERSION: 2022.09.0
CONNECT_VERSION: 2024.03.0
RSC_LICENSE: ${{ secrets.RSC_LICENSE }}
CONNECT_LICENSE_FILE: ${{ secrets.CONNECT_LICENSE_FILE }}

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pr-commands.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
runs-on: ubuntu-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
RSC_VERSION: 2022.09.0
CONNECT_VERSION: 2024.03.0
RSC_LICENSE: ${{ secrets.RSC_LICENSE }}
CONNECT_LICENSE_FILE: ${{ secrets.CONNECT_LICENSE_FILE }}
CONNECTAPI_INTEGRATED: true
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-coverage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
runs-on: ubuntu-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
RSC_VERSION: 2022.09.0
CONNECT_VERSION: 2024.03.0
RSC_LICENSE: ${{ secrets.RSC_LICENSE }}
CONNECT_LICENSE_FILE: ${{ secrets.CONNECT_LICENSE_FILE }}
CONNECTAPI_INTEGRATED: true
Expand Down
16 changes: 8 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ PWD := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))

PROJECT=connectapi
NETWORK=${PROJECT}_default
RSC_VERSION=2022.09.0
CONNECT_VERSION=2024.03.0

#---------------------------------------------
# Network
Expand All @@ -30,10 +30,10 @@ network-down:
# Update versions
#---------------------------------------------
update-versions:
@sed -i '' "s/RSC_VERSION\:.*/RSC_VERSION: ${RSC_VERSION}/g" .github/workflows/pkgdown.yaml
@sed -i '' "s/RSC_VERSION\:.*/RSC_VERSION: ${RSC_VERSION}/g" .github/workflows/test-coverage.yaml
@sed -i '' "s/RSC_VERSION\:.*/RSC_VERSION: ${RSC_VERSION}/g" .github/workflows/integration-tests.yaml
@sed -i '' "s/^current_connect_version <- .*/current_connect_version <- '${RSC_VERSION}'/g" R/connectapi.R
@sed -i '' "s/CONNECT_VERSION\:.*/CONNECT_VERSION: ${CONNECT_VERSION}/g" .github/workflows/pkgdown.yaml
@sed -i '' "s/CONNECT_VERSION\:.*/CONNECT_VERSION: ${CONNECT_VERSION}/g" .github/workflows/test-coverage.yaml
@sed -i '' "s/CONNECT_VERSION\:.*/CONNECT_VERSION: ${CONNECT_VERSION}/g" .github/workflows/pr-commands.yaml
@sed -i '' "s/^current_connect_version <- .*/current_connect_version <- '${CONNECT_VERSION}'/g" R/connectapi.R

#---------------------------------------------
# Helpers
Expand All @@ -49,7 +49,7 @@ mail-down:
connect-up:
NETWORK=${NETWORK} \
RSC_LICENSE=$(RSC_LICENSE) \
RSC_VERSION=$(RSC_VERSION) \
CONNECT_VERSION=$(CONNECT_VERSION) \
docker compose -f inst/ci/test-connect.yml -f .github/local/make-network.yml up -d

connect-down:
Expand All @@ -59,7 +59,7 @@ connect-down:
connect-file-up:
NETWORK=${NETWORK} \
RSC_LICENSE=$(RSC_LICENSE) \
RSC_VERSION=$(RSC_VERSION) \
CONNECT_VERSION=$(CONNECT_VERSION) \
docker compose -f inst/ci/test-connect-lic.yml -f .github/local/make-network.yml up -d

connect-file-down:
Expand All @@ -69,7 +69,7 @@ connect-file-down:
test-env-up:
NETWORK=${NETWORK} \
RSC_LICENSE=$(RSC_LICENSE) \
RSC_VERSION=$(RSC_VERSION) \
CONNECT_VERSION=$(CONNECT_VERSION) \
docker compose -f .github/local/test-connect-ci.yml -f .github/local/make-network.yml up -d

test-env-down:
Expand Down
6 changes: 4 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# connectapi (development version)

- The package is now tested against many versions of Connect, back to 1.8.8.2 (May 2021).
There are now fewer warnings about version mismatches: you should only see a warning if your Connect server is older than that. (#244)
- Now correctly provides methods for `tbl_connect`, rather than `tbl_lazy`,
preventing problems when also using dplyr (#177).
- BREAKING: The functions `Connect$download_bundle()` and
Expand Down Expand Up @@ -126,7 +128,7 @@

# connectapi 0.1.0.9017

BREAKING:
BREAKING:
* Switch from `RSTUDIO_CONNECT_*` variables to `CONNECT_*` variables
* Rename a handful of functions:
- `connect$activate_bundle` to `connect$content_deploy`
Expand All @@ -144,7 +146,7 @@ BREAKING:
- `cache_apps`
- `tag_page`

OTHER:
OTHER:
* Add some endpoints:
- `content`
- `audit_logs`
Expand Down
4 changes: 2 additions & 2 deletions R/acl.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#' Get ACL Details
#'
#' \lifecycle{deprecated} Retrieve the Access Controls associated with a given
#' piece of content. Deprecated in favor of [content_add_user()] or [permissions].

Check warning on line 6 in R/acl.R

View workflow job for this annotation

GitHub Actions / lint

file=R/acl.R,line=6,col=81,[line_length_linter] Lines should not be more than 80 characters. This line is 82 characters.
#'
#' NOTE: ACLs can still be stored, even when access_type for content is "all" or
#' "logged_in" users. In these cases, granting or removing "viewer" privileges
Expand Down Expand Up @@ -31,11 +31,11 @@
#' @rdname get_acl
get_acl_user <- function(content) {
warn_experimental("get_acl")
lifecycle::deprecate_warn("0.1.0.9027", "get_acl_user()", "get_content_permissions()")

Check warning on line 34 in R/acl.R

View workflow job for this annotation

GitHub Actions / lint

file=R/acl.R,line=34,col=81,[line_length_linter] Lines should not be more than 80 characters. This line is 88 characters.

content_info <- content$get_content_remote()
prep <- get_acl_user_impl(content)
out <- parse_connectapi_typed(prep, !!!connectapi_ptypes$acl_user)
out <- parse_connectapi_typed(prep, connectapi_ptypes$acl_user)
out$content_guid <- content_info$guid
out$content_access_type <- content_info$access_type

Expand All @@ -46,11 +46,11 @@
#' @export
get_acl_group <- function(content) {
warn_experimental("get_acl")
lifecycle::deprecate_warn("0.1.0.9027", "get_acl_group()", "get_content_permissions()")

Check warning on line 49 in R/acl.R

View workflow job for this annotation

GitHub Actions / lint

file=R/acl.R,line=49,col=81,[line_length_linter] Lines should not be more than 80 characters. This line is 89 characters.

content_info <- content$get_content_remote()
prep <- get_acl_group_impl(content)
out <- parse_connectapi_typed(prep, !!!connectapi_ptypes$acl_group)
out <- parse_connectapi_typed(prep, connectapi_ptypes$acl_group)
if (nrow(out) > 0) {
out$content_guid <- content_info$guid
out$content_access_type <- content_info$access_type
Expand All @@ -62,7 +62,7 @@
#' @rdname get_acl
#' @export
get_acl <- function(content) {
lifecycle::deprecate_warn("0.1.0.9027", "get_acl()", "get_content_permissions()")

Check warning on line 65 in R/acl.R

View workflow job for this annotation

GitHub Actions / lint

file=R/acl.R,line=65,col=81,[line_length_linter] Lines should not be more than 80 characters. This line is 83 characters.
get_acl_user(content)
}

Expand Down Expand Up @@ -120,7 +120,7 @@
#' @export
get_acl_user_role <- function(content, user_guid) {
warn_experimental("acl_user_role")
lifecycle::deprecate_warn("0.1.0.9027", "get_acl_user_role()", "get_user_permission()")

Check warning on line 123 in R/acl.R

View workflow job for this annotation

GitHub Actions / lint

file=R/acl.R,line=123,col=81,[line_length_linter] Lines should not be more than 80 characters. This line is 89 characters.
scoped_experimental_silence()
acls <- get_acl_user_impl(content)
if (is.null(user_guid) || is.na(user_guid)) {
Expand All @@ -136,7 +136,7 @@
#' @export
get_acl_group_role <- function(content, group_guid) {
warn_experimental("acl_group_role")
lifecycle::deprecate_warn("0.1.0.9027", "get_acl_user_role()", "get_group_permission()")

Check warning on line 139 in R/acl.R

View workflow job for this annotation

GitHub Actions / lint

file=R/acl.R,line=139,col=81,[line_length_linter] Lines should not be more than 80 characters. This line is 90 characters.
scoped_experimental_silence()
acls <- get_acl_group_impl(content)
if (is.null(group_guid) || is.na(group_guid)) {
Expand All @@ -162,7 +162,7 @@
#' - `acl_remove_user()` removes a user's ACLs from a piece of content
#' - `acl_remove_group()` removes a group's ACLs from a piece of content
#'
#' - `acl_add_self()` is useful for admins and adds the current user as a collaborator

Check warning on line 165 in R/acl.R

View workflow job for this annotation

GitHub Actions / lint

file=R/acl.R,line=165,col=81,[line_length_linter] Lines should not be more than 80 characters. This line is 86 characters.
#' - `acl_remove_self()` removes the current user's ACLs from a piece of content
#'
#' @param content The R6 Content object (as returned by `content_item()`)
Expand All @@ -177,9 +177,9 @@
#' @export
acl_add_user <- function(content, user_guid, role) {
warn_experimental("acl_add")
lifecycle::deprecate_warn("0.1.0.9027", "acl_add_user()", "content_add_user()")

Check warning on line 180 in R/acl.R

View workflow job for this annotation

GitHub Actions / lint

file=R/acl.R,line=180,col=81,[line_length_linter] Lines should not be more than 80 characters. This line is 81 characters.
stopifnot(role %in% c("owner", "viewer"))
res <- content$get_connect()$POST(

Check warning on line 182 in R/acl.R

View workflow job for this annotation

GitHub Actions / lint

file=R/acl.R,line=182,col=3,[object_usage_linter] local variable 'res' assigned but may not be used
glue::glue("applications/{content$get_content()$guid}/users"),
body = list(
app_role = role,
Expand All @@ -193,7 +193,7 @@
#' @export
acl_add_group <- function(content, group_guid, role) {
warn_experimental("acl_add")
lifecycle::deprecate_warn("0.1.0.9027", "acl_add_group()", "content_add_group()")

Check warning on line 196 in R/acl.R

View workflow job for this annotation

GitHub Actions / lint

file=R/acl.R,line=196,col=81,[line_length_linter] Lines should not be more than 80 characters. This line is 83 characters.
stopifnot(role %in% c("owner", "viewer"))
res <- content$get_connect()$POST(
glue::glue("applications/{content$get_content()$guid}/groups"),
Expand Down
6 changes: 1 addition & 5 deletions R/connect.R
Original file line number Diff line number Diff line change
Expand Up @@ -1004,11 +1004,7 @@ connect <- function(
tryCatch(
{
check_connect_license(con)

# check Connect is accessible
srv <- safe_server_settings(con)

check_connect_version(using_version = srv$version)
check_connect_version(using_version = safe_server_version(con))
},
error = function(err) {
if (.check_is_fatal) {
Expand Down
2 changes: 1 addition & 1 deletion R/connectapi.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ utils::globalVariables(
)
)

current_connect_version <- "2022.09.0"
current_connect_version <- "2024.03.0"
8 changes: 4 additions & 4 deletions R/content.R
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,7 @@ get_jobs <- function(content) {
validate_R6_class(content, "Content")

jobs <- content$jobs()
parse_connectapi_typed(jobs, !!!connectapi_ptypes$jobs)
parse_connectapi_typed(jobs, connectapi_ptypes$jobs)
}

# TODO: Need to test `logged_error` on a real error
Expand All @@ -602,7 +602,7 @@ get_job <- function(content, key) {
job$stderr <- strsplit(job$stderr, "\n")[[1]]
# a bit of an abuse
# since stdout / stderr / logged_error are here now...
parse_connectapi_typed(list(job), !!!connectapi_ptypes$job)
parse_connectapi_typed(list(job), connectapi_ptypes$job)
}

#' Set RunAs User
Expand Down Expand Up @@ -779,7 +779,7 @@ get_bundles <- function(content, limit = Inf) {
validate_R6_class(content, "Content")
bundles <- content$get_bundles()

parse_connectapi_typed(bundles, !!!connectapi_ptypes$bundles)
parse_connectapi_typed(bundles, connectapi_ptypes$bundles)
}

#' @rdname get_bundles
Expand Down Expand Up @@ -951,5 +951,5 @@ get_group_permission <- function(content, guid) {
get_content_permissions <- function(content, add_owner = TRUE) {
validate_R6_class(content, "Content")
res <- content$permissions(add_owner = add_owner)
parse_connectapi_typed(res, !!!connectapi_ptypes$permissions)
parse_connectapi_typed(res, connectapi_ptypes$permissions)
}
18 changes: 9 additions & 9 deletions R/get.R
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ get_users <- function(src, page_size = 20, prefix = NULL, limit = 25) {
limit = limit
)

out <- parse_connectapi_typed(res, !!!connectapi_ptypes$users)
out <- parse_connectapi_typed(res, connectapi_ptypes$users)

return(out)
}
Expand Down Expand Up @@ -88,7 +88,7 @@ get_groups <- function(src, page_size = 20, prefix = NULL, limit = 25) {

res <- page_offset(src, src$groups(page_size = page_size, prefix = prefix), limit = limit)

out <- parse_connectapi_typed(res, !!!connectapi_ptypes$groups)
out <- parse_connectapi_typed(res, connectapi_ptypes$groups)

return(out)
}
Expand Down Expand Up @@ -280,7 +280,7 @@ get_content <- function(src, guid = NULL, owner_guid = NULL, name = NULL, ..., .
res <- res %>% purrr::keep(.p = .p)
}

out <- parse_connectapi_typed(res, !!!connectapi_ptypes$content)
out <- parse_connectapi_typed(res, connectapi_ptypes$content)

return(out)
}
Expand Down Expand Up @@ -359,7 +359,7 @@ content_list_by_tag <- function(src, tag) {

res <- src$GET(glue::glue("v1/tags/{tag_id}/content"))

out <- parse_connectapi_typed(res, !!!connectapi_ptypes$content)
out <- parse_connectapi_typed(res, connectapi_ptypes$content)
return(out)
}

Expand Down Expand Up @@ -516,7 +516,7 @@ get_content_old <- function(src, filter = NULL, limit = 25, page_size = 25) {
page_size = page_size
)

out <- parse_connectapi_typed(res, !!!connectapi_ptypes$content_old)
out <- parse_connectapi_typed(res, connectapi_ptypes$content_old)

return(out)
}
Expand Down Expand Up @@ -602,7 +602,7 @@ get_usage_shiny <- function(src, content_guid = NULL,

res <- page_cursor(src, res, limit = limit)

out <- parse_connectapi_typed(res, !!!connectapi_ptypes$usage_shiny)
out <- parse_connectapi_typed(res, connectapi_ptypes$usage_shiny)

return(out)
}
Expand Down Expand Up @@ -695,7 +695,7 @@ get_usage_static <- function(src, content_guid = NULL,

res <- page_cursor(src, res, limit = limit)

out <- parse_connectapi_typed(res, !!!connectapi_ptypes$usage_static)
out <- parse_connectapi_typed(res, connectapi_ptypes$usage_static)

return(out)
}
Expand Down Expand Up @@ -754,7 +754,7 @@ get_audit_logs <- function(src, limit = 20L, previous = NULL,

res <- page_cursor(src, res, limit = limit)

out <- parse_connectapi_typed(res, !!!connectapi_ptypes$audit_logs)
out <- parse_connectapi_typed(res, connectapi_ptypes$audit_logs)

return(out)
}
Expand Down Expand Up @@ -796,7 +796,7 @@ get_procs <- function(src) {
c(list(pid = y), x)
}
)
tbl_data <- parse_connectapi_typed(proc_prep, !!!connectapi_ptypes$procs)
tbl_data <- parse_connectapi_typed(proc_prep, connectapi_ptypes$procs)

return(tbl_data)
}
2 changes: 1 addition & 1 deletion R/lazy.R
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ api_build.op_base_connect <- function(op, con, ..., n) {
} else {
stop(glue::glue("'{op$x}' is not recognized"))
}
parse_connectapi_typed(res, !!!op$ptype)
parse_connectapi_typed(res, op$ptype)
}

cat_line <- function(...) {
Expand Down
16 changes: 9 additions & 7 deletions R/parse.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@ swap_timestamp_format <- function(.col) {
}
}

ensure_columns <- function(.data, ...) {
defaults <- rlang::list2(...)
names <- names(defaults)
for (i in seq_along(defaults)) {
.data <- ensure_column(.data, defaults[[i]], names[[i]])
ensure_columns <- function(.data, ptype) {
# Given a prototype, ensure that all columns are present and cast to the correct type.
# If a column is missing in .data, it will be created with all missing values of the correct type.
# If a column is present in both, it will be cast to the correct type.
# If a column is present in .data but not in ptype, it will be left as is.
for (i in names(ptype)) {
.data <- ensure_column(.data, ptype[[i]], i)
}
.data
}
Expand Down Expand Up @@ -66,8 +68,8 @@ ensure_column <- function(data, default, name) {
data
}

parse_connectapi_typed <- function(data, ...) {
ensure_columns(parse_connectapi(data), ...)
parse_connectapi_typed <- function(data, ptype) {
ensure_columns(parse_connectapi(data), ptype)
}

parse_connectapi <- function(data) {
Expand Down
29 changes: 25 additions & 4 deletions R/utils-ci.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,27 @@ determine_license_env <- function(license) {
}
}

compose_start <- function(connect_license = Sys.getenv("RSC_LICENSE"), rsc_version, clean = TRUE) {
version_to_docker_tag <- function(version) {
# Prior to 2022.09.0, the plain version number was the tag
# After, it's "<ubuntu-codename>-<version>"
# If you want a specific image tag, just pass it in and it will go through unchanged
try(
{
numver <- numeric_version(version)
if (numver > "2023.06") {
version <- paste0("jammy-", version)
} else if (numver >= "2022.09") {
# There's both jammy and bionic for these, but the bionic ones
# seem more reliable in CI
version <- paste0("bionic-", version)
}
},
silent = TRUE
)
version
}

Comment on lines +28 to +47
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At first I thought this might be over-complicated, but it's good, and we will soon have noble- to deal with too.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is really just sugar; if you know the image tag you can just specify it (now, that is, bionic was hard-coded before). This just prevents us from having to remember whether it's bionic or jammy or whatever else.

compose_start <- function(connect_license = Sys.getenv("RSC_LICENSE"), connect_version, clean = TRUE) {
warn_dire("compose_start")
scoped_dire_silence()

Expand All @@ -39,7 +59,7 @@ compose_start <- function(connect_license = Sys.getenv("RSC_LICENSE"), rsc_versi

compose_file_path <- system.file(compose_file, package = "connectapi")
env_vars <- c(
RSC_VERSION = rsc_version,
CONNECT_VERSION = version_to_docker_tag(connect_version),
PATH = Sys.getenv("PATH"),
license_details$env_params
)
Expand Down Expand Up @@ -106,11 +126,12 @@ update_renviron_creds <- function(server, api_key, prefix, .file = ".Renviron")
build_test_env <- function(connect_license = Sys.getenv("RSC_LICENSE"),
clean = TRUE,
username = "admin",
password = "admin0", rsc_version = current_connect_version) {
password = "admin0",
connect_version = Sys.getenv("CONNECT_VERSION", current_connect_version)) {
warn_dire("build_test_env")
scoped_dire_silence()

compose_start(connect_license = connect_license, clean = clean, rsc_version = rsc_version)
compose_start(connect_license = connect_license, clean = clean, connect_version = connect_version)

# It was ci_connect before but it's ci-connect on my machine now;
# this is a regex so it will match either
Expand Down
Loading