|
| 1 | +name: Check JSON schemas consistency |
| 2 | + |
| 3 | +# The json_schemas package contains TypeScript code that generates JSON schema files. |
| 4 | +# This workflow ensures that any changes to the TypeScript code are reflected in the generated JSON schema files. |
| 5 | +# If there is a mismatch, the workflow fails, prompting the developer to regenerate the JSON schema files. |
| 6 | + |
| 7 | +on: |
| 8 | + pull_request: |
| 9 | + # List all .ts - .json file pairs that need to be kept in sync |
| 10 | + paths: |
| 11 | + - 'packages/json_schemas/src/actor.schema.ts' |
| 12 | + - 'packages/json_schemas/schemas/actor.schema.json' |
| 13 | + |
| 14 | +jobs: |
| 15 | + check_json_schemas: |
| 16 | + name: 'Check JSON schemas consistency' |
| 17 | + runs-on: ubuntu-latest |
| 18 | + steps: |
| 19 | + - uses: actions/checkout@v5 |
| 20 | + |
| 21 | + - name: Use Node.js ${{ matrix.node-version }} |
| 22 | + uses: actions/setup-node@v5 |
| 23 | + with: |
| 24 | + node-version: ${{ matrix.node-version }} |
| 25 | + |
| 26 | + - name: Cache node_modules |
| 27 | + uses: actions/cache@v4 |
| 28 | + with: |
| 29 | + path: '**/node_modules' |
| 30 | + key: ${{ runner.os }}-${{ matrix.node-version }}-modules-${{ hashFiles('**/package-lock.json') }} |
| 31 | + |
| 32 | + - name: Install Dependencies |
| 33 | + run: npm ci --no-audit |
| 34 | + - run: cd packages/json_schemas && npm run build |
| 35 | + |
| 36 | + - name: Check JSON consistency |
| 37 | + run: | |
| 38 | + files_to_check=( |
| 39 | + "packages/json_schemas/src/actor.schema.ts|packages/json_schemas/schemas/actor.schema.json" |
| 40 | + # add more ts|json pairs here |
| 41 | + ) |
| 42 | +
|
| 43 | + failed=0 |
| 44 | +
|
| 45 | + for pair in "${files_to_check[@]}"; do |
| 46 | + ts_file="${pair%%|*}" |
| 47 | + json_file="${pair##*|}" |
| 48 | +
|
| 49 | + if ! git diff --exit-code "$json_file" >/dev/null; then |
| 50 | + echo "ERROR: $json_file is out of sync with $ts_file." |
| 51 | + echo "Please update $json_file by running the build script (npm run build:json)." |
| 52 | + failed=1 |
| 53 | + fi |
| 54 | + done |
| 55 | +
|
| 56 | + if [ $failed -eq 1 ]; then |
| 57 | + exit 1 |
| 58 | + fi |
0 commit comments