Skip to content

Commit 6be92e2

Browse files
committed
Add STAC validation to build process using gostac-validator
Validates all generated STAC catalog and collection JSON files against the STAC spec after each build to ensure ecosystem compatibility. The validator is built from source on first run and cached in .cache/. https://claude.ai/code/session_01HqPu7U8YpWHFqhJJRAMUtq
1 parent 521a8c6 commit 6be92e2

2 files changed

Lines changed: 57 additions & 2 deletions

File tree

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44
"description": "",
55
"main": "index.js",
66
"scripts": {
7-
"build": "npx @11ty/eleventy",
7+
"build": "npx @11ty/eleventy && npm run validate:stac",
88
"start": "npx @11ty/eleventy --serve --port=8081",
9-
"clean": "rm -r docs .cache"
9+
"clean": "rm -r docs .cache",
10+
"validate:stac": "bash scripts/validate-stac.sh"
1011
},
1112
"repository": {
1213
"type": "git",

scripts/validate-stac.sh

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
5+
PROJECT_DIR="$(dirname "$SCRIPT_DIR")"
6+
STAC_DIR="$PROJECT_DIR/docs/stac"
7+
VALIDATOR_DIR="$PROJECT_DIR/.cache/gostac-validator"
8+
VALIDATOR_BIN="$VALIDATOR_DIR/stac-cli"
9+
VALIDATOR_REPO="https://github.com/StacLabs/gostac-validator.git"
10+
11+
# Build the validator if not already present
12+
if [ ! -x "$VALIDATOR_BIN" ]; then
13+
echo "Building gostac-validator..."
14+
rm -rf "$VALIDATOR_DIR"
15+
git clone --depth 1 "$VALIDATOR_REPO" "$VALIDATOR_DIR"
16+
cd "$VALIDATOR_DIR"
17+
go build -o stac-cli ./cmd/cli
18+
cd "$PROJECT_DIR"
19+
echo "gostac-validator built successfully."
20+
fi
21+
22+
# Check that the STAC output directory exists
23+
if [ ! -d "$STAC_DIR" ]; then
24+
echo "Error: STAC output directory not found at $STAC_DIR"
25+
echo "Run 'npm run build' first to generate the STAC catalog."
26+
exit 1
27+
fi
28+
29+
# Find all STAC JSON files and validate them
30+
STAC_FILES=$(find "$STAC_DIR" -name '*.json' -type f)
31+
FILE_COUNT=$(echo "$STAC_FILES" | wc -l)
32+
echo "Validating $FILE_COUNT STAC file(s) in $STAC_DIR..."
33+
34+
FAILED=0
35+
for file in $STAC_FILES; do
36+
RELATIVE=$(echo "$file" | sed "s|$PROJECT_DIR/||")
37+
OUTPUT=$("$VALIDATOR_BIN" "$file" 2>&1) || true
38+
39+
if echo "$OUTPUT" | grep -q '"valid": true'; then
40+
echo "$RELATIVE"
41+
else
42+
echo "$RELATIVE"
43+
echo "$OUTPUT" | sed 's/^/ /'
44+
FAILED=$((FAILED + 1))
45+
fi
46+
done
47+
48+
echo ""
49+
if [ "$FAILED" -gt 0 ]; then
50+
echo "STAC validation failed: $FAILED file(s) invalid."
51+
exit 1
52+
else
53+
echo "All $FILE_COUNT STAC file(s) are valid."
54+
fi

0 commit comments

Comments
 (0)