name: Rust
on:
push:
branches: [main]
tags:
- v*
pull_request:
branches: [main]
env:
CARGO_TERM_COLOR: always
jobs:
build:
name: Build & test on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
steps:
- uses: actions/checkout@v4
- name: Install dependencies (Ubuntu)
if: runner.os == 'Linux'
run: |
sudo apt update -y
sudo apt install -y gdal-bin proj-bin
- name: Install dependencies (Windows GDAL + PROJ via OSGeo4W)
if: runner.os == 'Windows'
id: osgeo4w
uses: echoix/setup-OSGeo4W@v0.2.0
with:
packages: >-
gdal
proj
- name: Verify GDAL/PROJ (Windows)
if: runner.os == 'Windows'
shell: cmd
run: |
CALL "${{ steps.osgeo4w.outputs.root }}\OSGeo4W.bat" gdalinfo --version
CALL "${{ steps.osgeo4w.outputs.root }}\OSGeo4W.bat" ogr2ogr --help > NUL
CALL "${{ steps.osgeo4w.outputs.root }}\OSGeo4W.bat" proj
- name: Rust toolchain
uses: dtolnay/rust-toolchain@stable
- name: Verify CMake (Windows)
if: runner.os == 'Windows'
shell: cmd
run: |
"C:\Program Files\CMake\bin\cmake.exe" --version
- name: Formatting
if: runner.os == 'Linux'
id: fmt
continue-on-error: true
run: cargo fmt --check
- name: Linting
if: runner.os == 'Linux'
id: lint
continue-on-error: true
run: cargo clippy --no-default-features -F cli -- -D warnings --no-deps
- name: Build
run: cargo build --no-default-features -F cli --verbose
- name: Test (Linux)
if: runner.os == 'Linux'
run: cargo test --no-default-features -F cli -- --nocapture
- name: Test (Windows)
if: runner.os == 'Windows'
shell: cmd
env:
CMAKE: C:\Program Files\CMake\bin\cmake.exe
run: |
CALL "${{ steps.osgeo4w.outputs.root }}\OSGeo4W.bat" "%USERPROFILE%\.cargo\bin\cargo.exe" test --no-default-features -F cli -- --nocapture
- name: Dry-run cargo publish
if: runner.os == 'Linux' && !startsWith(github.ref, 'refs/tags/')
run: cargo publish --dry-run
- name: Fail job if fmt failed
if: runner.os == 'Linux' && steps.fmt.outcome == 'failure'
run: |
echo "Lint (cargo clippy) failed; marking job as failed."
exit 1
- name: Fail job if lint failed
if: runner.os == 'Linux' && steps.lint.outcome == 'failure'
run: |
echo "Lint (cargo clippy) failed; marking job as failed."
exit 1
publish:
name: Publish to crates.io
runs-on: ubuntu-latest
needs: build
if: startsWith(github.ref, 'refs/tags/v')
steps:
- uses: actions/checkout@v4
- name: Rust toolchain
uses: dtolnay/rust-toolchain@stable
- name: Publish crate
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
run: cargo publish