Extend precommit with more hooks #2949
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Validate model.json | |
| on: | |
| pull_request: | |
| paths: | |
| - '**/model.json' | |
| - 'profile_library/model_schema.json' | |
| - '.github/scripts/validate_model_json.py' | |
| - '.github/workflows/validate-model-json.yml' | |
| permissions: | |
| contents: read | |
| jobs: | |
| validate_model_json: | |
| name: Validate model.json | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout trusted validation code | |
| uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7 | |
| with: | |
| ref: ${{ github.event.pull_request.base.sha }} | |
| path: base | |
| persist-credentials: false | |
| - name: Checkout PR files | |
| uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7 | |
| with: | |
| ref: ${{ github.event.pull_request.head.sha }} | |
| path: pr | |
| persist-credentials: false | |
| - uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v6 | |
| with: | |
| python-version: "3.x" | |
| - name: Install validation dependencies | |
| run: python -m pip install jsonschema | |
| - uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9 | |
| name: List changed files from the PR | |
| id: list-files | |
| with: | |
| script: | | |
| const files = await github.paginate(github.rest.pulls.listFiles, { | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| pull_number: context.payload.pull_request.number | |
| }); | |
| require('fs').writeFileSync('pr/changed_files.json', JSON.stringify(files.map(file => file.filename))); | |
| - name: Initialize validation result | |
| run: | | |
| mkdir -p validation-result | |
| echo "failure" > validation-result/model_json_validation_status.txt | |
| { | |
| echo "<!-- model.json validate action comment -->" | |
| echo | |
| echo "The model.json validation workflow failed before it could write a detailed report." | |
| } > validation-result/model_json_validation_report.md | |
| - name: Validate model.json against schema | |
| working-directory: pr | |
| run: >- | |
| python ../base/.github/scripts/validate_model_json.py | |
| --schema ../base/profile_library/model_schema.json | |
| --changed-files changed_files.json | |
| --report ../validation-result/model_json_validation_report.md | |
| --status ../validation-result/model_json_validation_status.txt | |
| - name: Upload validation result | |
| if: always() | |
| uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7 | |
| with: | |
| name: model-json-validation | |
| path: | | |
| ./validation-result/model_json_validation_report.md | |
| ./validation-result/model_json_validation_status.txt |