Skip to content

Commit

Permalink
Bump default version to 2024.03.0; don't warn about version mismatch …
Browse files Browse the repository at this point in the history
…unless older than the oldest we now test
  • Loading branch information
nealrichardson committed Apr 18, 2024
1 parent 1b64c27 commit f3e6ebf
Show file tree
Hide file tree
Showing 12 changed files with 60 additions and 122 deletions.
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 }}
CONNECT_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 }}
CONNECT_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 }}
CONNECT_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
4 changes: 2 additions & 2 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
CONNECT_VERSION=2022.09.0
CONNECT_VERSION=2024.03.0

#---------------------------------------------
# Network
Expand Down Expand Up @@ -32,7 +32,7 @@ network-down:
update-versions:
@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/integration-tests.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

#---------------------------------------------
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"
60 changes: 25 additions & 35 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,6 @@ warn_once <- function(msg, id = msg) {
}
warn_env <- new.env(parent = emptyenv())

tested_connect_version <- function() {
current_connect_version
}

check_connect_license <- function(url) {
if (is_R6_class(url, "Connect")) {
res <- url$GET_RESULT_URL(url$server)
Expand Down Expand Up @@ -177,48 +173,42 @@ safe_server_settings <- function(client) {
}

safe_server_version <- function(client) {
srv <- safe_server_settings(client)
return(srv$version)
version <- safe_server_settings(client)$version
if (is.null(version) || nchar(version) == 0) {
message("Version information is not exposed by this Posit Connect instance.")
# Return 0 so this will always show up as "too old"
version <- "0"
}
version
}

# TODO: switch compare_connect_version ordering...
error_if_less_than <- function(client, tested_version) {
comp <- compare_connect_version(using_version = safe_server_version(client), tested_version = tested_version)
if (comp > 0) {
stop(glue::glue("ERROR: This API requires Posit Connect version {tested_version}, but you are using {srv$version}. Please use a previous version of the `connectapi` package, upgrade Posit Connect, or review the API documentation corresponding to your version."))
server_version <- safe_server_version(client)
comp <- compare_connect_version(server_version, tested_version)
if (comp < 0) {
msg <- paste0(
"ERROR: This API requires Posit Connect version ", tested_version,
" but you are using", server_version, ". Please use a previous version",
" of the `connectapi` package, upgrade Posit Connect, or review the API ",
"documentation corresponding to your version."
)
stop(msg)
}
invisible()
}

compare_connect_version <- function(using_version, tested_version) {
if (is.null(using_version)) {
message("Version information is not exposed by this Posit Connect instance.")
return(0)
} else if (nchar(using_version) == 0) {
message("Version information is not exposed by this Posit Connect instance.")
return(0)
} else {
minor_using_version <- simplify_version(using_version)
minor_tested_version <- simplify_version(tested_version)
return(compareVersion(minor_tested_version, minor_using_version))
}
compareVersion(simplify_version(using_version), simplify_version(tested_version))
}

check_connect_version <- function(using_version, tested_version = tested_connect_version()) {
comp <- compare_connect_version(using_version = using_version, tested_version = tested_version)

msg <- switch(as.character(comp),
"0" = NULL,
"1" = warn_once(glue::glue(
check_connect_version <- function(using_version, minimum_tested_version = "1.8.8.2") {
comp <- compare_connect_version(using_version, minimum_tested_version)
if (comp < 0) {
warn_once(glue::glue(
"You are using an older version of Posit Connect ",
"({using_version}) than was tested ({tested_version}). ",
"({using_version}) than is tested ({minimum_tested_version}). ",
"Some APIs may not function as expected."
), id = "old-connect"),
"-1" = warn_once(glue::glue(
"You are using a newer version of Posit Connect ",
"({using_version}) than was tested ({tested_version}). ",
"Most APIs should function as expected."
), id = "new-connect")
)
), id = "old-connect")
}
invisible()
}
36 changes: 7 additions & 29 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -23,29 +23,9 @@ knitr::opts_chunk$set(
# connectapi <img src='man/figures/logo.svg' align="right" height="139" />

This package provides an R client for the [Posit Connect Server
API](https://docs.posit.co/connect/api/) as well as helpful functions that
utilize the client. The package is based on the `rsconnect`
[package](https://rstudio.github.io/rsconnect/), but is publicly exported to be
easier to use, is extensible via an R6 class, and is separated from the
`rsconnect` package for easier support and maintenance.

## Disclaimer

Because many of these functions are experimental, it is advisable to be cautious
about (1) upgrading the package, (2) upgrading Posit Connect when you care
about the reproducibility of workflows that use `connectapi`. As a result, we
would advise:

- managing package versions with [`renv`](https://rstudio.github.io/renv/)
- test your dependent content before and after upgrading Posit Connect

Please pay careful attention to the lifecycle badges of the various functions
and warnings present when you are using experimental features.

**Also, [please share
feedback!!](https://community.rstudio.com/c/r-admin/posit-connect/27) We love
hearing how the Posit Connect Server API is helpful and what additional
endpoints would be useful!!**
API](https://docs.posit.co/connect/api/), as well as helpful functions that
utilize the client.
It is designed to work with all supported versions of Connect, though some features may only be available to newer versions.

## Installation

Expand Down Expand Up @@ -183,12 +163,10 @@ This is likely due to either (1) `Connect$server` or `Connect$api_key` being
defined improperly or (2) you do not have access to the Posit Connect cluster
to do the operation in question

**Constant warning about version numbers**
**Warning about version numbers**

This warning is intentionally chatty. While version number mismatches between
Posit Connect and `connectapi` can be benign, we want you to be clear that
`connectapi` is tightly coupled to a version of Posit Connect (because Posit
Connect's APIs change over time).
We test the package against a range of versions of Connect, as old as 1.8.8.2 (May 2021).
If your Connect server is older than that, the package may still work, but `connectapi` will warn you.

We strive to:

Expand Down Expand Up @@ -221,7 +199,7 @@ Community](https://community.rstudio.com/c/r-admin/posit-connect/27)

**Other ideas for FAQs or Common Issues?**

Please submit a PR! We would love to have your contribution!
Please open an issue or PR! We would love to have your contribution!

## Code of Conduct

Expand Down
44 changes: 11 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,10 @@ status](https://github.com/rstudio/connectapi/workflows/R-CMD-check/badge.svg)](
# connectapi <img src='man/figures/logo.svg' align="right" height="139" />

This package provides an R client for the [Posit Connect Server
API](https://docs.posit.co/connect/api/) as well as helpful functions
that utilize the client. The package is based on the `rsconnnect`
[package](https://rstudio.github.io/rsconnect/), but is publicly
exported to be easier to use, is extensible via an R6 class, and is
separated from the `rsconnect` package for easier support and
maintenance.

## Disclaimer

Because many of these functions are experimental, it is advisable to be
cautious about (1) upgrading the package, (2) upgrading Posit Connect
when you care about the reproducibility of workflows that use
`connectapi`. As a result, we would advise:

- managing package versions with
[`renv`](https://rstudio.github.io/renv/)
- test your dependent content before and after upgrading Posit Connect

Please pay careful attention to the lifecycle badges of the various
functions and warnings present when you are using experimental features.

**Also, [please share
feedback!!](https://community.rstudio.com/c/r-admin/posit-connect/27) We
love hearing how the Posit Connect Server API is helpful and what
additional endpoints would be useful!!**
API](https://docs.posit.co/connect/api/), as well as helpful functions
that utilize the client. It is designed to work with all supported
versions of Connect, though some features may only be available to newer
versions.

## Installation

Expand All @@ -62,8 +41,8 @@ To create a client:
``` r
library(connectapi)
client <- connect(
server = 'https://connect.example.com',
api_key = '<SUPER SECRET API KEY>'
server = "https://connect.example.com",
api_key = "<SUPER SECRET API KEY>"
)
```

Expand Down Expand Up @@ -179,12 +158,11 @@ This is likely due to either (1) `Connect$server` or `Connect$api_key`
being defined improperly or (2) you do not have access to the Posit
Connect cluster to do the operation in question

**Constant warning about version numbers**
**Warning about version numbers**

This warning is intentionally chatty. While version number mismatches
between Posit Connect and `connectapi` can be benign, we want you to be
clear that `connectapi` is tightly coupled to a version of Posit Connect
(because Posit Connect's APIs changes over time).
We test the package against a range of versions of Connect, as old as
1.8.8.2 (May 2021). If your Connect server is older than that, the
package may still work, but `connectapi` will warn you.

We strive to:

Expand Down Expand Up @@ -224,7 +202,7 @@ Community](https://community.rstudio.com/c/r-admin/posit-connect/27)

**Other ideas for FAQs or Common Issues?**

Please submit a PR! We would love to have your contribution!
Please open an issue or PR! We would love to have your contribution!

## Code of Conduct

Expand Down
6 changes: 1 addition & 5 deletions tests/integrated/helper.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@ expect_ptype_equal <- function(actual, expected, exact = TRUE) {
}

skip_if_connect_older_than <- function(client, version) {
connect_version <- safe_server_version(client)
if (is.null(connect_version) || nchar(connect_version) == 0) {
connect_version <- "0"
}
if (numeric_version(connect_version) < numeric_version(version)) {
if (numeric_version(safe_server_version(client)) < numeric_version(version)) {
skip(paste("Requires Connect >=", version))
}
}
5 changes: 2 additions & 3 deletions tests/testthat/_snaps/utils.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@
Code
capture_warning(check_connect_version("2022.02", "2022.01"))
Output
<warning: You are using a newer version of Posit Connect (2022.02) than was tested (2022.01). Most APIs should function as expected.
This warning is displayed once per session.>
NULL

---

Code
capture_warning(check_connect_version("2022.01", "2022.02"))
Output
<warning: You are using an older version of Posit Connect (2022.01) than was tested (2022.02). Some APIs may not function as expected.
<warning: You are using an older version of Posit Connect (2022.01) than is tested (2022.02). Some APIs may not function as expected.
This warning is displayed once per session.>

13 changes: 7 additions & 6 deletions tests/testthat/test-utils.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
context("utils")

test_that("safequery handles values correctly", {
test_that("safe_query handles values correctly", {
pref <- "prefixed"
nullval <- NULL
expect_identical(safe_query(nullval, pref), "")
Expand Down Expand Up @@ -38,21 +38,22 @@ test_that("error_if_less_than errors as expected", {

test_that("check_connect_version works", {
# silent for patch version changes
expect_silent(check_connect_version("1.8.2-4", "1.8.2.1-10"))
expect_silent(check_connect_version("1.8.2.1-10", "1.8.2-4"))

# silent if newer
expect_silent(check_connect_version("1.8.2-4", "1.8.0.5-1"))

# warnings for minor version changes
expect_warning(check_connect_version("1.8.2-4", "1.8.0.5-1"), "newer")
warn_clear("new-connect")
expect_warning(check_connect_version("1.8.2-4", "2.8.0.5-1"), "older")
warn_clear("old-connect")
})

test_that("check_connect_version warning snapshot", {
# warning messages seem to cause issues in different environments based on color codes
testthat::skip_on_cran()
skip_on_cran()
local_edition(3)
# No warning
expect_snapshot(capture_warning(check_connect_version("2022.02", "2022.01")))
warn_clear("new-connect")
expect_snapshot(capture_warning(check_connect_version("2022.01", "2022.02")))
warn_clear("old-connect")
})

0 comments on commit f3e6ebf

Please sign in to comment.