|
| 1 | +name: Check TypeScript Configuration |
| 2 | + |
| 3 | +# See: https://docs.github.com/en/actions/reference/events-that-trigger-workflows |
| 4 | +on: |
| 5 | + push: |
| 6 | + paths: |
| 7 | + - ".github/workflows/check-tsconfig.yml" |
| 8 | + - "**/tsconfig*.json" |
| 9 | + pull_request: |
| 10 | + paths: |
| 11 | + - ".github/workflows/check-tsconfig.yml" |
| 12 | + - "**/tsconfig*.json" |
| 13 | + schedule: |
| 14 | + # Run every Tuesday at 8 AM UTC to catch breakage from changes to the JSON schema. |
| 15 | + - cron: "0 8 * * TUE" |
| 16 | + workflow_dispatch: |
| 17 | + repository_dispatch: |
| 18 | + |
| 19 | +jobs: |
| 20 | + validate: |
| 21 | + runs-on: ubuntu-latest |
| 22 | + |
| 23 | + strategy: |
| 24 | + fail-fast: false |
| 25 | + |
| 26 | + matrix: |
| 27 | + file: |
| 28 | + - ./tsconfig.json |
| 29 | + |
| 30 | + steps: |
| 31 | + - name: Checkout repository |
| 32 | + uses: actions/checkout@v2 |
| 33 | + |
| 34 | + - name: Install strip-json-comments-cli |
| 35 | + run: sudo npm install --global strip-json-comments-cli |
| 36 | + |
| 37 | + # TypeScript allows comments in tsconfig.json. So does ajv-cli, but it didn't back at the 3.x version in use. |
| 38 | + - name: Convert ${{ matrix.file }} to valid JSON |
| 39 | + id: convert |
| 40 | + run: | |
| 41 | + OUTPUT_FOLDER="${{ runner.temp }}/staging" |
| 42 | + mkdir -p "$OUTPUT_FOLDER" |
| 43 | + OUTPUT_PATH="${OUTPUT_FOLDER}/$(basename ${{ matrix.file }})" |
| 44 | + strip-json-comments --no-whitespace "${{ matrix.file }}" > "$OUTPUT_PATH" |
| 45 | + echo "::set-output name=output-path::$OUTPUT_PATH" |
| 46 | +
|
| 47 | + - name: Download JSON schema for tsconfig.json |
| 48 | + id: download-schema |
| 49 | + uses: carlosperate/[email protected] |
| 50 | + with: |
| 51 | + # See: https://github.com/SchemaStore/schemastore/blob/master/src/schemas/json/tsconfig.json |
| 52 | + file-url: https://json.schemastore.org/tsconfig.json |
| 53 | + location: ${{ runner.temp }}/tsconfig-json-schema |
| 54 | + file-name: tsconfig-json-schema.json |
| 55 | + |
| 56 | + - name: Install JSON schema validator |
| 57 | + # tsconfig.json schema is draft-04, which is not supported by ajv-cli >=4. |
| 58 | + run: sudo npm install --global [email protected] |
| 59 | + |
| 60 | + - name: Validate ${{ matrix.file }} |
| 61 | + # See: https://github.com/ajv-validator/ajv-cli#readme |
| 62 | + run: | |
| 63 | + ajv validate \ |
| 64 | + -s "${{ steps.download-schema.outputs.file-path }}" \ |
| 65 | + -d "${{ steps.convert.outputs.output-path }}" |
0 commit comments