diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index bc9f80d..317e5cc 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -10,6 +10,11 @@ # Triggers: # - workflow_dispatch : manually, with configurable GDAL version + force flag # - push to tag : gdal-v* (e.g. git tag gdal-v3.13.1) +# - schedule : weekly upstream check only — compares the latest +# OSGeo/gdal release against our newest published +# gdal-v* bundle and opens a tracking issue when a +# newer GDAL exists. Never builds or publishes on its +# own; a human dispatches the build after review. # # Artefact strategy (every run produces durable output): # Workflow artifact : upload-artifact@v5 retention=30d no compression @@ -32,6 +37,8 @@ on: gdal_version: description: 'GDAL git tag to build (e.g. v3.13.1)' required: true + # current bundle baseline — keep in sync with env.GDAL_VERSION below + # and the "Latest GDAL runtime release" line in README.md default: 'v3.13.1' force_rebuild_gdal: description: 'Force full GDAL rebuild, ignoring cache' @@ -50,21 +57,86 @@ on: tags: - 'gdal-v*' # e.g. gdal-v3.13.1 + schedule: + - cron: '0 6 * * 1' # Mondays 06:00 UTC — upstream release check only + # Required by softprops/action-gh-release to create releases and upload assets. -# Using minimum required scope — contents:write only. +# Using minimum required scope — contents:write only (the scheduled upstream +# check job narrows/extends its own permissions at job level). permissions: contents: write # Centralise defaults for manual runs. +# keep the fallback in sync with the gdal_version input default above env: GDAL_VERSION: ${{ github.event.inputs.gdal_version || 'v3.13.1' }} # ───────────────────────────────────────────────────────────────────────────── -# JOB 1 — Build GDAL from source +# JOB 0 — Scheduled upstream release check (schedule trigger only) # ───────────────────────────────────────────────────────────────────────────── jobs: + check-upstream: + name: "Check upstream GDAL release" + if: github.event_name == 'schedule' + runs-on: ubuntu-latest + permissions: + contents: read + issues: write + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + steps: + - name: Compare upstream GDAL release with newest published bundle + run: | + set -euo pipefail + + upstream_tag=$(gh api repos/OSGeo/gdal/releases/latest --jq '.tag_name') + ours_tag=$(gh api "repos/${GITHUB_REPOSITORY}/releases?per_page=100" \ + --jq '[.[] | select(.draft == false and .prerelease == false) | .tag_name | select(startswith("gdal-v"))][0] // empty') + ours_version="${ours_tag#gdal-}" + + echo "upstream: ${upstream_tag}" + echo "ours: ${ours_version:-} (${ours_tag:-no gdal-v* release})" + + # sort -V puts the newest version last; equal versions mean up to date + newest=$(printf '%s\n%s\n' "${upstream_tag}" "${ours_version:-v0.0.0}" | sort -V | tail -n 1) + if [ "${newest}" = "${ours_version}" ] || [ "${upstream_tag}" = "${ours_version}" ]; then + echo "Bundle is up to date with upstream GDAL." + exit 0 + fi + + issue_title="upstream: GDAL ${upstream_tag} released — build new runtime bundle" + existing=$(gh issue list --repo "${GITHUB_REPOSITORY}" --state open \ + --search "\"${issue_title}\" in:title" --json number --jq 'length') + if [ "${existing}" -gt 0 ]; then + echo "Tracking issue already open; nothing to do." + exit 0 + fi + + gh issue create --repo "${GITHUB_REPOSITORY}" \ + --title "${issue_title}" \ + --label upstream,build \ + --body "$(printf '%s\n' \ + "The scheduled upstream check found a newer GDAL release." \ + "" \ + "- Upstream: [\`${upstream_tag}\`](https://github.com/OSGeo/gdal/releases/tag/${upstream_tag})" \ + "- Newest published bundle: \`${ours_tag:-none}\`" \ + "" \ + "To build and publish a new runtime bundle after reviewing upstream release notes:" \ + "" \ + '```bash' \ + "git tag gdal-${upstream_tag} && git push origin gdal-${upstream_tag}" \ + '```' \ + "" \ + "or dispatch the Build GDAL (Windows) workflow with \`gdal_version=${upstream_tag}\`." \ + "" \ + "After publishing, rebuild gdalraster against the new bundle and verify with \`gdalraster.windows::verify_gdalraster_runtime()\`, then update the README latest-release line and the default \`gdal_version\` in build.yml.")" + +# ───────────────────────────────────────────────────────────────────────────── +# JOB 1 — Build GDAL from source +# ───────────────────────────────────────────────────────────────────────────── build-gdal: name: "Build GDAL" + if: github.event_name != 'schedule' runs-on: windows-latest outputs: diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml new file mode 100644 index 0000000..811a2cb --- /dev/null +++ b/.github/workflows/e2e.yml @@ -0,0 +1,131 @@ +# ============================================================================= +# e2e.yml — End-to-end verification of the full user workflow on a clean +# Windows machine (#20). +# +# Proves the documented workflow exactly as a user machine would run it: +# 1. install the package (local checkout) +# 2. install_gdal_runtime() — published GDAL runtime bundle +# 3. install_gdalraster() — source build against the bundle +# 4. verify_gdalraster_runtime() — Algorithm API registry is populated +# 5. add_gdal_rprofile_hook() — startup hook, verified in a fresh +# R session via plain library(gdalraster) +# +# This workflow only consumes exported package functionality — build, link, +# and activation logic are never reimplemented in CI (see AGENTS.md +# responsibility split). gdalraster's own R dependencies are installed as +# CRAN binaries so the only from-source compile is gdalraster itself. +# +# Triggers: +# - workflow_dispatch : manually, optionally pinning a runtime release tag +# - schedule : weekly (Mondays 08:00 UTC, after the upstream check) +# - release published : gdal-v* bundle releases, so every new bundle is +# proven against gdalraster automatically +# ============================================================================= + +name: E2E Runtime Verification + +on: + workflow_dispatch: + inputs: + runtime_tag: + description: 'GDAL runtime release tag to install (or "latest")' + required: false + default: 'latest' + schedule: + - cron: '0 8 * * 1' + release: + types: [published] + +permissions: read-all + +jobs: + e2e: + name: "E2E: runtime + gdalraster + hook" + # release trigger fires for package releases (v*) too; only bundle + # releases are relevant here + if: github.event_name != 'release' || startsWith(github.event.release.tag_name, 'gdal-v') + runs-on: windows-latest + timeout-minutes: 90 + env: + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + RUNTIME_TAG: ${{ github.event_name == 'release' && github.event.release.tag_name || github.event.inputs.runtime_tag || 'latest' }} + steps: + - uses: actions/checkout@v6 + + - uses: r-lib/actions/setup-r@v2 + with: + r-version: 'release' + use-public-rspm: true + + # installs gdalraster.windows (local checkout) plus its dependencies + - uses: r-lib/actions/setup-r-dependencies@v2 + with: + extra-packages: any::pak, local::. + + - name: Install GDAL runtime bundle + shell: Rscript {0} + run: | + tag <- Sys.getenv("RUNTIME_TAG", unset = "latest") + if (!nzchar(tag)) tag <- "latest" + gdalraster.windows::install_gdal_runtime(tag = tag) + + - name: Install gdalraster R dependencies (CRAN binaries) + shell: Rscript {0} + run: | + src <- file.path(tempdir(), "gdalraster-src.tar.gz") + utils::download.file( + "https://codeload.github.com/firelab/gdalraster/tar.gz/HEAD", + destfile = src, mode = "wb", quiet = TRUE + ) + exdir <- file.path(tempdir(), "gdalraster-src") + utils::untar(src, exdir = exdir) + pkg_dir <- list.dirs(exdir, recursive = FALSE)[[1]] + pak::local_install_deps(pkg_dir) + + - name: Build gdalraster from source against the bundle + shell: Rscript {0} + run: | + gdalraster.windows::install_gdalraster() + + - name: Verify algorithm API (explicit load) + shell: Rscript {0} + run: | + ok <- gdalraster.windows::verify_gdalraster_runtime() + stopifnot(isTRUE(ok)) + + - name: Verify algorithm API (startup hook, fresh session) + shell: Rscript {0} + run: | + rprofile <- file.path(getwd(), "e2e-hook.Rprofile") + gdalraster.windows::add_gdal_rprofile_hook(rprofile = rprofile) + + script <- file.path(getwd(), "e2e-hook-check.R") + writeLines( + c( + "library(gdalraster)", + "n <- length(gdalraster::gdal_global_reg_names())", + "cat('algorithm registry entries:', n, '\n')", + "stopifnot(n > 0L)" + ), + con = script + ) + + status <- withr::with_envvar( + c(R_PROFILE_USER = rprofile), + system2(file.path(R.home("bin"), "Rscript.exe"), args = script) + ) + stopifnot(identical(status, 0L)) + + - name: Write summary + if: always() + shell: pwsh + run: | + @" + ## E2E runtime verification + + | Item | Value | + |------|-------| + | Runtime tag | ``$env:RUNTIME_TAG`` | + | Trigger | ``${{ github.event_name }}`` | + | Result | ${{ job.status }} | + "@ | Out-File -Append -Encoding utf8 $env:GITHUB_STEP_SUMMARY diff --git a/AGENTS.md b/AGENTS.md index 4d469d6..e7adf39 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -54,12 +54,20 @@ gdalraster::gdal_global_reg_names() ## responsibility split -- CI's only responsibility is the GDAL runtime bundle: build, verify the - bundle contract, and publish durable artifacts (workflow artifact + release - asset). +- The build workflow's only responsibility is the GDAL runtime bundle: build, + verify the bundle contract, and publish durable artifacts (workflow artifact + + release asset). A scheduled job in the same workflow checks upstream OSGeo/gdal + releases and opens a tracking issue when a newer GDAL exists (never builds + or publishes on its own). - Building `gdalraster` against the bundle is package functionality (`install_gdalraster()` with scoped Makevars via `withr`), exercised on user machines and by package tests — never reimplemented inside CI. +- The e2e workflow ([`.github/workflows/e2e.yml`](.github/workflows/e2e.yml)) + proves the full user workflow on a clean Windows runner by consuming the + exported package functions (`install_gdal_runtime()`, + `install_gdalraster()`, `verify_gdalraster_runtime()`, + `add_gdal_rprofile_hook()`) exactly as a user machine would; it runs on + dispatch, weekly, and whenever a `gdal-v*` bundle release is published. ## source of truth diff --git a/DESCRIPTION b/DESCRIPTION index 5f1e113..5f53b41 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: gdalraster.windows Title: Windows GDAL Runtime and gdalraster Bootstrap Tools -Version: 0.3.0 +Version: 0.3.0.9000 Authors@R: person("Jimmy", "Briggs", , "jimmy.briggs@jimbrig.com", role = c("aut", "cre"), comment = c(ORCID = "0000-0002-7489-8787")) @@ -13,6 +13,7 @@ URL: https://github.com/jimbrig/gdalraster.windows, BugReports: https://github.com/jimbrig/gdalraster.windows/issues Imports: cli, + gitcreds, httr2, rlang, stats, diff --git a/NAMESPACE b/NAMESPACE index 9f365b7..7bcc501 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -13,9 +13,22 @@ export(verify_gdalraster_runtime) importFrom(cli,cli_alert_info) importFrom(cli,cli_alert_warning) importFrom(cli,cli_inform) +importFrom(gitcreds,gitcreds_get) +importFrom(httr2,req_auth_bearer_token) +importFrom(httr2,req_error) +importFrom(httr2,req_perform) +importFrom(httr2,req_user_agent) +importFrom(httr2,request) +importFrom(httr2,resp_body_json) +importFrom(httr2,resp_body_raw) +importFrom(httr2,resp_status) +importFrom(rlang,"%||%") importFrom(rlang,local_use_cli) importFrom(rlang,new_environment) importFrom(rlang,on_load) importFrom(rlang,run_on_load) +importFrom(rlang,try_fetch) importFrom(stats,setNames) importFrom(utils,packageVersion) +importFrom(withr,with_envvar) +importFrom(withr,with_makevars) diff --git a/NEWS.md b/NEWS.md index 68409e7..0e8723f 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,10 @@ +# gdalraster.windows (development version) + +## Fixes + +- `install_gdal_runtime(tag = "latest")` no longer trusts GitHub's single "latest release" pointer, which broke the default install path whenever an R package release (`v*`, no bundle asset) was marked latest. "latest" now scans the release list and selects the newest non-draft, non-prerelease release that publishes a runtime bundle asset matching `asset_pattern`, decoupling the package release track from the GDAL bundle release track. +- GitHub API requests are now authenticated when a token is available — resolved from the git credential store (`gitcreds`), then the `GITHUB_PAT` and `GITHUB_TOKEN` environment variables — avoiding anonymous rate limits in CI and behind shared networks. Release-asset selection also tolerates assets with a missing `name` field. + # gdalraster.windows 0.3.0 ## Documentation diff --git a/R/aaa.R b/R/aaa.R index e69de29..0bd8975 100644 --- a/R/aaa.R +++ b/R/aaa.R @@ -0,0 +1,41 @@ + +# ------------------------------------------------------------------------ +# +# Title : Shared Package Resources +# By : Jimmy Briggs +# Date : 2026-07-03 +# +# ------------------------------------------------------------------------ + +# github repositories ------------------------------------------------------ + +#' Repository publishing the GDAL runtime bundle releases (`gdal-v*` tags) +#' @noRd +#' @keywords internal +.bundle_repo <- "jimbrig/gdalraster.windows" + +#' Upstream repository providing the gdalraster source tarball +#' @noRd +#' @keywords internal +.gdalraster_repo <- "firelab/gdalraster" + +# release assets ------------------------------------------------------------ + +#' Regex selecting a runtime bundle zip among release assets +#' @noRd +#' @keywords internal +.bundle_asset_pattern <- "gdal-(bundle|ucrt64)-.*\\.zip$" + +# runtime dll naming -------------------------------------------------------- + +#' Regex matching the top-level GDAL runtime DLL (SONAME discovered by glob, +#' never hardcoded; see #2) +#' @noRd +#' @keywords internal +.gdal_dll_pattern <- "^libgdal-[0-9]+\\.dll$" + +#' Concrete-but-arbitrary DLL filename used only to produce missing-file +#' error paths when no runtime DLL exists yet; never dyn.load()ed +#' @noRd +#' @keywords internal +.gdal_dll_fallback <- "libgdal-39.dll" diff --git a/R/gdal_runtime.R b/R/gdal_runtime.R index 4a828df..48e6f4d 100644 --- a/R/gdal_runtime.R +++ b/R/gdal_runtime.R @@ -78,9 +78,16 @@ configure_gdal_home <- function(path, mode = c("option", "env")) { #' locks on the runtime (another R session, a File Explorer preview pane), the #' install aborts cleanly instead of leaving a partially-replaced runtime. #' -#' @param repo GitHub repo slug, e.g. `"jimbrig/gdalraster.windows"`. -#' @param tag Release tag or `"latest"`. -#' @param asset_pattern Regex used to select the release asset. +#' @param repo GitHub repo slug publishing the runtime bundle releases. +#' Defaults to `"jimbrig/gdalraster.windows"`. +#' @param tag Release tag or `"latest"`. With `"latest"`, the newest release +#' that publishes a runtime bundle asset (matching `asset_pattern`) is +#' selected; releases without a bundle asset — such as R package releases +#' (`v*`) — are skipped, so GitHub's "latest release" pointer does not need +#' to be a GDAL bundle release. +#' @param asset_pattern Regex used to select the release asset. Defaults to +#' the runtime bundle zip naming convention +#' (`gdal-(bundle|ucrt64)-.*\.zip$`). #' @param gdal_home Destination GDAL home directory. #' @param overwrite Whether to replace existing `gdal_home`. #' @param local_zip Optional local GDAL runtime zip to install directly. @@ -91,10 +98,12 @@ configure_gdal_home <- function(path, mode = c("option", "env")) { #' #' @return Invisibly returns installed GDAL home path. #' @export +#' +#' @importFrom httr2 request req_user_agent req_error req_perform resp_body_raw resp_status install_gdal_runtime <- function( - repo = "jimbrig/gdalraster.windows", + repo = .bundle_repo, tag = "latest", - asset_pattern = "gdal-(bundle|ucrt64)-.*\\.zip$", + asset_pattern = .bundle_asset_pattern, gdal_home = default_gdal_home(), overwrite = FALSE, local_zip = NULL, @@ -346,7 +355,8 @@ load_gdal_dll <- function(gdal_home = default_gdal_home(), quiet = FALSE) { #' an isolated package-managed library; pass `.libPaths()[1]` to install #' into your default user library. #' @param source_tarball Optional local path to `gdalraster_*.tar.gz`. -#' @param repo Source GitHub repo slug for gdalraster. +#' @param repo Source GitHub repo slug for gdalraster. Defaults to +#' `"firelab/gdalraster"`. #' @param ref Git ref (branch, tag, commit) used when downloading from GitHub. #' @param upgrade When `TRUE`, missing R package dependencies of gdalraster are #' installed from `repos` before the source build. Has no effect on the @@ -356,11 +366,14 @@ load_gdal_dll <- function(gdal_home = default_gdal_home(), quiet = FALSE) { #' #' @return Invisibly returns installed library path. #' @export +#' +#' @importFrom httr2 request req_user_agent req_error req_perform resp_body_raw resp_status +#' @importFrom withr with_makevars with_envvar install_gdalraster <- function( gdal_home = default_gdal_home(), lib = default_gdalraster_lib(), source_tarball = NULL, - repo = "firelab/gdalraster", + repo = .gdalraster_repo, ref = "HEAD", upgrade = FALSE, repos = getOption("repos") diff --git a/R/gdalraster.windows-package.R b/R/gdalraster.windows-package.R index a65cf64..2584f02 100644 --- a/R/gdalraster.windows-package.R +++ b/R/gdalraster.windows-package.R @@ -2,5 +2,6 @@ "_PACKAGE" ## usethis namespace: start +#' @importFrom rlang %||% ## usethis namespace: end NULL diff --git a/R/utils_pkg.R b/R/utils_pkg.R index 845d748..1343ca7 100644 --- a/R/utils_pkg.R +++ b/R/utils_pkg.R @@ -73,7 +73,7 @@ gdal_dll_candidates <- function(gdal_home = default_gdal_home()) { list.files( path = bin_dir, - pattern = "^libgdal-[0-9]+\\.dll$", + pattern = .gdal_dll_pattern, full.names = TRUE ) } @@ -83,7 +83,7 @@ gdal_dll_candidates <- function(gdal_home = default_gdal_home()) { gdal_dll_path <- function(gdal_home = default_gdal_home()) { dlls <- gdal_dll_candidates(gdal_home = gdal_home) if (length(dlls) < 1L) { - return(file.path(gdal_bin_dir(gdal_home), "libgdal-39.dll")) + return(file.path(gdal_bin_dir(gdal_home), .gdal_dll_fallback)) } dlls[[1]] } @@ -173,26 +173,107 @@ github_release_url <- function(repo, tag = "latest") { } if (identical(tag, "latest")) { - paste0("https://api.github.com/repos/", repo, "/releases/latest") + paste0("https://api.github.com/repos/", repo, "/releases?per_page=100") } else { paste0("https://api.github.com/repos/", repo, "/releases/tags/", tag) } } +#' Token from the git credential store, empty string when unavailable #' @keywords internal #' @noRd -resolve_release_asset <- function(repo, tag = "latest", asset_pattern = "\\.zip$") { - release_req <- httr2::request(github_release_url(repo = repo, tag = tag)) - release_req <- httr2::req_user_agent( - release_req, - paste0(pkg_name(), "/", pkg_version()) +#' @importFrom gitcreds gitcreds_get +#' @importFrom rlang try_fetch +gitcreds_pat <- function() { + rlang::try_fetch( + { + creds <- gitcreds::gitcreds_get(url = "https://github.com") + creds$password %||% "" + }, + error = function(cnd) "" ) - release_req <- httr2::req_error( - release_req, - is_error = function(resp) httr2::resp_status(resp) >= 400L +} + +#' Resolve a GitHub PAT: git credential store (gitcreds), then the +#' GITHUB_PAT and GITHUB_TOKEN environment variables; "" when none found +#' @keywords internal +#' @noRd +github_pat <- function() { + pat <- gitcreds_pat() + if (nzchar(pat)) { + return(pat) + } + pat <- Sys.getenv("GITHUB_PAT", unset = "") + if (nzchar(pat)) { + return(pat) + } + Sys.getenv("GITHUB_TOKEN", unset = "") +} + +#' @keywords internal +#' @noRd +#' @importFrom httr2 request req_user_agent req_auth_bearer_token req_error req_perform resp_body_json resp_status +github_api_json <- function(url, pat = github_pat()) { + req <- httr2::request(url) + req <- httr2::req_user_agent(req, paste0(pkg_name(), "/", pkg_version())) + if (is.character(pat) && length(pat) == 1L && nzchar(pat)) { + req <- httr2::req_auth_bearer_token(req, pat) + } + req <- httr2::req_error(req, is_error = function(resp) httr2::resp_status(resp) >= 400L) + resp <- httr2::req_perform(req) + httr2::resp_body_json(resp, simplifyVector = FALSE) +} + +#' Pick the first (newest) non-draft, non-prerelease release carrying an +#' asset that matches `asset_pattern`. +#' +#' The repository publishes two kinds of releases: GDAL runtime bundle +#' releases (`gdal-v*`, with a bundle zip asset) and R package releases +#' (`v*`, no bundle asset). GitHub's single "latest release" pointer usually +#' tracks the package releases, so "latest" here is resolved by scanning the +#' release list for bundle assets instead of trusting `/releases/latest`. +#' +#' @keywords internal +#' @noRd +select_release_asset <- function(releases, asset_pattern, call = rlang::caller_env()) { + for (release in releases) { + if (isTRUE(release$draft) || isTRUE(release$prerelease)) { + next + } + for (asset in release$assets) { + asset_name <- asset[["name"]] + if (is.null(asset_name) || !nzchar(asset_name)) { + next + } + if (grepl(asset_pattern, asset_name, perl = TRUE)) { + return(list( + id = asset$id, + name = asset_name, + url = asset$browser_download_url, + tag = release$tag_name + )) + } + } + } + + cli::cli_abort( + "No release with an asset matching {.val {asset_pattern}} was found.", + call = call ) - release_resp <- httr2::req_perform(release_req) - release_json <- httr2::resp_body_json(release_resp, simplifyVector = TRUE) +} + +#' @keywords internal +#' @noRd +resolve_release_asset <- function(repo, tag = "latest", asset_pattern = "\\.zip$") { + release_json <- github_api_json(github_release_url(repo = repo, tag = tag)) + + if (identical(tag, "latest")) { + return(select_release_asset( + release_json, + asset_pattern = asset_pattern, + call = rlang::caller_env() + )) + } assets <- release_json$assets if (is.null(assets) || length(assets) == 0L) { @@ -202,7 +283,15 @@ resolve_release_asset <- function(repo, tag = "latest", asset_pattern = "\\.zip$ ) } - match_idx <- which(grepl(asset_pattern, assets$name, perl = TRUE)) + asset_names <- vapply( + assets, + function(asset) { + name <- asset[["name"]] + if (is.null(name)) "" else as.character(name) + }, + character(1) + ) + match_idx <- which(grepl(asset_pattern, asset_names, perl = TRUE)) if (length(match_idx) < 1L) { cli::cli_abort( c( @@ -214,12 +303,12 @@ resolve_release_asset <- function(repo, tag = "latest", asset_pattern = "\\.zip$ ) } - asset <- assets[match_idx[[1]], , drop = FALSE] + asset <- assets[[match_idx[[1]]]] list( - id = asset$id[[1]], - name = asset$name[[1]], - url = asset$browser_download_url[[1]], - tag = release_json$tag_name[[1]] + id = asset$id, + name = asset$name, + url = asset$browser_download_url, + tag = release_json$tag_name ) } diff --git a/man/install_gdal_runtime.Rd b/man/install_gdal_runtime.Rd index 3df9b77..a78fcd6 100644 --- a/man/install_gdal_runtime.Rd +++ b/man/install_gdal_runtime.Rd @@ -5,9 +5,9 @@ \title{Install precompiled GDAL runtime} \usage{ install_gdal_runtime( - repo = "jimbrig/gdalraster.windows", + repo = .bundle_repo, tag = "latest", - asset_pattern = "gdal-(bundle|ucrt64)-.*\\\\.zip$", + asset_pattern = .bundle_asset_pattern, gdal_home = default_gdal_home(), overwrite = FALSE, local_zip = NULL, @@ -15,11 +15,18 @@ install_gdal_runtime( ) } \arguments{ -\item{repo}{GitHub repo slug, e.g. \code{"jimbrig/gdalraster.windows"}.} +\item{repo}{GitHub repo slug publishing the runtime bundle releases. +Defaults to \code{"jimbrig/gdalraster.windows"}.} -\item{tag}{Release tag or \code{"latest"}.} +\item{tag}{Release tag or \code{"latest"}. With \code{"latest"}, the newest release +that publishes a runtime bundle asset (matching \code{asset_pattern}) is +selected; releases without a bundle asset — such as R package releases +(\verb{v*}) — are skipped, so GitHub's "latest release" pointer does not need +to be a GDAL bundle release.} -\item{asset_pattern}{Regex used to select the release asset.} +\item{asset_pattern}{Regex used to select the release asset. Defaults to +the runtime bundle zip naming convention +(\verb{gdal-(bundle|ucrt64)-.*\\.zip$}).} \item{gdal_home}{Destination GDAL home directory.} diff --git a/man/install_gdalraster.Rd b/man/install_gdalraster.Rd index 96686cd..b73ae61 100644 --- a/man/install_gdalraster.Rd +++ b/man/install_gdalraster.Rd @@ -8,7 +8,7 @@ install_gdalraster( gdal_home = default_gdal_home(), lib = default_gdalraster_lib(), source_tarball = NULL, - repo = "firelab/gdalraster", + repo = .gdalraster_repo, ref = "HEAD", upgrade = FALSE, repos = getOption("repos") @@ -23,7 +23,8 @@ into your default user library.} \item{source_tarball}{Optional local path to \code{gdalraster_*.tar.gz}.} -\item{repo}{Source GitHub repo slug for gdalraster.} +\item{repo}{Source GitHub repo slug for gdalraster. Defaults to +\code{"firelab/gdalraster"}.} \item{ref}{Git ref (branch, tag, commit) used when downloading from GitHub.} diff --git a/tests/testthat/test-gdal-runtime.R b/tests/testthat/test-gdal-runtime.R index 161c792..4212d8a 100644 --- a/tests/testthat/test-gdal-runtime.R +++ b/tests/testthat/test-gdal-runtime.R @@ -30,6 +30,112 @@ create_gdal_home_fixture <- function(python = TRUE) { gdal_home } +# builds a synthetic github release list entry; versions are deliberately +# fake (v9.x) so the fixtures cannot be mistaken for real release tags +release_fixture <- function(tag, assets = list(), draft = FALSE, prerelease = FALSE) { + list(tag_name = tag, draft = draft, prerelease = prerelease, assets = assets) +} + +asset_fixture <- function(id, name, url) { + list(id = id, name = name, browser_download_url = url) +} + +testthat::test_that("select_release_asset skips releases without a matching bundle asset", { + releases <- list( + # package release: no bundle asset, must be skipped + release_fixture("v9.0.0"), + # draft bundle release: must be skipped even though the asset matches + release_fixture( + "gdal-v9.9.2", + draft = TRUE, + assets = list( + asset_fixture(30L, "gdal-ucrt64-v9.9.2-windows-x64.zip", "https://example.com/draft.zip") + ) + ), + # newest published bundle release: wins, non-matching assets ignored + release_fixture( + "gdal-v9.9.1", + assets = list( + asset_fixture(10L, "checksums.txt", "https://example.com/checksums.txt"), + asset_fixture(11L, "gdal-ucrt64-v9.9.1-windows-x64.zip", "https://example.com/bundle.zip") + ) + ), + # older published bundle release: valid but not first + release_fixture( + "gdal-v9.9.0", + assets = list( + asset_fixture(20L, "gdal-ucrt64-v9.9.0-windows-x64.zip", "https://example.com/old.zip") + ) + ) + ) + + asset <- gdalraster.windows:::select_release_asset( + releases, + asset_pattern = gdalraster.windows:::.bundle_asset_pattern + ) + + testthat::expect_equal(asset$tag, "gdal-v9.9.1") + testthat::expect_equal(asset$name, "gdal-ucrt64-v9.9.1-windows-x64.zip") + testthat::expect_equal(asset$url, "https://example.com/bundle.zip") +}) + +testthat::test_that("select_release_asset errors when no release carries a bundle asset", { + releases <- list(release_fixture("v9.0.0")) + + testthat::expect_error( + gdalraster.windows:::select_release_asset( + releases, + asset_pattern = gdalraster.windows:::.bundle_asset_pattern + ), + "No release with an asset matching" + ) +}) + +testthat::test_that("select_release_asset tolerates assets with a missing name field", { + releases <- list( + release_fixture( + "gdal-v9.9.1", + assets = list( + list(id = 1L, browser_download_url = "https://example.com/nameless.zip"), + asset_fixture(2L, "gdal-ucrt64-v9.9.1-windows-x64.zip", "https://example.com/bundle.zip") + ) + ) + ) + + asset <- gdalraster.windows:::select_release_asset( + releases, + asset_pattern = gdalraster.windows:::.bundle_asset_pattern + ) + + testthat::expect_equal(asset$name, "gdal-ucrt64-v9.9.1-windows-x64.zip") +}) + +testthat::test_that("github_pat falls back from gitcreds to GITHUB_PAT to GITHUB_TOKEN", { + testthat::local_mocked_bindings( + gitcreds_pat = function() "", + .env = asNamespace("gdalraster.windows") + ) + + withr::local_envvar(GITHUB_PAT = "pat-value", GITHUB_TOKEN = "token-value") + testthat::expect_equal(gdalraster.windows:::github_pat(), "pat-value") + + withr::local_envvar(GITHUB_PAT = NA) + testthat::expect_equal(gdalraster.windows:::github_pat(), "token-value") + + withr::local_envvar(GITHUB_TOKEN = NA) + testthat::expect_equal(gdalraster.windows:::github_pat(), "") +}) + +testthat::test_that("github_pat prefers the git credential store when populated", { + testthat::local_mocked_bindings( + gitcreds_pat = function() "gitcreds-value", + .env = asNamespace("gdalraster.windows") + ) + + withr::local_envvar(GITHUB_PAT = "pat-value") + testthat::expect_equal(gdalraster.windows:::github_pat(), "gitcreds-value") +}) + testthat::test_that("dll discovery supports dynamic GDAL soname", { bin_dir <- withr::local_tempdir() file.create(file.path(bin_dir, "libgdal-39.dll"))