Skip to content

Commit 1f0e749

Browse files
committed
Add CI workflow to validate tsconfig.json files
On every push or pull request that affects the repository's TypeScript configuration files, and periodically, validate them against their JSON schema.
1 parent cd91005 commit 1f0e749

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed

.github/workflows/check-tsconfig.yml

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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.ya?ml"
8+
- "**/tsconfig*.json"
9+
pull_request:
10+
paths:
11+
- ".github/workflows/check-tsconfig.ya?ml"
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/download-file-action@v1
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 }}"

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
[![Tests Status](https://github.com/arduino/arduino-lint-action/workflows/Test%20Action/badge.svg)](https://github.com/arduino/arduino-lint-action/actions?workflow=Test+Action)
44
[![Integration Tests Status](https://github.com/arduino/arduino-lint-action/workflows/Integration%20Tests/badge.svg)](https://github.com/arduino/arduino-lint-action/actions?workflow=Integration+Tests)
55
[![Check Packaging status](https://github.com/arduino/arduino-lint-action/actions/workflows/check-packaging-ncc-typescript-npm.yml/badge.svg)](https://github.com/arduino/arduino-lint-action/actions/workflows/check-packaging-ncc-typescript-npm.yml)
6+
[![Check TypeScript Configuration status](https://github.com/arduino/arduino-lint-action/actions/workflows/check-tsconfig.yml/badge.svg)](https://github.com/arduino/arduino-lint-action/actions/workflows/check-tsconfig.yml)
67
[![Check npm status](https://github.com/arduino/arduino-lint-action/actions/workflows/check-npm.yml/badge.svg)](https://github.com/arduino/arduino-lint-action/actions/workflows/check-npm.yml)
78
[![Spellcheck Status](https://github.com/arduino/arduino-lint-action/workflows/Spell%20Check/badge.svg)](https://github.com/arduino/arduino-lint-action/actions?workflow=Spell+Check)
89

0 commit comments

Comments
 (0)