Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
145 changes: 123 additions & 22 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,8 @@ jobs:
# added, not straight away (ci-label.yml runs test-rust.yml only).
ios:
name: iOS app
if: >-
github.event_name == 'push'
|| (github.event_name == 'workflow_dispatch' && inputs.platforms != 'linux')
|| contains(github.event.pull_request.labels.*.name, 'ci:macos')
|| contains(github.event.pull_request.labels.*.name, 'ci:full')
needs: plan
if: needs.plan.outputs.ios == 'true'
runs-on: macos-latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
Expand All @@ -121,10 +118,8 @@ jobs:
# platform, a pull request labelled `ci:full`), from the next push after the label is added.
android:
name: Android app
if: >-
github.event_name == 'push'
|| (github.event_name == 'workflow_dispatch' && inputs.platforms != 'linux')
|| contains(github.event.pull_request.labels.*.name, 'ci:full')
needs: plan
if: needs.plan.outputs.android == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
Expand Down Expand Up @@ -375,6 +370,8 @@ jobs:
runs-on: ubuntu-latest
outputs:
os: ${{ steps.os.outputs.os }}
ios: ${{ steps.apps.outputs.ios }}
android: ${{ steps.apps.outputs.android }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
Expand All @@ -386,6 +383,22 @@ jobs:
LABELS: ${{ toJSON(github.event.pull_request.labels.*.name) }}
PLATFORMS: ${{ inputs.platforms }}
run: echo "os=$(.github/scripts/platforms.sh)" >> "$GITHUB_OUTPUT"
# Whether the `ios` and `android` jobs run: they read it, and so does `Tests pass`, to tell a
# job meant to skip from one that should have run.
- id: apps
env:
IOS: >-
${{ github.event_name == 'push'
|| (github.event_name == 'workflow_dispatch' && inputs.platforms != 'linux')
|| contains(github.event.pull_request.labels.*.name, 'ci:macos')
|| contains(github.event.pull_request.labels.*.name, 'ci:full') }}
ANDROID: >-
${{ github.event_name == 'push'
|| (github.event_name == 'workflow_dispatch' && inputs.platforms != 'linux')
|| contains(github.event.pull_request.labels.*.name, 'ci:full') }}
run: |
echo "ios=$IOS" >> "$GITHUB_OUTPUT"
echo "android=$ANDROID" >> "$GITHUB_OUTPUT"

test:
needs: [plan, select]
Expand All @@ -396,19 +409,114 @@ jobs:
# The release build runs nightly; `ci:full` asks for it before merging.
release-build: ${{ contains(github.event.pull_request.labels.*.name, 'ci:full') }}

# The tests that run GDAL or DuckDB, with both installed (#2644). Elsewhere they skip without the
# program, so here RUSTGIS_REQUIRE_GDAL and RUSTGIS_REQUIRE_DUCKDB make a missing one fail them
# instead (`test_runs` in rustgis-data). The `test` job installs neither and keeps covering what a
# user without them sees. It runs the whole of rustgis-data and rustgis-engine, which hold those
# tests, when the run tests either; otherwise its steps skip and it passes. Whole on purpose: a
# filter on test names would miss a new test named otherwise, and with the programs installed
# other tests take the paths a user with them gets (a geodatabase read through GDAL when the
# built-in reader can't). It runs beside `test`, so it costs runner time, not the run's length.
programs:
name: GDAL and DuckDB
needs: select
runs-on: ubuntu-latest
env:
RUSTFLAGS: -D warnings -C linker=clang -C link-arg=-fuse-ld=mold
CARGO_PROFILE_DEV_DEBUG: line-tables-only
RUSTGIS_REQUIRE_GDAL: "1"
RUSTGIS_REQUIRE_DUCKDB: "1"
# GDAL comes from the runner's packages (RustGIS needs 3.8 or later; the install step prints
# the version). DuckDB's command line program is pinned by checksum.
DUCKDB_VERSION: 2.0.1
DUCKDB_SHA256: b676268be4d39e4e41a904442c9796c9914e645cc085c7505f048f2c992b5eca
steps:
- id: scope
env:
PACKAGES: ${{ needs.select.outputs.packages }}
run: |
if [ "$PACKAGES" = --workspace ] || grep -qE '(^| )-p rustgis-(data|engine)( |$)' <<<"$PACKAGES"; then
echo "run=true" >> "$GITHUB_OUTPUT"
else
echo "Neither rustgis-data nor rustgis-engine is tested in this run; skipping."
echo "run=false" >> "$GITHUB_OUTPUT"
fi
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
if: steps.scope.outputs.run == 'true'
with:
persist-credentials: false
- name: Install GDAL and DuckDB
if: steps.scope.outputs.run == 'true'
run: |
set -euo pipefail
sudo apt-get update -qq
sudo apt-get install -y --no-install-recommends mold gdal-bin
curl -fsSLo "$RUNNER_TEMP/duckdb.tar.gz" \
"https://github.com/duckdb/duckdb/releases/download/v$DUCKDB_VERSION/duckdb-cli-linux-amd64.tar.gz"
echo "$DUCKDB_SHA256 $RUNNER_TEMP/duckdb.tar.gz" | sha256sum -c -
mkdir "$RUNNER_TEMP/duckdb"
tar -xzf "$RUNNER_TEMP/duckdb.tar.gz" -C "$RUNNER_TEMP/duckdb" duckdb
echo "$RUNNER_TEMP/duckdb" >> "$GITHUB_PATH"
# DuckDB Spatial, which every query loads, installed now so a download that fails says so here.
"$RUNNER_TEMP/duckdb/duckdb" -c "INSTALL spatial; LOAD spatial;"
ogrinfo --version
"$RUNNER_TEMP/duckdb/duckdb" --version
- uses: dtolnay/rust-toolchain@b725eda525362e7cf34af9a7243cac1e3f01a7ec # stable
if: steps.scope.outputs.run == 'true'
- uses: Swatinem/rust-cache@d1527c8f67ef9af357290475d4af4b0fab8f12e0 # v2
if: steps.scope.outputs.run == 'true'
with:
# Only main saves the cache (see test-rust.yml).
save-if: ${{ github.ref == 'refs/heads/main' }}
- uses: taiki-e/install-action@ab49d3c64680143e184118bed66a46419fc15519 # v2
if: steps.scope.outputs.run == 'true'
with:
tool: cargo-nextest@0.9.151
- name: Clear the previous test report
if: steps.scope.outputs.run == 'true'
run: rm -f target/nextest/ci/junit.xml
- name: Tests
if: steps.scope.outputs.run == 'true'
run: cargo nextest run -p rustgis-data -p rustgis-engine --locked --profile ci

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This job runs the whole of rustgis-data and rustgis-engine again on every run that tests either package, so those crates are compiled and their roughly 4,500 tests run a second time beside test. The rust-cache key is per job, so programs also gets its own cache and no compile is shared. The PR body's timings (22 min here, 21 for test) show the cost. Consider running only the tests that need the programs, for example with a nextest filterset on the names of the skip-gated tests, or put the install and RUSTGIS_REQUIRE_* on the ubuntu leg of test and accept the trade-off that test then stops covering a machine without the programs. If keeping the full run is deliberate, say so in the job comment.

Category: performance

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Kept whole on purpose; 705db13 says why in the job comment. A filter on test names would miss a new GDAL or DuckDB test named otherwise, and with the programs installed other tests also take the paths a user with them gets, such as a geodatabase read through GDAL when the built-in reader can't. The job runs beside test, so it costs runner time, not the run's length.

Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
# As in test-rust.yml: a test that passed only on a retry goes in the summary, and on a push to
# main to the `flaky` job. `test` skips these tests, so only this job can see them.
- name: Flaky tests
id: flaky
if: ${{ !cancelled() && steps.scope.outputs.run == 'true' }}
run: |
.github/scripts/flaky-tests.sh target/nextest/ci/junit.xml > flaky-programs.txt
if [ -s flaky-programs.txt ]; then
echo "found=true" >> "$GITHUB_OUTPUT"
echo "::warning::Tests that passed only on a retry with GDAL and DuckDB: see the job summary."
{
echo "### Flaky tests (GDAL and DuckDB)"
echo
echo "These failed and then passed on a retry, so the run did not fail. Each is a bug to fix."
echo
sed 's/^/- `/; s/$/`/' flaky-programs.txt
} >> "$GITHUB_STEP_SUMMARY"
fi
- name: Keep the flaky tests' names
if: ${{ !cancelled() && steps.flaky.outputs.found == 'true' && github.event_name == 'push' }}
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7
with:
name: flaky-programs
path: flaky-programs.txt
retention-days: 1

# A test that failed and then passed on a retry (.config/nextest.toml) on a push to main gets an
# issue, or a comment on its open one: a retry hides a flaky test from the run, not from us. A
# pull request only lists them in the test jobs' summaries. Like nightly.yml's report, it writes
# issues and runs none of the repository's code.
flaky:
name: Flaky tests
needs: test
needs: [test, programs]
if: ${{ !cancelled() && github.event_name == 'push' && github.repository == 'opengeos/RustGIS' }}
runs-on: ubuntu-latest
permissions:
issues: write
steps:
# One file a runner, flaky-<runner>.txt, each line a test ("<binary> <test>").
# One file a runner (and flaky-programs.txt from `programs`), each line a test ("<binary> <test>").
- uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8
with:
pattern: flaky-*
Expand Down Expand Up @@ -439,24 +547,17 @@ jobs:
# The check to require before merging, so the list of required checks needn't follow the jobs
# above (a runner that only a label adds, a job added later). It fails if any of them failed or
# was cancelled. A skipped job passes only when it was meant to skip: `ios` and `android` skip
# unless their conditions below hold (the same as on the jobs), and every other job always runs.
# unless `plan` says they run, and every other job always runs.
tests_pass:
name: Tests pass
needs: [lint, wasm, ios, android, licenses, schema, rows, deferrals, ratchets, plan, select, test]
needs: [lint, wasm, ios, android, licenses, schema, rows, deferrals, ratchets, plan, select, test, programs]
if: ${{ always() }}
runs-on: ubuntu-latest
steps:
- env:
NEEDS: ${{ toJSON(needs) }}
RUNS_IOS: >-
${{ github.event_name == 'push'
|| (github.event_name == 'workflow_dispatch' && inputs.platforms != 'linux')
|| contains(github.event.pull_request.labels.*.name, 'ci:macos')
|| contains(github.event.pull_request.labels.*.name, 'ci:full') }}
RUNS_ANDROID: >-
${{ github.event_name == 'push'
|| (github.event_name == 'workflow_dispatch' && inputs.platforms != 'linux')
|| contains(github.event.pull_request.labels.*.name, 'ci:full') }}
RUNS_IOS: ${{ needs.plan.outputs.ios }}
RUNS_ANDROID: ${{ needs.plan.outputs.android }}
run: |
set -euo pipefail
meant_to_run() {
Expand Down
3 changes: 3 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,9 @@ the pull request which of these it reaches and why the rest don't apply:
`cargo xtask test-hygiene` (also in CI) requires `// test-wait: reason` on timer waits in tests and
`#[ignore = "reason"]` on ignored tests, and refuses an `assert_eq!` or `assert_ne!` (or `debug_assert_*`)
whose two sides are the same tokens; prefer completion or progress signals, and a fixed expected value.
A test that needs GDAL or DuckDB skips with `if !gdal::test_runs().unwrap() { return; }` (`duckdb::`,
`raster::gdal::`), never on `available()` or `usable()`: CI's `GDAL and DuckDB` job installs both and
sets `RUSTGIS_REQUIRE_GDAL` and `RUSTGIS_REQUIRE_DUCKDB`, so only then does a missing program fail it.
`clippy.toml` refuses the four sphere measures in `rustgis-geom` (`haversine_m`, `geodesic_length_m`,
`geodesic_ring_perimeter_m`, `geodesic_ring_area_m2`): the Earth measures on the WGS 84 ellipsoid
(`wgs84_distance_m`, `wgs84_length_m`, `wgs84_step_m`, `wgs84_ring_perimeter_area_m2`), and a call kept on
Expand Down
4 changes: 2 additions & 2 deletions crates/data/src/filegdb/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,7 @@ fn hostile_bytes_never_panic() {
/// fields, and a TIN, which GDAL stores as a multipatch (a triangle fan).
#[test]
fn reads_what_gdal_writes_when_gdal_is_installed() {
if !crate::source::gdal::available() {
if !crate::source::gdal::test_runs().unwrap() {
return;
}
let dir = std::env::temp_dir().join(format!("rustgis-filegdb-{}", std::process::id()));
Expand All @@ -647,7 +647,7 @@ fn reads_what_gdal_writes_when_gdal_is_installed() {
.unwrap();
let (gdb_s, points_s, tins_s) = (gdb.display().to_string(), points.display().to_string(), tins.display().to_string());
run(&["-f", "OpenFileGDB", "-a_srs", "EPSG:4326", "-nlt", "POINT", "-nln", "places", "-oo", "AUTODETECT_TYPE=YES", &gdb_s, &points_s]);
run(&["-f", "OpenFileGDB", "-update", "-a_srs", "EPSG:2056", "-nlt", "TINZ", "-nln", "blocks", &gdb_s, &tins_s]);
run(&["-f", "OpenFileGDB", "-update", "-a_srs", "EPSG:2056", "-nlt", "GEOMETRYCOLLECTIONZ", "-nln", "blocks", &gdb_s, &tins_s]);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The switch from TINZ to GEOMETRYCOLLECTIONZ is the fix for the test passing only by skipping, but nothing in the code says why. A later maintainer could reasonably change it back to TINZ, and the test would then skip again or fail. The reason is in the PR body only. A short comment on the line keeps it where the next reader will look:

Suggested change
run(&["-f", "OpenFileGDB", "-update", "-a_srs", "EPSG:2056", "-nlt", "GEOMETRYCOLLECTIONZ", "-nln", "blocks", &gdb_s, &tins_s]);
// TINZ makes GDAL write a polygon layer and then refuse the TIN (3.8.4 and 3.10.3). A GEOMETRYCOLLECTIONZ layer is a multipatch, which is what this reads.
run(&["-f", "OpenFileGDB", "-update", "-a_srs", "EPSG:2056", "-nlt", "GEOMETRYCOLLECTIONZ", "-nln", "blocks", &gdb_s, &tins_s]);

Confidence: high that the comment is missing; the fix itself is verified by the author's run.

Category: quality

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Left for the release quality pass. A switch back to TINZ no longer goes unnoticed: the GDAL and DuckDB job now fails this test where it used to skip.

assert!(is_geodatabase(&gdb));
assert_eq!(layers(&gdb).unwrap(), ["places", "blocks"]);
let read = read_dir(&gdb, None).unwrap().layers;
Expand Down
18 changes: 11 additions & 7 deletions crates/data/src/raster/gdal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ pub fn available() -> bool {
program("gdal_translate").is_some() && program("gdalinfo").is_some()
}

/// Whether a test that needs GDAL's raster programs runs: skipped without them, unless
/// `RUSTGIS_REQUIRE_GDAL` is set, when it fails on the `Err` instead.
pub fn test_runs() -> std::result::Result<bool, String> {
external::test_runs("RUSTGIS_REQUIRE_GDAL", "GDAL's raster programs (gdal_translate and gdalinfo)", available())
}

/// What converting a file's contents made: the GeoTIFF's bytes, and whether the raster was taken
/// as WGS 84 (see [`Converted::assumed_lonlat`]).
pub struct ConvertedBytes {
Expand Down Expand Up @@ -935,10 +941,10 @@ mod tests {
/// A VRT renamed `.img` isn't opened as a VRT, so the raster it names isn't read.
#[test]
fn a_renamed_vrt_isnt_read_when_gdal_is_installed() {
let Some(translate) = program("gdal_translate") else { return };
if program("gdalinfo").is_none() {
if !test_runs().unwrap() {
return;
}
let translate = program("gdal_translate").unwrap();
let dir = tempfile::tempdir().unwrap();
let asc = dir.path().join("private.asc");
std::fs::write(&asc, "ncols 1\nnrows 1\nxllcorner 0\nyllcorner 0\ncellsize 1\n7\n").unwrap();
Expand All @@ -963,10 +969,10 @@ mod tests {
/// Runs only where GDAL is installed: a NetCDF file's variables.
#[test]
fn raster_conversion_provenance_excludes_cache_files_when_gdal_is_installed() {
let Some(translate) = program("gdal_translate") else { return };
if program("gdalinfo").is_none() {
if !test_runs().unwrap() {
return;
}
let translate = program("gdal_translate").unwrap();
let dir = std::env::temp_dir().join(format!("rustgis-gdal-raster-{}", std::process::id()));
let _ = std::fs::remove_dir_all(&dir);
std::fs::create_dir_all(&dir).unwrap();
Expand All @@ -984,9 +990,7 @@ mod tests {
.arg(&img)
.status()
.is_ok_and(|s| s.success());
if !ok {
return;
}
assert!(ok, "gdal_translate couldn't make the ERDAS Imagine fixture");
let cache = dir.join("cache");
let captured = crate::provenance::Capture::start();
let c = convert_in(&cache, &img, None, None, None).unwrap();
Expand Down
10 changes: 8 additions & 2 deletions crates/data/src/source/duckdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,12 @@ pub fn available() -> bool {
program().is_some()
}

/// Whether a test that needs DuckDB runs: skipped without it, unless `RUSTGIS_REQUIRE_DUCKDB` is
/// set, when it fails on the `Err` instead.
pub fn test_runs() -> std::result::Result<bool, String> {
external::test_runs("RUSTGIS_REQUIRE_DUCKDB", "DuckDB (the duckdb program)", available())
}

/// A live-only database named for a query: add its tables instead.
fn live_not_here() -> DataError {
DataError::Unsupported(
Expand Down Expand Up @@ -1605,7 +1611,7 @@ mod tests {
#[test]
fn previews_rows() {
assert!(checked(" ;").is_err() && checked("SELECT 1\0").is_err());
if !available() {
if !test_runs().unwrap() {
return;
}
let dir = std::env::temp_dir().join(format!("rustgis-duckdb-preview-{}", std::process::id()));
Expand Down Expand Up @@ -1642,7 +1648,7 @@ mod tests {
/// Queries and a database through DuckDB when it is installed (skipped otherwise).
#[test]
fn runs_queries_when_duckdb_is_installed() {
if !available() {
if !test_runs().unwrap() {
return;
}
let dir = std::env::temp_dir().join(format!("rustgis-duckdb-test-{}", std::process::id()));
Expand Down
13 changes: 13 additions & 0 deletions crates/data/src/source/external.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,19 @@ pub(crate) fn cache_dir(env: &str, sub: &str) -> Option<PathBuf> {
crate::dirs::cache_dir().map(|b| b.join(sub))
}

/// Whether a test that needs a program runs (`here`: it is installed). Where it isn't, the test is
/// skipped, unless the environment variable `require` is set, as in CI's job that installs the
/// programs: then the `Err` says what is missing, and the test fails instead of passing unrun.
pub(crate) fn test_runs(require: &str, what: &str, here: bool) -> std::result::Result<bool, String> {
if here {
Ok(true)
} else if std::env::var_os(require).is_some_and(|v| !v.is_empty()) {
Err(format!("{require} is set, but {what} wasn't found"))
} else {
Ok(false)
}
}

const RELOAD_PREFIX: &str = "reload-";
const RELOAD_OWNER_MARKER: &[u8] = b"RustGIS reload workspace v1\n";

Expand Down
Loading
Loading