Skip to content

Commit 562f314

Browse files
committed
Migrate to task-based TypeScript configuration checking infrastructure
1 parent 4a1212d commit 562f314

File tree

4 files changed

+114
-66
lines changed

4 files changed

+114
-66
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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-task.ya?ml"
8+
- "**/tsconfig*.json"
9+
- ".npmrc"
10+
- "package.json"
11+
- "package-lock.json"
12+
- "Taskfile.ya?ml"
13+
pull_request:
14+
paths:
15+
- ".github/workflows/check-tsconfig-task.ya?ml"
16+
- "**/tsconfig*.json"
17+
- ".npmrc"
18+
- "package.json"
19+
- "package-lock.json"
20+
- "Taskfile.ya?ml"
21+
schedule:
22+
# Run every Tuesday at 8 AM UTC to catch breakage from changes to the JSON schema.
23+
- cron: "0 8 * * TUE"
24+
workflow_dispatch:
25+
repository_dispatch:
26+
27+
jobs:
28+
validate:
29+
name: validate (${{ matrix.file }})
30+
runs-on: ubuntu-latest
31+
32+
strategy:
33+
fail-fast: false
34+
35+
matrix:
36+
file:
37+
- ./tsconfig.json
38+
39+
steps:
40+
- name: Checkout repository
41+
uses: actions/checkout@v4
42+
43+
- name: Setup Node.js
44+
uses: actions/setup-node@v4
45+
with:
46+
node-version-file: package.json
47+
48+
- name: Install Task
49+
uses: arduino/setup-task@v2
50+
with:
51+
repo-token: ${{ secrets.GITHUB_TOKEN }}
52+
version: 3.x
53+
54+
- name: Validate
55+
env:
56+
TSCONFIG_PATH: ${{ matrix.file }}
57+
run: |
58+
task \
59+
--silent \
60+
ts:validate

.github/workflows/check-tsconfig.yml

Lines changed: 0 additions & 65 deletions
This file was deleted.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
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)
66
[![Check Prettier Formatting status](https://github.com/arduino/arduino-lint-action/actions/workflows/check-prettier-formatting-task.yml/badge.svg)](https://github.com/arduino/arduino-lint-action/actions/workflows/check-prettier-formatting-task.yml)
7-
[![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)
7+
[![Check TypeScript Configuration status](https://github.com/arduino/arduino-lint-action/actions/workflows/check-tsconfig-task.yml/badge.svg)](https://github.com/arduino/arduino-lint-action/actions/workflows/check-tsconfig-task.yml)
88
[![Check npm status](https://github.com/arduino/arduino-lint-action/actions/workflows/check-npm-task.yml/badge.svg)](https://github.com/arduino/arduino-lint-action/actions/workflows/check-npm-task.yml)
99
[![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)
1010

Taskfile.yml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ version: "3"
44
vars:
55
# Path of the primary npm-managed project:
66
DEFAULT_NPM_PROJECT_PATH: ./
7+
# Last version of ajv-cli with support for the JSON schema "Draft 4" specification
8+
SCHEMA_DRAFT_4_AJV_CLI_VERSION: 3.3.0
79

810
tasks:
911
build:
@@ -15,6 +17,9 @@ tasks:
1517
desc: Check for problems with the project
1618
deps:
1719
- task: npm:validate
20+
- task: ts:validate
21+
vars:
22+
TSCONFIG_PATH: "./tsconfig.json"
1823

1924
fix:
2025
desc: Make automated corrections to the project's files
@@ -153,6 +158,43 @@ tasks:
153158
- npx tsc
154159
- npx ncc build
155160

161+
ts:validate:
162+
desc: |
163+
Validate TypeScript configuration file against its JSON schema
164+
Environment variable parameters:
165+
TSCONFIG_PATH: Path of the TypeScript configuration file (default: ./tsconfig.json).
166+
vars:
167+
# Source: https://github.com/SchemaStore/schemastore/blob/master/src/schemas/json/tsconfig.json
168+
SCHEMA_URL: https://json.schemastore.org/tsconfig.json
169+
SCHEMA_PATH:
170+
sh: task utility:mktemp-file TEMPLATE="tsconfig-schema-XXXXXXXXXX.json"
171+
INSTANCE_PATH: '{{default "./tsconfig.json" .TSCONFIG_PATH}}'
172+
WORKING_FOLDER:
173+
sh: task utility:mktemp-folder TEMPLATE="ts-validate-XXXXXXXXXX"
174+
WORKING_INSTANCE_PATH:
175+
sh: echo "{{.WORKING_FOLDER}}/$(basename "{{.INSTANCE_PATH}}")"
176+
deps:
177+
- task: npm:install-deps
178+
cmds:
179+
- |
180+
# TypeScript allows comments in tsconfig.json.
181+
# ajv-cli did not support comments in JSON at the 3.x version in use (support was added in a later version).
182+
npx strip-json-comments-cli \
183+
--no-whitespace \
184+
"{{.INSTANCE_PATH}}" \
185+
> "{{.WORKING_INSTANCE_PATH}}"
186+
- |
187+
wget \
188+
--quiet \
189+
--output-document="{{.SCHEMA_PATH}}" \
190+
{{.SCHEMA_URL}}
191+
- |
192+
cd "{{.WORKING_FOLDER}}" # Workaround for https://github.com/npm/cli/issues/3210
193+
npx ajv-cli@{{.SCHEMA_DRAFT_4_AJV_CLI_VERSION}} validate \
194+
--all-errors \
195+
-s "{{.SCHEMA_PATH}}" \
196+
-d "{{.WORKING_INSTANCE_PATH}}"
197+
156198
# Make a temporary file named according to the passed TEMPLATE variable and print the path passed to stdout
157199
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/windows-task/Taskfile.yml
158200
utility:mktemp-file:
@@ -164,6 +206,17 @@ tasks:
164206
vars:
165207
RAW_PATH: "{{.RAW_PATH}}"
166208

209+
# Make a temporary folder named according to the passed TEMPLATE variable and print the path passed to stdout
210+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/windows-task/Taskfile.yml
211+
utility:mktemp-folder:
212+
vars:
213+
RAW_PATH:
214+
sh: mktemp --directory --tmpdir "{{.TEMPLATE}}"
215+
cmds:
216+
- task: utility:normalize-path
217+
vars:
218+
RAW_PATH: "{{.RAW_PATH}}"
219+
167220
# Print a normalized version of the path passed via the RAW_PATH variable to stdout
168221
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/windows-task/Taskfile.yml
169222
utility:normalize-path:

0 commit comments

Comments
 (0)