Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 71 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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:-<none>} (${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:
Expand Down
131 changes: 131 additions & 0 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
@@ -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
12 changes: 10 additions & 2 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Comment thread
jimbrig marked this conversation as resolved.
Resolved
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

Expand Down
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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"))
Expand Down
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 5 additions & 1 deletion R/gdal_runtime.R
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
79 changes: 61 additions & 18 deletions R/utils_pkg.R
Original file line number Diff line number Diff line change
Expand Up @@ -173,26 +173,68 @@ 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)
}
}

#' @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)
}
Comment thread
jimbrig marked this conversation as resolved.
Resolved

#' 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(
Comment thread
jimbrig marked this conversation as resolved.
Resolved
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) {
Expand All @@ -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))
Comment thread
jimbrig marked this conversation as resolved.
Resolved
if (length(match_idx) < 1L) {
cli::cli_abort(
c(
Expand All @@ -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
)
}

Expand Down
Loading