-
Notifications
You must be signed in to change notification settings - Fork 0
54 lines (47 loc) · 2.12 KB
/
tests-jsonschema.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
name: ✅ Tests JSON schema 🔲
on:
push:
branches:
- "**"
paths:
- "**/values.schema.json"
- "**/*.values.schema.json"
- ".github/jsonschema/**"
- ".github/workflows/tests-jsonschema.yml"
concurrency:
cancel-in-progress: true
group: tests-jsonschema-${{ github.ref_name }}
jobs:
tests:
name: Test
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 20
cache: "yarn"
- name: install
run: |
# fetch kube json-schema locally and add $id for schema resolution
curl https://raw.githubusercontent.com/ad-m/kubernetes-json-schema/master/master-standalone-strict/_definitions.json | jq '. + {"$id": "https://raw.githubusercontent.com/ad-m/kubernetes-json-schema/master/master-standalone-strict/_definitions.json"}' > kube.json
- name: test valid schema
run: |
AJV_PARAMS="--spec draft7 --allow-union-types --strict=false --all-errors --errors=json --validate-formats=false -r "plugins/**/*.schema.json" -r kube.json"
echo "jsonschema-valid.yaml should have no error"
cat .github/jsonschema/jsonschema-valid.yml | yq -o=json > jsonschema-valid.json
RES=$(npx ajv-cli validate -s ./docs/values.schema.json -d jsonschema-valid.json $AJV_PARAMS)
if [ "$RES" == "jsonschema-valid.json valid" ]; then
echo "Valid schema"
else
echo "Invalid schema"
exit 1
fi
- name: test invalid schema
run: |
AJV_PARAMS="--spec draft7 --allow-union-types --strict=false --all-errors --errors=json --validate-formats=false -r "plugins/**/*.schema.json" -r kube.json"
echo "jsonschema-invalid.yaml should have 23 errors"
cat .github/jsonschema/jsonschema-invalid.yml | yq -o=json > jsonschema-invalid.json
npx ajv-cli validate -s ./docs/values.schema.json $AJV_PARAMS -d jsonschema-invalid.json 2>&1 | tail --lines=+2 > invalid-result.json
cat invalid-result.json | jq -e "length == 10"