From e9eafef17823773ab72d0a4938d8ef716c806a86 Mon Sep 17 00:00:00 2001 From: Wei Ji <23487320+weiji14@users.noreply.github.com> Date: Mon, 8 Jul 2024 16:47:13 +1200 Subject: [PATCH 1/4] :construction_worker: Setup CI job matrix for cargo test Ensure that Rust unit tests and doctests are checked too. Running on Ubuntu-24.04. --- .github/workflows/ci.yml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 979f012..e62daa7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,10 +14,25 @@ on: types: [ opened, reopened, synchronize ] branches: [ "main" ] +env: + CARGO_TERM_COLOR: always + permissions: contents: read jobs: + cargo: + runs-on: ubuntu-24.04 + steps: + - name: Checkout repository + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 + + - name: Build + run: cargo build --verbose + + - name: Run tests + run: cargo test --verbose + linux: runs-on: ubuntu-22.04 strategy: From 86700506711e39a865fbc4942345f130aec4d10b Mon Sep 17 00:00:00 2001 From: Wei Ji <23487320+weiji14@users.noreply.github.com> Date: Mon, 8 Jul 2024 17:37:21 +1200 Subject: [PATCH 2/4] :pushpin: Test on Rust stable, beta and nightly toolchains Test on all three release channels of Rust. --- .github/workflows/ci.yml | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e62daa7..35f9525 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,11 +21,20 @@ permissions: contents: read jobs: - cargo: + rust: runs-on: ubuntu-24.04 + strategy: + matrix: + toolchain: + - stable + - beta + - nightly steps: - name: Checkout repository - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 + uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + + - name: Update Rust toolchain + run: rustup update ${{ matrix.toolchain }} && rustup default ${{ matrix.toolchain }} - name: Build run: cargo build --verbose From 56771448d5083ffb8c25a45f247ec6563fc8bd2f Mon Sep 17 00:00:00 2001 From: Wei Ji <23487320+weiji14@users.noreply.github.com> Date: Mon, 8 Jul 2024 18:35:52 +1200 Subject: [PATCH 3/4] :triangular_flag_on_post: Add --crate-type=rlib compilation target Needed to enable doctests, otherwise `cargo test --doc` would error with "warning: doc tests are not supported for crate type(s) `cdylib` in package `cog3pio`". Xref https://users.rust-lang.org/t/how-to-run-only-the-doctests/54048/2 and https://github.com/rust-lang/cargo/issues/4717. --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 2e9a722..43531d6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,7 +7,7 @@ license = "MIT OR Apache-2.0" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [lib] name = "cog3pio" -crate-type = ["cdylib"] +crate-type = ["cdylib", "rlib"] [dependencies] bytes = "1.5.0" From bd59c1c41fc819de4fbebd54218207bf984b17bb Mon Sep 17 00:00:00 2001 From: Wei Ji <23487320+weiji14@users.noreply.github.com> Date: Mon, 8 Jul 2024 18:40:59 +1200 Subject: [PATCH 4/4] :green_heart: Fix broken doctest due to mismatched Array type Update docstring in src/lib.rs to check for an Array3 output from the read_geotiff function. Patches bca4c185e73c4cf4802b03aeb4e8da048c1ffff8. --- src/lib.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index dc1746f..1cec2fc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -19,7 +19,7 @@ //! //! use bytes::Bytes; //! use cog3pio::io::geotiff::read_geotiff; -//! use ndarray::Array2; +//! use ndarray::Array3; //! use object_store::path::Path; //! use object_store::{parse_url, GetResult, ObjectStore}; //! use tokio; @@ -38,9 +38,9 @@ //! Cursor::new(bytes) //! }; //! -//! let arr: Array2 = read_geotiff(stream).unwrap(); -//! assert_eq!(arr.dim(), (549, 549)); -//! assert_eq!(arr[[500, 500]], 0.13482364); +//! let arr: Array3 = read_geotiff(stream).unwrap(); +//! assert_eq!(arr.dim(), (1, 549, 549)); +//! assert_eq!(arr[[0, 500, 500]], 0.13482364); //! } //! ```