From 0c3fbb38e6841462c58c81b89b32c849b9c77892 Mon Sep 17 00:00:00 2001 From: Jimmy Briggs Date: Fri, 3 Jul 2026 14:56:04 -0400 Subject: [PATCH 1/6] fix: resolve "latest" runtime by scanning releases for bundle assets install_gdal_runtime(tag = "latest") previously trusted GitHub's single /releases/latest pointer, which broke the default install path whenever an R package release (v*, no bundle zip) was marked as the repo's latest release. "latest" now lists releases and selects the newest non-draft, non-prerelease release carrying an asset that matches asset_pattern, so the package release track and the GDAL bundle release track stay fully decoupled. Package releases may also attach the paired bundle zip (as v0.3.0 does) and are then picked up directly. Adds unit tests for the selection logic, documents the new "latest" semantics on install_gdal_runtime(), and bumps to dev version 0.3.0.9000 with a NEWS entry. Co-authored-by: Cursor --- DESCRIPTION | 2 +- NEWS.md | 6 +++ R/gdal_runtime.R | 6 ++- R/utils_pkg.R | 79 +++++++++++++++++++++++------- man/install_gdal_runtime.Rd | 6 ++- tests/testthat/test-gdal-runtime.R | 61 +++++++++++++++++++++++ 6 files changed, 139 insertions(+), 21 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 5f1e113..09e012e 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")) diff --git a/NEWS.md b/NEWS.md index 68409e7..1259f02 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,9 @@ +# 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. + # gdalraster.windows 0.3.0 ## Documentation diff --git a/R/gdal_runtime.R b/R/gdal_runtime.R index 4a828df..80d1bca 100644 --- a/R/gdal_runtime.R +++ b/R/gdal_runtime.R @@ -79,7 +79,11 @@ configure_gdal_home <- function(path, mode = c("option", "env")) { #' 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 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. #' @param gdal_home Destination GDAL home directory. #' @param overwrite Whether to replace existing `gdal_home`. diff --git a/R/utils_pkg.R b/R/utils_pkg.R index 845d748..f9adfad 100644 --- a/R/utils_pkg.R +++ b/R/utils_pkg.R @@ -173,7 +173,7 @@ 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) } @@ -181,18 +181,60 @@ github_release_url <- function(repo, tag = "latest") { #' @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()) - ) - release_req <- httr2::req_error( - release_req, - is_error = function(resp) httr2::resp_status(resp) >= 400L +github_api_json <- function(url) { + req <- httr2::request(url) + req <- httr2::req_user_agent(req, paste0(pkg_name(), "/", pkg_version())) + 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) { + 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 +244,8 @@ 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) asset$name, character(1)) + match_idx <- which(grepl(asset_pattern, asset_names, perl = TRUE)) if (length(match_idx) < 1L) { cli::cli_abort( c( @@ -214,12 +257,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..8ac97ff 100644 --- a/man/install_gdal_runtime.Rd +++ b/man/install_gdal_runtime.Rd @@ -17,7 +17,11 @@ install_gdal_runtime( \arguments{ \item{repo}{GitHub repo slug, e.g. \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.} diff --git a/tests/testthat/test-gdal-runtime.R b/tests/testthat/test-gdal-runtime.R index 161c792..2288e53 100644 --- a/tests/testthat/test-gdal-runtime.R +++ b/tests/testthat/test-gdal-runtime.R @@ -30,6 +30,67 @@ create_gdal_home_fixture <- function(python = TRUE) { gdal_home } +testthat::test_that("select_release_asset skips releases without a matching bundle asset", { + releases <- list( + list( + tag_name = "v0.3.0", + draft = FALSE, + prerelease = FALSE, + assets = list() + ), + list( + tag_name = "gdal-v3.13.2", + draft = TRUE, + prerelease = FALSE, + assets = list( + list(id = 30L, name = "gdal-ucrt64-v3.13.2-windows-x64.zip", browser_download_url = "https://example.com/draft.zip") + ) + ), + list( + tag_name = "gdal-v3.13.1", + draft = FALSE, + prerelease = FALSE, + assets = list( + list(id = 10L, name = "checksums.txt", browser_download_url = "https://example.com/checksums.txt"), + list(id = 11L, name = "gdal-ucrt64-v3.13.1-windows-x64.zip", browser_download_url = "https://example.com/bundle.zip") + ) + ), + list( + tag_name = "gdal-v3.13.0", + draft = FALSE, + prerelease = FALSE, + assets = list( + list(id = 20L, name = "gdal-ucrt64-v3.13.0-windows-x64.zip", browser_download_url = "https://example.com/old.zip") + ) + ) + ) + + asset <- gdalraster.windows:::select_release_asset( + releases, + asset_pattern = "gdal-(bundle|ucrt64)-.*\\.zip$" + ) + + # the package release (no assets) and the draft are skipped; the newest + # published bundle release wins and non-matching assets within it are ignored + testthat::expect_equal(asset$tag, "gdal-v3.13.1") + testthat::expect_equal(asset$name, "gdal-ucrt64-v3.13.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( + list(tag_name = "v0.3.0", draft = FALSE, prerelease = FALSE, assets = list()) + ) + + testthat::expect_error( + gdalraster.windows:::select_release_asset( + releases, + asset_pattern = "gdal-(bundle|ucrt64)-.*\\.zip$" + ), + "No release with an asset matching" + ) +}) + testthat::test_that("dll discovery supports dynamic GDAL soname", { bin_dir <- withr::local_tempdir() file.create(file.path(bin_dir, "libgdal-39.dll")) From d87de0090ab2dc0fd15491f7365cf65b320878a4 Mon Sep 17 00:00:00 2001 From: Jimmy Briggs Date: Fri, 3 Jul 2026 15:04:24 -0400 Subject: [PATCH 2/6] feat(cicd): scheduled upstream GDAL check and e2e verification workflow (#20) build.yml gains a schedule-only job that compares the latest OSGeo/gdal release against our newest published gdal-v* bundle and opens a labeled tracking issue when a newer GDAL exists - it never builds or publishes on its own. New e2e.yml proves the full documented user workflow on a clean windows-latest runner (install runtime, source-build gdalraster against it, verify the algorithm registry, and verify the .Rprofile startup hook in a fresh session), consuming only exported package functions per the AGENTS.md responsibility split, which is updated accordingly. Co-authored-by: Cursor --- .github/workflows/build.yml | 73 +++++++++++++++- .github/workflows/e2e.yml | 131 +++++++++++++++++++++++++++++ AGENTS.md | 12 ++- tests/testthat/test-gdal-runtime.R | 18 +++- 4 files changed, 227 insertions(+), 7 deletions(-) create mode 100644 .github/workflows/e2e.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index bc9f80d..495a80a 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 @@ -50,8 +55,12 @@ 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 @@ -60,11 +69,71 @@ 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..48ded87 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 +- Build CI's only responsibility is the GDAL runtime bundle: build, verify the bundle contract, and publish durable artifacts (workflow artifact + release - asset). + 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/tests/testthat/test-gdal-runtime.R b/tests/testthat/test-gdal-runtime.R index 2288e53..0f4fe98 100644 --- a/tests/testthat/test-gdal-runtime.R +++ b/tests/testthat/test-gdal-runtime.R @@ -43,7 +43,11 @@ testthat::test_that("select_release_asset skips releases without a matching bund draft = TRUE, prerelease = FALSE, assets = list( - list(id = 30L, name = "gdal-ucrt64-v3.13.2-windows-x64.zip", browser_download_url = "https://example.com/draft.zip") + list( + id = 30L, + name = "gdal-ucrt64-v3.13.2-windows-x64.zip", + browser_download_url = "https://example.com/draft.zip" + ) ) ), list( @@ -52,7 +56,11 @@ testthat::test_that("select_release_asset skips releases without a matching bund prerelease = FALSE, assets = list( list(id = 10L, name = "checksums.txt", browser_download_url = "https://example.com/checksums.txt"), - list(id = 11L, name = "gdal-ucrt64-v3.13.1-windows-x64.zip", browser_download_url = "https://example.com/bundle.zip") + list( + id = 11L, + name = "gdal-ucrt64-v3.13.1-windows-x64.zip", + browser_download_url = "https://example.com/bundle.zip" + ) ) ), list( @@ -60,7 +68,11 @@ testthat::test_that("select_release_asset skips releases without a matching bund draft = FALSE, prerelease = FALSE, assets = list( - list(id = 20L, name = "gdal-ucrt64-v3.13.0-windows-x64.zip", browser_download_url = "https://example.com/old.zip") + list( + id = 20L, + name = "gdal-ucrt64-v3.13.0-windows-x64.zip", + browser_download_url = "https://example.com/old.zip" + ) ) ) ) From 4b908ba87a567c092552b966f492d4549ae5f4e5 Mon Sep 17 00:00:00 2001 From: Jimmy Briggs Date: Fri, 3 Jul 2026 15:14:41 -0400 Subject: [PATCH 3/6] refactor: centralize repo slugs, asset patterns, and dll naming in R/constants.R Single source of truth for the bundle repo, gdalraster source repo, bundle asset regex, and dll name pattern/fallback; function signatures now reference the constants and roxygen docs state the concrete defaults. Test fixtures for release selection use deliberately fake v9.x versions via fixture helpers so they cannot be mistaken for real release tags, and build.yml marks its duplicated version defaults with keep-in-sync comments. Co-authored-by: Cursor --- .github/workflows/build.yml | 3 ++ R/constants.R | 48 ++++++++++++++++++++ R/gdal_runtime.R | 16 ++++--- R/utils_pkg.R | 4 +- man/install_gdal_runtime.Rd | 11 +++-- man/install_gdalraster.Rd | 5 ++- tests/testthat/test-gdal-runtime.R | 72 +++++++++++++----------------- 7 files changed, 103 insertions(+), 56 deletions(-) create mode 100644 R/constants.R diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 495a80a..317e5cc 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -37,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' @@ -65,6 +67,7 @@ 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' }} diff --git a/R/constants.R b/R/constants.R new file mode 100644 index 0000000..04e8a57 --- /dev/null +++ b/R/constants.R @@ -0,0 +1,48 @@ +# ------------------------------------------------------------------------ +# +# Title : package constants +# +# single source of truth for repo slugs, release asset patterns, and dll +# naming conventions used across the package. workflow-side counterparts +# (default gdal_version in .github/workflows/build.yml and the readme +# latest-release line) are release-time bookkeeping and are called out in +# the scheduled upstream-check issue template. +# +# ------------------------------------------------------------------------ + +#' Repository publishing the GDAL runtime bundle releases (`gdal-v*` tags) +#' @keywords internal +#' @noRd +default_bundle_repo <- function() { + "jimbrig/gdalraster.windows" +} + +#' Upstream repository providing the gdalraster source tarball +#' @keywords internal +#' @noRd +default_gdalraster_repo <- function() { + "firelab/gdalraster" +} + +#' Regex selecting a runtime bundle zip among release assets +#' @keywords internal +#' @noRd +bundle_asset_pattern <- function() { + "gdal-(bundle|ucrt64)-.*\\.zip$" +} + +#' Regex matching the top-level GDAL runtime DLL (SONAME discovered by glob, +#' never hardcoded; see #2) +#' @keywords internal +#' @noRd +gdal_dll_name_pattern <- function() { + "^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 +#' @keywords internal +#' @noRd +gdal_dll_fallback_name <- function() { + "libgdal-39.dll" +} diff --git a/R/gdal_runtime.R b/R/gdal_runtime.R index 80d1bca..bb2e18c 100644 --- a/R/gdal_runtime.R +++ b/R/gdal_runtime.R @@ -78,13 +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 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. +#' @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. @@ -96,9 +99,9 @@ configure_gdal_home <- function(path, mode = c("option", "env")) { #' @return Invisibly returns installed GDAL home path. #' @export install_gdal_runtime <- function( - repo = "jimbrig/gdalraster.windows", + repo = default_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, @@ -350,7 +353,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 @@ -364,7 +368,7 @@ install_gdalraster <- function( gdal_home = default_gdal_home(), lib = default_gdalraster_lib(), source_tarball = NULL, - repo = "firelab/gdalraster", + repo = default_gdalraster_repo(), ref = "HEAD", upgrade = FALSE, repos = getOption("repos") diff --git a/R/utils_pkg.R b/R/utils_pkg.R index f9adfad..88a5035 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_name_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_name())) } dlls[[1]] } diff --git a/man/install_gdal_runtime.Rd b/man/install_gdal_runtime.Rd index 8ac97ff..70dd12f 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 = default_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,7 +15,8 @@ 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"}. With \code{"latest"}, the newest release that publishes a runtime bundle asset (matching \code{asset_pattern}) is @@ -23,7 +24,9 @@ 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..02bc66f 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 = default_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 0f4fe98..d041802 100644 --- a/tests/testthat/test-gdal-runtime.R +++ b/tests/testthat/test-gdal-runtime.R @@ -30,74 +30,62 @@ 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( - list( - tag_name = "v0.3.0", - draft = FALSE, - prerelease = FALSE, - assets = list() - ), - list( - tag_name = "gdal-v3.13.2", + # 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, - prerelease = FALSE, assets = list( - list( - id = 30L, - name = "gdal-ucrt64-v3.13.2-windows-x64.zip", - browser_download_url = "https://example.com/draft.zip" - ) + asset_fixture(30L, "gdal-ucrt64-v9.9.2-windows-x64.zip", "https://example.com/draft.zip") ) ), - list( - tag_name = "gdal-v3.13.1", - draft = FALSE, - prerelease = FALSE, + # newest published bundle release: wins, non-matching assets ignored + release_fixture( + "gdal-v9.9.1", assets = list( - list(id = 10L, name = "checksums.txt", browser_download_url = "https://example.com/checksums.txt"), - list( - id = 11L, - name = "gdal-ucrt64-v3.13.1-windows-x64.zip", - browser_download_url = "https://example.com/bundle.zip" - ) + 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") ) ), - list( - tag_name = "gdal-v3.13.0", - draft = FALSE, - prerelease = FALSE, + # older published bundle release: valid but not first + release_fixture( + "gdal-v9.9.0", assets = list( - list( - id = 20L, - name = "gdal-ucrt64-v3.13.0-windows-x64.zip", - browser_download_url = "https://example.com/old.zip" - ) + 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 = "gdal-(bundle|ucrt64)-.*\\.zip$" + asset_pattern = gdalraster.windows:::bundle_asset_pattern() ) - # the package release (no assets) and the draft are skipped; the newest - # published bundle release wins and non-matching assets within it are ignored - testthat::expect_equal(asset$tag, "gdal-v3.13.1") - testthat::expect_equal(asset$name, "gdal-ucrt64-v3.13.1-windows-x64.zip") + 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( - list(tag_name = "v0.3.0", draft = FALSE, prerelease = FALSE, assets = list()) - ) + releases <- list(release_fixture("v9.0.0")) testthat::expect_error( gdalraster.windows:::select_release_asset( releases, - asset_pattern = "gdal-(bundle|ucrt64)-.*\\.zip$" + asset_pattern = gdalraster.windows:::bundle_asset_pattern() ), "No release with an asset matching" ) From 8eb0f46683c5b7ea475025b1fdd5f75a4bf6bbaf Mon Sep 17 00:00:00 2001 From: Jimmy Briggs Date: Fri, 3 Jul 2026 15:18:05 -0400 Subject: [PATCH 4/6] refactor: move shared constants to R/aaa.R using dot-prefixed convention Follows the LandRise package layout (aaa.R for shared package resources) with dot-prefixed internal constants instead of accessor functions. Co-authored-by: Cursor --- R/aaa.R | 41 +++++++++++++++++++++++++ R/constants.R | 48 ------------------------------ R/gdal_runtime.R | 6 ++-- R/utils_pkg.R | 4 +-- man/install_gdal_runtime.Rd | 4 +-- man/install_gdalraster.Rd | 2 +- tests/testthat/test-gdal-runtime.R | 4 +-- 7 files changed, 51 insertions(+), 58 deletions(-) delete mode 100644 R/constants.R 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/constants.R b/R/constants.R deleted file mode 100644 index 04e8a57..0000000 --- a/R/constants.R +++ /dev/null @@ -1,48 +0,0 @@ -# ------------------------------------------------------------------------ -# -# Title : package constants -# -# single source of truth for repo slugs, release asset patterns, and dll -# naming conventions used across the package. workflow-side counterparts -# (default gdal_version in .github/workflows/build.yml and the readme -# latest-release line) are release-time bookkeeping and are called out in -# the scheduled upstream-check issue template. -# -# ------------------------------------------------------------------------ - -#' Repository publishing the GDAL runtime bundle releases (`gdal-v*` tags) -#' @keywords internal -#' @noRd -default_bundle_repo <- function() { - "jimbrig/gdalraster.windows" -} - -#' Upstream repository providing the gdalraster source tarball -#' @keywords internal -#' @noRd -default_gdalraster_repo <- function() { - "firelab/gdalraster" -} - -#' Regex selecting a runtime bundle zip among release assets -#' @keywords internal -#' @noRd -bundle_asset_pattern <- function() { - "gdal-(bundle|ucrt64)-.*\\.zip$" -} - -#' Regex matching the top-level GDAL runtime DLL (SONAME discovered by glob, -#' never hardcoded; see #2) -#' @keywords internal -#' @noRd -gdal_dll_name_pattern <- function() { - "^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 -#' @keywords internal -#' @noRd -gdal_dll_fallback_name <- function() { - "libgdal-39.dll" -} diff --git a/R/gdal_runtime.R b/R/gdal_runtime.R index bb2e18c..d6656c9 100644 --- a/R/gdal_runtime.R +++ b/R/gdal_runtime.R @@ -99,9 +99,9 @@ configure_gdal_home <- function(path, mode = c("option", "env")) { #' @return Invisibly returns installed GDAL home path. #' @export install_gdal_runtime <- function( - repo = default_bundle_repo(), + repo = .bundle_repo, tag = "latest", - asset_pattern = bundle_asset_pattern(), + asset_pattern = .bundle_asset_pattern, gdal_home = default_gdal_home(), overwrite = FALSE, local_zip = NULL, @@ -368,7 +368,7 @@ install_gdalraster <- function( gdal_home = default_gdal_home(), lib = default_gdalraster_lib(), source_tarball = NULL, - repo = default_gdalraster_repo(), + repo = .gdalraster_repo, ref = "HEAD", upgrade = FALSE, repos = getOption("repos") diff --git a/R/utils_pkg.R b/R/utils_pkg.R index 88a5035..1951ac5 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 = gdal_dll_name_pattern(), + 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), gdal_dll_fallback_name())) + return(file.path(gdal_bin_dir(gdal_home), .gdal_dll_fallback)) } dlls[[1]] } diff --git a/man/install_gdal_runtime.Rd b/man/install_gdal_runtime.Rd index 70dd12f..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 = default_bundle_repo(), + repo = .bundle_repo, tag = "latest", - asset_pattern = bundle_asset_pattern(), + asset_pattern = .bundle_asset_pattern, gdal_home = default_gdal_home(), overwrite = FALSE, local_zip = NULL, diff --git a/man/install_gdalraster.Rd b/man/install_gdalraster.Rd index 02bc66f..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 = default_gdalraster_repo(), + repo = .gdalraster_repo, ref = "HEAD", upgrade = FALSE, repos = getOption("repos") diff --git a/tests/testthat/test-gdal-runtime.R b/tests/testthat/test-gdal-runtime.R index d041802..d0dcb92 100644 --- a/tests/testthat/test-gdal-runtime.R +++ b/tests/testthat/test-gdal-runtime.R @@ -71,7 +71,7 @@ testthat::test_that("select_release_asset skips releases without a matching bund asset <- gdalraster.windows:::select_release_asset( releases, - asset_pattern = gdalraster.windows:::bundle_asset_pattern() + asset_pattern = gdalraster.windows:::.bundle_asset_pattern ) testthat::expect_equal(asset$tag, "gdal-v9.9.1") @@ -85,7 +85,7 @@ testthat::test_that("select_release_asset errors when no release carries a bundl testthat::expect_error( gdalraster.windows:::select_release_asset( releases, - asset_pattern = gdalraster.windows:::bundle_asset_pattern() + asset_pattern = gdalraster.windows:::.bundle_asset_pattern ), "No release with an asset matching" ) From c661683ffafe8833befe24cbe17affef22b976e7 Mon Sep 17 00:00:00 2001 From: Jimmy Briggs Date: Fri, 3 Jul 2026 15:21:39 -0400 Subject: [PATCH 5/6] fix: authenticate GitHub API requests and harden asset selection (#21 review) github_api_json() gains a pat argument defaulting to github_pat(), which resolves a token from the git credential store (gitcreds) then the GITHUB_PAT and GITHUB_TOKEN env vars, avoiding anonymous rate limits. Release-asset selection tolerates assets missing a name field in both the latest-scan and explicit-tag paths. Adds gitcreds to Imports, explicit @importFrom statements for httr2/gitcreds/rlang in the package doc, tests for the PAT fallback order and nameless assets, and fixes the AGENTS.md wording flagged by Copilot. Co-authored-by: Cursor --- AGENTS.md | 6 ++-- DESCRIPTION | 1 + NAMESPACE | 10 ++++++ NEWS.md | 1 + R/gdalraster.windows-package.R | 10 ++++++ R/utils_pkg.R | 51 +++++++++++++++++++++++++++--- tests/testthat/test-gdal-runtime.R | 45 ++++++++++++++++++++++++++ 7 files changed, 117 insertions(+), 7 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 48ded87..e7adf39 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -54,9 +54,9 @@ gdalraster::gdal_global_reg_names() ## responsibility split -- Build CI'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 +- 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 diff --git a/DESCRIPTION b/DESCRIPTION index 09e012e..5f53b41 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -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..6362c57 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -13,6 +13,16 @@ 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) diff --git a/NEWS.md b/NEWS.md index 1259f02..0e8723f 100644 --- a/NEWS.md +++ b/NEWS.md @@ -3,6 +3,7 @@ ## 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 diff --git a/R/gdalraster.windows-package.R b/R/gdalraster.windows-package.R index a65cf64..03cdd21 100644 --- a/R/gdalraster.windows-package.R +++ b/R/gdalraster.windows-package.R @@ -2,5 +2,15 @@ "_PACKAGE" ## usethis namespace: start +#' @importFrom gitcreds gitcreds_get +#' @importFrom httr2 request +#' @importFrom httr2 req_auth_bearer_token +#' @importFrom httr2 req_error +#' @importFrom httr2 req_perform +#' @importFrom httr2 req_user_agent +#' @importFrom httr2 resp_body_json +#' @importFrom httr2 resp_body_raw +#' @importFrom httr2 resp_status +#' @importFrom rlang %||% ## usethis namespace: end NULL diff --git a/R/utils_pkg.R b/R/utils_pkg.R index 1951ac5..5552b38 100644 --- a/R/utils_pkg.R +++ b/R/utils_pkg.R @@ -179,11 +179,43 @@ github_release_url <- function(repo, tag = "latest") { } } +#' Token from the git credential store, empty string when unavailable #' @keywords internal #' @noRd -github_api_json <- function(url) { +gitcreds_pat <- function() { + rlang::try_fetch( + { + creds <- gitcreds::gitcreds_get(url = "https://github.com") + creds$password %||% "" + }, + error = function(cnd) "" + ) +} + +#' 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 +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) @@ -206,10 +238,14 @@ select_release_asset <- function(releases, asset_pattern, call = rlang::caller_e next } for (asset in release$assets) { - if (grepl(asset_pattern, asset$name, perl = TRUE)) { + 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, + name = asset_name, url = asset$browser_download_url, tag = release$tag_name )) @@ -244,7 +280,14 @@ resolve_release_asset <- function(repo, tag = "latest", asset_pattern = "\\.zip$ ) } - asset_names <- vapply(assets, function(asset) asset$name, character(1)) + 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( diff --git a/tests/testthat/test-gdal-runtime.R b/tests/testthat/test-gdal-runtime.R index d0dcb92..4212d8a 100644 --- a/tests/testthat/test-gdal-runtime.R +++ b/tests/testthat/test-gdal-runtime.R @@ -91,6 +91,51 @@ testthat::test_that("select_release_asset errors when no release carries a bundl ) }) +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")) From 576b89a159ce444128730ca6f74c401c016e24d8 Mon Sep 17 00:00:00 2001 From: Jimmy Briggs Date: Fri, 3 Jul 2026 15:24:55 -0400 Subject: [PATCH 6/6] refactor(docs): move importFrom tags to the functions that use them Package doc keeps only the shared rlang %||% import; httr2, gitcreds, withr, and rlang try_fetch imports now live on their consuming functions. Synced via attachment::att_amend_desc(). Co-authored-by: Cursor --- NAMESPACE | 3 +++ R/gdal_runtime.R | 5 +++++ R/gdalraster.windows-package.R | 9 --------- R/utils_pkg.R | 3 +++ 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/NAMESPACE b/NAMESPACE index 6362c57..7bcc501 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -27,5 +27,8 @@ 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/R/gdal_runtime.R b/R/gdal_runtime.R index d6656c9..48e6f4d 100644 --- a/R/gdal_runtime.R +++ b/R/gdal_runtime.R @@ -98,6 +98,8 @@ 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 = .bundle_repo, tag = "latest", @@ -364,6 +366,9 @@ 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(), diff --git a/R/gdalraster.windows-package.R b/R/gdalraster.windows-package.R index 03cdd21..2584f02 100644 --- a/R/gdalraster.windows-package.R +++ b/R/gdalraster.windows-package.R @@ -2,15 +2,6 @@ "_PACKAGE" ## usethis namespace: start -#' @importFrom gitcreds gitcreds_get -#' @importFrom httr2 request -#' @importFrom httr2 req_auth_bearer_token -#' @importFrom httr2 req_error -#' @importFrom httr2 req_perform -#' @importFrom httr2 req_user_agent -#' @importFrom httr2 resp_body_json -#' @importFrom httr2 resp_body_raw -#' @importFrom httr2 resp_status #' @importFrom rlang %||% ## usethis namespace: end NULL diff --git a/R/utils_pkg.R b/R/utils_pkg.R index 5552b38..1343ca7 100644 --- a/R/utils_pkg.R +++ b/R/utils_pkg.R @@ -182,6 +182,8 @@ github_release_url <- function(repo, tag = "latest") { #' Token from the git credential store, empty string when unavailable #' @keywords internal #' @noRd +#' @importFrom gitcreds gitcreds_get +#' @importFrom rlang try_fetch gitcreds_pat <- function() { rlang::try_fetch( { @@ -210,6 +212,7 @@ github_pat <- function() { #' @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()))