Skip to content

Commit d4a2802

Browse files
committed
Add support for validating multiple schema files
1 parent a6d026d commit d4a2802

3 files changed

Lines changed: 117 additions & 6 deletions

File tree

README.md

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

1717
## Usage
1818

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

2123
```yaml
2224
steps:
@@ -25,6 +27,49 @@ steps:
2527
validationfile: "myschema.zaml"
2628
```
2729
30+
### Multiple files validation
31+
32+
You can validate multiple files using the `validationfiles` input:
33+
34+
```yaml
35+
steps:
36+
- uses: "authzed/action-spicedb-validate@v1"
37+
with:
38+
validationfiles: |
39+
schemas/schema1.zaml
40+
schemas/schema2.zaml
41+
```
42+
43+
Comma-separated values are also supported:
44+
45+
```yaml
46+
steps:
47+
- uses: "authzed/action-spicedb-validate@v1"
48+
with:
49+
validationfiles: "schemas/schema1.zaml, schemas/schema2.zaml"
50+
```
51+
52+
You can also use glob patterns (including recursive `**` patterns):
53+
54+
```yaml
55+
steps:
56+
- uses: "authzed/action-spicedb-validate@v1"
57+
with:
58+
validationfiles: "schemas/**/*.zaml"
59+
```
60+
61+
### Inputs
62+
63+
| Input | Description | Required |
64+
|-------|-------------|----------|
65+
| `validationfile` | Path to a single YAML file to validate | No* |
66+
| `validationfiles` | List of paths to validate (newline or comma separated, supports glob patterns including `**`) | No* |
67+
| `fail-on-warn` | Whether validation warnings should cause the validation to fail | No |
68+
69+
\* At least one of `validationfile` or `validationfiles` must be provided.
70+
71+
> **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.
72+
2873
See [test-schema.zaml] for an example of an input file.
2974

3075
[test-schema.zaml]: test-schema.zaml

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: 66 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,69 @@
1-
#/bin/bash
2-
ARGS=""
1+
#!/bin/bash
2+
set -e
3+
4+
# Enable recursive globbing for ** patterns
5+
shopt -s globstar nullglob
36

7+
ARGS=""
48
[[ $INPUT_FAIL_ON_WARN == "true" ]] && ARGS+=" --fail-on-warn"
59

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

0 commit comments

Comments
 (0)