Skip to content

Commit 420b9a4

Browse files
committed
Add support for validating multiple schema files
1 parent c5019b2 commit 420b9a4

3 files changed

Lines changed: 123 additions & 6 deletions

File tree

README.md

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ A compatible file can be produced by downloading from the [Authzed Playground].
1616

1717
## Usage
1818

19+
### Single file validation
20+
1921
Add the following to any workflow:
2022

2123
```yaml
@@ -29,7 +31,53 @@ steps:
2931
> **Note:** The `actions/checkout` step is required before running this action.
3032
> Without it, your repository files won't be available and validation will fail with "no such file or directory".
3133

32-
The `validationfile` path should be relative to the repository root.
34+
### Multiple files validation
35+
36+
You can validate multiple files using the `validationfiles` input:
37+
38+
```yaml
39+
steps:
40+
- uses: "actions/checkout@v4"
41+
- uses: "authzed/action-spicedb-validate@v1"
42+
with:
43+
validationfiles: |
44+
schemas/schema1.zaml
45+
schemas/schema2.zaml
46+
```
47+
48+
Comma-separated values are also supported:
49+
50+
```yaml
51+
steps:
52+
- uses: "actions/checkout@v4"
53+
- uses: "authzed/action-spicedb-validate@v1"
54+
with:
55+
validationfiles: "schemas/schema1.zaml, schemas/schema2.zaml"
56+
```
57+
58+
You can also use glob patterns (including recursive `**` patterns):
59+
60+
```yaml
61+
steps:
62+
- uses: "actions/checkout@v4"
63+
- uses: "authzed/action-spicedb-validate@v1"
64+
with:
65+
validationfiles: "schemas/**/*.zaml"
66+
```
67+
68+
### Inputs
69+
70+
| Input | Description | Required |
71+
|-------|-------------|----------|
72+
| `validationfile` | Path to a single YAML file to validate | No* |
73+
| `validationfiles` | List of paths to validate (newline or comma separated, supports glob patterns including `**`) | No* |
74+
| `fail-on-warn` | Whether validation warnings should cause the validation to fail | No |
75+
76+
\* At least one of `validationfile` or `validationfiles` must be provided.
77+
78+
The `validationfile`/`validationfiles` paths should be relative to the repository root.
79+
80+
> **Note:** File paths with spaces are supported when using newline-separated literal paths or the single `validationfile` input. Glob patterns in paths with spaces may not expand correctly. Filenames containing literal glob characters (`*`, `?`, `[`) or commas must use the single `validationfile` input.
3381

3482
See [test-schema.zaml] for an example of an input file.
3583

action.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@ description: "Runs the `zed validate` command on the provided schema and test da
44
author: "authzed"
55
inputs:
66
validationfile:
7-
description: "path to the YAML file containing schema, test relationships, assertions and expected relations"
8-
required: true
7+
description: "path to the YAML file containing schema, test relationships, assertions and expected relations (for single file validation)"
8+
required: false
9+
validationfiles:
10+
description: "list of paths to YAML files to validate (newline or comma separated, supports glob patterns)"
11+
required: false
912
fail-on-warn:
1013
description: "whether validation warnings should cause the validation to fail"
1114
required: false

entrypoint.sh

Lines changed: 69 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,72 @@
1-
#/bin/bash
2-
ARGS=""
1+
#!/bin/bash
2+
set -e
3+
4+
# Enable recursive globbing for ** patterns (bash 4+)
5+
# Guard for bash 3.x compatibility (e.g., macOS default)
6+
shopt -s nullglob
7+
shopt -s globstar 2>/dev/null || true
38

9+
ARGS=""
410
[[ $INPUT_FAIL_ON_WARN == "true" ]] && ARGS+=" --fail-on-warn"
511

6-
/zed validate $ARGS $INPUT_VALIDATIONFILE
12+
# Collect all files to validate
13+
FILES=()
14+
HAD_INPUT=0
15+
16+
# Handle single file input (backward compatibility)
17+
if [[ -n "$INPUT_VALIDATIONFILE" ]]; then
18+
HAD_INPUT=1
19+
FILES+=("$INPUT_VALIDATIONFILE")
20+
fi
21+
22+
# Handle multiple files input
23+
if [[ -n "$INPUT_VALIDATIONFILES" ]]; then
24+
HAD_INPUT=1
25+
# Replace commas with newlines and process each entry
26+
# Use printf instead of echo to avoid option interpretation
27+
while IFS= read -r entry; do
28+
# Trim leading/trailing whitespace without breaking spaces in paths
29+
entry="${entry#"${entry%%[![:space:]]*}"}"
30+
entry="${entry%"${entry##*[![:space:]]}"}"
31+
[[ -z "$entry" ]] && continue
32+
33+
# Check if entry contains glob pattern characters
34+
if [[ "$entry" == *"*"* || "$entry" == *"?"* || "$entry" == *"["* ]]; then
35+
# Expand glob pattern safely without eval (globstar enabled for ** support)
36+
# Use an array assignment for safe glob expansion
37+
expanded=()
38+
# shellcheck disable=SC2206
39+
expanded=($entry)
40+
for file in "${expanded[@]}"; do
41+
[[ -f "$file" ]] && FILES+=("$file")
42+
done
43+
else
44+
FILES+=("$entry")
45+
fi
46+
done <<< "$(printf '%s\n' "$INPUT_VALIDATIONFILES" | tr ',' '\n')"
47+
fi
48+
49+
# Check if we have any files to validate
50+
if [[ $HAD_INPUT -eq 0 ]]; then
51+
echo "Error: No validation files provided. Set either 'validationfile' or 'validationfiles' input."
52+
exit 1
53+
fi
54+
55+
if [[ ${#FILES[@]} -eq 0 ]]; then
56+
echo "Error: No files matched the provided patterns."
57+
exit 1
58+
fi
59+
60+
# Validate each file
61+
FAILED=0
62+
for file in "${FILES[@]}"; do
63+
echo "Validating $file..."
64+
# ARGS is intentionally unquoted for word splitting (may be empty or --fail-on-warn)
65+
# Use -- to prevent filenames starting with - from being interpreted as options
66+
# shellcheck disable=SC2086
67+
if ! /zed validate $ARGS -- "$file"; then
68+
FAILED=1
69+
fi
70+
done
71+
72+
exit $FAILED

0 commit comments

Comments
 (0)