Skip to content

Commit

Permalink
chore: add github validation workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
cwaldren-ld committed Mar 6, 2024
1 parent 88e25b6 commit 4e6940c
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 1 deletion.
26 changes: 26 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: CI
on:
push:
branches: [ 'main' ]
paths-ignore:
- '**.md' # Don't run CI on markdown changes.
pull_request:
branches: [ 'main', 'feat/**' ]
paths-ignore:
- '**.md'

jobs:
lints:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Validate JSON Formatting
run: |
./scripts/ci/format-json.sh
git diff-index --quiet HEAD --
- name: Validate JSON schemas
run: |
./scripts/ci/validate-json-schemas.sh
- name: Validate all SDKs are represented in data files
run: |
./scripts/ci/sdk-consistency.sh
1 change: 0 additions & 1 deletion data/releases.json

This file was deleted.

File renamed without changes.
22 changes: 22 additions & 0 deletions scripts/ci/json-schemas.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash

mapfile -t schemas < <(git grep -Fl 'https://json-schema.org' '**/*.json')

function runTest() {
primary=$(realpath --relative-to="$(pwd)" "$1")

# Build up a list of reference schemas to use, being careful to ignore the
# schema under test. If we don't skip that one, ajv will generate an error
# about duplicate $ids.
ajvFlags=()
for schema in "${schemas[@]}"; do
if [[ "$schema" != "$primary" ]]; then
ajvFlags+=(-r "${schema}")
fi
done

npx --package=ajv-cli --package=ajv-formats ajv validate --spec=draft2020 -s "$primary" "${ajvFlags[@]}" -d "$2"
}

runTest ./schemas/features.json ./data/features.json
runTest ./schemas/types.json ./data/types.json
27 changes: 27 additions & 0 deletions scripts/ci/sdk-consistency.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash

# Checks that for each SDK ID defined in sdks.json, all other files have an entry for that ID.
# If not, outputs a diff containing the missing IDs and exits with a non-zero status.

cleanup() {
rm ./data/*.json.keys
}

trap cleanup EXIT

jq -r 'values[]' ./data/sdks.json | sort > ./data/sdks.json.keys

for file in ./data/*.json; do
# Skip sdks.json itself
if [ "$file" == "./data/sdks.json" ]; then
continue
fi
jq -r 'keys[]' "$file" | sort > "$file.keys"
if diff -q sdks.json.keys "$file.keys" > /dev/null; then
echo "$file is consistent"
else
echo "$file is missing some SDK IDs:"
diff ./data/sdks.json.keys "$file.keys"
exit 1
fi
done

0 comments on commit 4e6940c

Please sign in to comment.