name: CI
on:
push:
branches: [main]
pull_request:
branches: [main]
env:
CARGO_TERM_COLOR: always
jobs:
version-check:
name: Version Consistency
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Verify all package versions match
shell: bash
run: |
# Extract version strings from the four canonical files listed in
# CLAUDE.md's "Version Bump Checklist". CI fails fast when any are
# out of sync — a full release can't ship mismatched versions.
root=$(grep -m1 '^version = ' Cargo.toml | sed 's/.*"\(.*\)".*/\1/')
cli=$(grep -m1 '^version = ' cli/Cargo.toml | sed 's/.*"\(.*\)".*/\1/')
py=$(grep -m1 '^version = ' bindings/python/pyproject.toml | sed 's/.*"\(.*\)".*/\1/')
cs=$(grep -oE '<Version>[^<]+</Version>' bindings/csharp/Unpdf/Unpdf.csproj | head -1 | sed 's/<[^>]*>//g')
echo "Root Cargo.toml: $root"
echo "cli/Cargo.toml: $cli"
echo "bindings/python/pyproject.toml: $py"
echo "bindings/csharp/Unpdf/Unpdf.csproj: $cs"
# Also verify the workspace's CLI dep on unpdf points at the same
# version so consumers of the published crate aren't broken.
dep=$(grep -m1 'unpdf = { version =' cli/Cargo.toml | sed 's/.*version = "\([^"]*\)".*/\1/')
echo "cli -> unpdf dep version: $dep"
fail=0
for v in "$cli" "$py" "$cs" "$dep"; do
if [ "$v" != "$root" ]; then
fail=1
fi
done
if [ $fail -eq 1 ]; then
echo "::error::Version mismatch — update all four canonical files AND cli's unpdf dep together per CLAUDE.md Version Bump Checklist."
exit 1
fi
echo "All versions match: $root"
build:
name: Build and Test
needs: version-check
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
rust: [stable]
steps:
- uses: actions/checkout@v4
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt, clippy
- name: Cache cargo
uses: actions/cache@v4
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-
- name: Build
run: cargo build --release --all-features
- name: Run tests
run: cargo test --all-features
- name: Check formatting
run: cargo fmt --all -- --check
- name: Run Clippy
run: cargo clippy --all-features -- -D warnings
build-ffi:
name: Build FFI Library
needs: version-check
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
lib: libunpdf.so
- os: ubuntu-latest
target: x86_64-unknown-linux-musl
lib: libunpdf.so
- os: windows-latest
target: x86_64-pc-windows-msvc
lib: unpdf.dll
- os: macos-latest
target: x86_64-apple-darwin
lib: libunpdf.dylib
steps:
- uses: actions/checkout@v4
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- name: Install musl-tools
if: contains(matrix.target, 'musl')
run: sudo apt-get update && sudo apt-get install -y musl-tools
- name: Set RUSTFLAGS for musl
if: contains(matrix.target, 'musl')
run: echo "RUSTFLAGS=-C target-feature=-crt-static" >> $GITHUB_ENV
- name: Build FFI library
run: cargo build --release --features ffi --target ${{ matrix.target }}