Skip to content

Commit dba1ead

Browse files
ci(ocr): validate optional feature (#404)
* ci(ocr): validate optional feature * ci(ocr): preserve test fixture line endings * ci(ocr): verify ONNX Runtime archive
1 parent 264a1c8 commit dba1ead

2 files changed

Lines changed: 112 additions & 1 deletion

File tree

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*.pdf binary
2+
tests/snapshots/*.md text eol=lf

.github/workflows/ci.yml

Lines changed: 110 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ on:
99
env:
1010
CARGO_TERM_COLOR: always
1111

12+
permissions:
13+
contents: read
14+
1215
jobs:
1316
test:
1417
name: Test
@@ -68,9 +71,12 @@ jobs:
6871
with:
6972
key: clippy
7073

71-
- name: Run clippy
74+
- name: Run default clippy
7275
run: cargo clippy -- -D warnings
7376

77+
- name: Run OCR clippy
78+
run: cargo clippy --features ocr -- -D warnings
79+
7480
build:
7581
name: Build
7682
runs-on: ${{ matrix.os }}
@@ -93,6 +99,109 @@ jobs:
9399
- name: Build
94100
run: cargo build --release --verbose
95101

102+
ocr:
103+
name: OCR (${{ matrix.os }})
104+
runs-on: ${{ matrix.os }}
105+
strategy:
106+
fail-fast: false
107+
matrix:
108+
os: [ubuntu-latest, macos-latest, windows-latest]
109+
steps:
110+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
111+
112+
- name: Install Rust
113+
uses: dtolnay/rust-toolchain@4cda84d5c5c54efe2404f9d843567869ab1699d4 # stable
114+
with:
115+
toolchain: stable
116+
117+
- name: Cache cargo
118+
uses: Swatinem/rust-cache@c19371144df3bb44fab255c43d04cbc2ab54d1c4 # v2.9.1
119+
with:
120+
key: ocr-${{ matrix.os }}
121+
122+
- name: Test optional OCR feature
123+
run: cargo test --features ocr
124+
125+
ocr-runtime:
126+
name: OCR runtime smoke
127+
runs-on: ubuntu-latest
128+
timeout-minutes: 30
129+
steps:
130+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
131+
132+
- name: Install Rust
133+
uses: dtolnay/rust-toolchain@4cda84d5c5c54efe2404f9d843567869ab1699d4 # stable
134+
with:
135+
toolchain: stable
136+
137+
- name: Cache cargo
138+
uses: Swatinem/rust-cache@c19371144df3bb44fab255c43d04cbc2ab54d1c4 # v2.9.1
139+
with:
140+
key: ocr-runtime
141+
142+
- name: Install PDFium
143+
shell: bash
144+
run: |
145+
archive="$RUNNER_TEMP/firecrawl-pdfium-linux-x64.tgz"
146+
directory="$RUNNER_TEMP/firecrawl-pdfium"
147+
curl --fail --location --silent --show-error \
148+
https://github.com/firecrawl/pdfium-rs/releases/download/native-v7988/firecrawl-pdfium-linux-x64.tgz \
149+
--output "$archive"
150+
echo "6248189e07bbc33cdeb31976c539a88614307c8a19f3276dbd018efbe5b4a2a2 $archive" | sha256sum --check
151+
mkdir -p "$directory"
152+
tar -xzf "$archive" -C "$directory"
153+
pdfium_path="$(find "$directory" -type f -name 'libpdfium.so' -print -quit)"
154+
test -n "$pdfium_path"
155+
echo "PDFIUM_LIB_PATH=$pdfium_path" >> "$GITHUB_ENV"
156+
157+
- name: Install ONNX Runtime
158+
shell: bash
159+
run: |
160+
archive="$RUNNER_TEMP/onnxruntime-linux-x64-1.27.0.tgz"
161+
directory="$RUNNER_TEMP/onnxruntime"
162+
curl --fail --location --silent --show-error \
163+
https://github.com/microsoft/onnxruntime/releases/download/v1.27.0/onnxruntime-linux-x64-1.27.0.tgz \
164+
--output "$archive"
165+
echo "547e40a48f1fe73e3f812d7c88a948612c23f896b91e4e2ee1e232d7b468246f $archive" | sha256sum --check
166+
mkdir -p "$directory"
167+
tar -xzf "$archive" -C "$directory"
168+
ort_path="$(find "$directory" -type f -name 'libonnxruntime.so*' -print -quit)"
169+
test -n "$ort_path"
170+
echo "ORT_DYLIB_PATH=$ort_path" >> "$GITHUB_ENV"
171+
172+
- name: Build OCR CLI
173+
run: cargo build --features ocr --bin pdf2md
174+
175+
- name: Test PDFium runtime
176+
run: cargo test --features ocr --test local_render_tests
177+
178+
- name: Run OCR CLI
179+
shell: bash
180+
run: |
181+
target/debug/pdf2md \
182+
tests/fixtures/scan_with_native_header_text.pdf \
183+
--ocr auto \
184+
--json > "$RUNNER_TEMP/ocr-result.json"
185+
186+
- name: Validate OCR JSON contract
187+
shell: bash
188+
run: |
189+
python3 - <<'PY'
190+
import json
191+
import os
192+
from pathlib import Path
193+
194+
result = json.loads(
195+
(Path(os.environ["RUNNER_TEMP"]) / "ocr-result.json").read_text()
196+
)
197+
assert result["schema_version"] == 1
198+
assert result["pages_routed_to_ocr"] == [1]
199+
assert result["pages_recommending_hosted"] == []
200+
assert result["pages"][0]["source"] in {"ocr", "fused"}
201+
assert result["pages"][0]["markdown"].strip()
202+
assert "layout_ms" not in result["pages"][0]["timings"]
203+
PY
204+
96205
wasm:
97206
name: WebAssembly
98207
runs-on: ubuntu-latest

0 commit comments

Comments
 (0)