Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Migrate to task-based TypeScript configuration checking infrastructure
  • Loading branch information
per1234 committed Oct 7, 2024
commit 562f31420fc6338519f00dd0fe8af2f88e7f2f7d
60 changes: 60 additions & 0 deletions .github/workflows/check-tsconfig-task.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: Check TypeScript Configuration

# See: https://docs.github.com/en/actions/reference/events-that-trigger-workflows
on:
push:
paths:
- ".github/workflows/check-tsconfig-task.ya?ml"
- "**/tsconfig*.json"
- ".npmrc"
- "package.json"
- "package-lock.json"
- "Taskfile.ya?ml"
pull_request:
paths:
- ".github/workflows/check-tsconfig-task.ya?ml"
- "**/tsconfig*.json"
- ".npmrc"
- "package.json"
- "package-lock.json"
- "Taskfile.ya?ml"
schedule:
# Run every Tuesday at 8 AM UTC to catch breakage from changes to the JSON schema.
- cron: "0 8 * * TUE"
workflow_dispatch:
repository_dispatch:

jobs:
validate:
name: validate (${{ matrix.file }})
runs-on: ubuntu-latest

strategy:
fail-fast: false

matrix:
file:
- ./tsconfig.json

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version-file: package.json

- name: Install Task
uses: arduino/setup-task@v2
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
version: 3.x

- name: Validate
env:
TSCONFIG_PATH: ${{ matrix.file }}
run: |
task \
--silent \
ts:validate
65 changes: 0 additions & 65 deletions .github/workflows/check-tsconfig.yml

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[![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)
[![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)
[![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)
[![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)
[![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)
[![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)
[![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)

Expand Down
53 changes: 53 additions & 0 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ version: "3"
vars:
# Path of the primary npm-managed project:
DEFAULT_NPM_PROJECT_PATH: ./
# Last version of ajv-cli with support for the JSON schema "Draft 4" specification
SCHEMA_DRAFT_4_AJV_CLI_VERSION: 3.3.0

tasks:
build:
Expand All @@ -15,6 +17,9 @@ tasks:
desc: Check for problems with the project
deps:
- task: npm:validate
- task: ts:validate
vars:
TSCONFIG_PATH: "./tsconfig.json"

fix:
desc: Make automated corrections to the project's files
Expand Down Expand Up @@ -153,6 +158,43 @@ tasks:
- npx tsc
- npx ncc build

ts:validate:
desc: |
Validate TypeScript configuration file against its JSON schema
Environment variable parameters:
TSCONFIG_PATH: Path of the TypeScript configuration file (default: ./tsconfig.json).
vars:
# Source: https://github.com/SchemaStore/schemastore/blob/master/src/schemas/json/tsconfig.json
SCHEMA_URL: https://json.schemastore.org/tsconfig.json
SCHEMA_PATH:
sh: task utility:mktemp-file TEMPLATE="tsconfig-schema-XXXXXXXXXX.json"
INSTANCE_PATH: '{{default "./tsconfig.json" .TSCONFIG_PATH}}'
WORKING_FOLDER:
sh: task utility:mktemp-folder TEMPLATE="ts-validate-XXXXXXXXXX"
WORKING_INSTANCE_PATH:
sh: echo "{{.WORKING_FOLDER}}/$(basename "{{.INSTANCE_PATH}}")"
deps:
- task: npm:install-deps
cmds:
- |
# TypeScript allows comments in tsconfig.json.
# ajv-cli did not support comments in JSON at the 3.x version in use (support was added in a later version).
npx strip-json-comments-cli \
--no-whitespace \
"{{.INSTANCE_PATH}}" \
> "{{.WORKING_INSTANCE_PATH}}"
- |
wget \
--quiet \
--output-document="{{.SCHEMA_PATH}}" \
{{.SCHEMA_URL}}
- |
cd "{{.WORKING_FOLDER}}" # Workaround for https://github.com/npm/cli/issues/3210
npx ajv-cli@{{.SCHEMA_DRAFT_4_AJV_CLI_VERSION}} validate \
--all-errors \
-s "{{.SCHEMA_PATH}}" \
-d "{{.WORKING_INSTANCE_PATH}}"

# Make a temporary file named according to the passed TEMPLATE variable and print the path passed to stdout
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/windows-task/Taskfile.yml
utility:mktemp-file:
Expand All @@ -164,6 +206,17 @@ tasks:
vars:
RAW_PATH: "{{.RAW_PATH}}"

# Make a temporary folder named according to the passed TEMPLATE variable and print the path passed to stdout
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/windows-task/Taskfile.yml
utility:mktemp-folder:
vars:
RAW_PATH:
sh: mktemp --directory --tmpdir "{{.TEMPLATE}}"
cmds:
- task: utility:normalize-path
vars:
RAW_PATH: "{{.RAW_PATH}}"

# Print a normalized version of the path passed via the RAW_PATH variable to stdout
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/windows-task/Taskfile.yml
utility:normalize-path:
Expand Down