Skip to content

Commit 71c57c5

Browse files
Add CI workflow to validate tsconfig files
On every push or pull request that affects the repository's tsconfig files, and periodically, validate them against the JSON schema.
1 parent 64e2156 commit 71c57c5

File tree

3 files changed

+87
-0
lines changed

3 files changed

+87
-0
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: Check TypeScript Configuration
2+
3+
env:
4+
# See: https://github.com/actions/setup-node/#readme
5+
NODE_VERSION: 16.x
6+
7+
# See: https://docs.github.com/en/actions/reference/events-that-trigger-workflows
8+
on:
9+
push:
10+
paths:
11+
- ".github/workflows/check-tsconfig-task.ya?ml"
12+
- "**/tsconfig*.json"
13+
- "Taskfile.ya?ml"
14+
pull_request:
15+
paths:
16+
- ".github/workflows/check-tsconfig-task.ya?ml"
17+
- "**/tsconfig*.json"
18+
- "Taskfile.ya?ml"
19+
schedule:
20+
# Run every Tuesday at 8 AM UTC to catch breakage from changes to the JSON schema.
21+
- cron: "0 8 * * TUE"
22+
workflow_dispatch:
23+
repository_dispatch:
24+
25+
jobs:
26+
validate:
27+
runs-on: ubuntu-latest
28+
29+
strategy:
30+
fail-fast: false
31+
32+
matrix:
33+
file:
34+
- ./tsconfig.json
35+
36+
steps:
37+
- name: Checkout repository
38+
uses: actions/checkout@v3
39+
40+
- name: Setup Node.js
41+
uses: actions/setup-node@v3
42+
with:
43+
node-version: ${{ env.NODE_VERSION }}
44+
45+
- name: Install Task
46+
uses: arduino/setup-task@v1
47+
with:
48+
repo-token: ${{ secrets.GITHUB_TOKEN }}
49+
version: 3.x
50+
51+
- name: Validate ${{ matrix.file }}
52+
env:
53+
TSCONFIG_PATH: ${{ matrix.file }}
54+
run: task --silent ts:validate

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
[![Check Taskfiles status](https://github.com/arduino/setup-protoc/actions/workflows/check-taskfiles.yml/badge.svg)](https://github.com/arduino/setup-protoc/actions/workflows/check-taskfiles.yml)
99
[![Integration Tests status](https://github.com/arduino/setup-protoc/actions/workflows/test-integration.yml/badge.svg)](https://github.com/arduino/setup-protoc/actions/workflows/test-integration.yml)
1010
[![Check npm status](https://github.com/arduino/setup-protoc/actions/workflows/check-npm-task.yml/badge.svg)](https://github.com/arduino/setup-protoc/actions/workflows/check-npm-task.yml)
11+
[![Check tsconfig status](https://github.com/arduino/setup-protoc/actions/workflows/check-tsconfig-task.yml/badge.svg)](https://github.com/arduino/setup-protoc/actions/workflows/check-tsconfig-task.yml)
1112

1213
This action makes the `protoc` compiler available to Workflows.
1314

Taskfile.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,38 @@ tasks:
185185
-r "{{.STYLELINTRC_SCHEMA_PATH}}" \
186186
-d "{{.PROJECT_FOLDER}}/{{.INSTANCE_PATH}}"
187187
188+
ts:validate:
189+
desc: Validate TypeScript configuration file against its JSON schema
190+
vars:
191+
# Source: https://github.com/SchemaStore/schemastore/blob/master/src/schemas/json/tsconfig.json
192+
SCHEMA_URL: https://json.schemastore.org/tsconfig.json
193+
SCHEMA_PATH:
194+
sh: task utility:mktemp-file TEMPLATE="tsconfig-schema-XXXXXXXXXX.json"
195+
INSTANCE_PATH: '{{default "./tsconfig.json" .TSCONFIG_PATH}}'
196+
WORKING_FOLDER:
197+
sh: task utility:mktemp-folder TEMPLATE="ts-validate-XXXXXXXXXX"
198+
WORKING_INSTANCE_PATH:
199+
sh: echo "{{.WORKING_FOLDER}}/$(basename "{{.INSTANCE_PATH}}")"
200+
cmds:
201+
- |
202+
# TypeScript allows comments in tsconfig.json.
203+
# ajv-cli did not support comments in JSON at the 3.x version in use (support was added in a later version).
204+
npx strip-json-comments-cli \
205+
--no-whitespace \
206+
"{{.INSTANCE_PATH}}" \
207+
> "{{.WORKING_INSTANCE_PATH}}"
208+
- |
209+
wget \
210+
--quiet \
211+
--output-document="{{.SCHEMA_PATH}}" \
212+
{{.SCHEMA_URL}}
213+
- |
214+
cd "{{.WORKING_FOLDER}}" # Workaround for https://github.com/npm/cli/issues/3210
215+
npx ajv-cli@{{.SCHEMA_DRAFT_4_AJV_CLI_VERSION}} validate \
216+
--all-errors \
217+
-s "{{.SCHEMA_PATH}}" \
218+
-d "{{.WORKING_INSTANCE_PATH}}"
219+
188220
# Make a temporary file named according to the passed TEMPLATE variable and print the path passed to stdout
189221
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/windows-task/Taskfile.yml
190222
utility:mktemp-file:

0 commit comments

Comments
 (0)