Skip to content

Commit e64bccf

Browse files
Merge pull request #56 from MatteoPologruto/tsconfig-check
Add CI workflow to validate tsconfig files
2 parents ce629e7 + 10f1c8c commit e64bccf

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
@@ -9,6 +9,7 @@
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)
1111
[![Check TypeScript status](https://github.com/arduino/setup-protoc/actions/workflows/check-typescript-task.yml/badge.svg)](https://github.com/arduino/setup-protoc/actions/workflows/check-typescript-task.yml)
12+
[![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)
1213

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

Taskfile.yml

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

0 commit comments

Comments
 (0)