Skip to content

Commit d220733

Browse files
Add GitHub Action for JavaScript type checking.
This introduces a new GitHub Action workflow for JavaScript type checking, mirroring the implementation for PHPStan. It also adds a `typecheck:js` Grunt task and includes it in the `precommit:js` task list. Co-authored-by: gemini-cli <176961590+gemini-code-assist[bot]@users.noreply.github.com>
1 parent b6c1bb7 commit d220733

3 files changed

Lines changed: 223 additions & 0 deletions

File tree

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
name: JavaScript Type Checking
2+
3+
on:
4+
# JavaScript type checking was introduced in 7.0.0.
5+
push:
6+
branches:
7+
- trunk
8+
- '[7-9].[0-9]'
9+
tags:
10+
- '[7-9].[0-9]'
11+
- '[7-9]+.[0-9].[0-9]+'
12+
pull_request:
13+
branches:
14+
- trunk
15+
- '[7-9].[0-9]'
16+
paths:
17+
# This workflow only scans JavaScript files.
18+
- '**.js'
19+
# These files configure npm. Changes could affect the outcome.
20+
- 'package*.json'
21+
- '.nvmrc'
22+
# This file configures TypeScript. Changes could affect the outcome.
23+
- 'tsconfig.json'
24+
# This directory contains TypeScript definitions. Changes could affect the outcome.
25+
- 'typings/**'
26+
# Confirm any changes to relevant workflow files.
27+
- '.github/workflows/javascript-type-checking.yml'
28+
- '.github/workflows/reusable-javascript-type-checking.yml'
29+
workflow_dispatch:
30+
31+
# Cancels all previous workflow runs for pull requests that have not completed.
32+
concurrency:
33+
# The concurrency group contains the workflow name and the branch name for pull requests
34+
# or the commit hash for any other events.
35+
group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.head_ref || github.sha }}
36+
cancel-in-progress: true
37+
38+
# Disable permissions for all available scopes by default.
39+
# Any needed permissions should be configured at the job level.
40+
permissions: {}
41+
42+
jobs:
43+
# Runs JavaScript type checking.
44+
typecheck:
45+
name: JavaScript type checking
46+
uses: ./.github/workflows/reusable-javascript-type-checking.yml
47+
permissions:
48+
contents: read
49+
if: ${{ github.repository == 'WordPress/wordpress-develop' || ( github.event_name == 'pull_request' && github.actor != 'dependabot[bot]' ) }}
50+
51+
slack-notifications:
52+
name: Slack Notifications
53+
uses: ./.github/workflows/slack-notifications.yml
54+
permissions:
55+
actions: read
56+
contents: read
57+
needs: [ typecheck ]
58+
if: ${{ github.repository == 'WordPress/wordpress-develop' && github.event_name != 'pull_request' && always() }}
59+
with:
60+
calling_status: ${{ contains( needs.*.result, 'cancelled' ) && 'cancelled' || contains( needs.*.result, 'failure' ) && 'failure' || 'success' }}
61+
secrets:
62+
SLACK_GHA_SUCCESS_WEBHOOK: ${{ secrets.SLACK_GHA_SUCCESS_WEBHOOK }}
63+
SLACK_GHA_CANCELLED_WEBHOOK: ${{ secrets.SLACK_GHA_CANCELLED_WEBHOOK }}
64+
SLACK_GHA_FIXED_WEBHOOK: ${{ secrets.SLACK_GHA_FIXED_WEBHOOK }}
65+
SLACK_GHA_FAILURE_WEBHOOK: ${{ secrets.SLACK_GHA_FAILURE_WEBHOOK }}
66+
67+
failed-workflow:
68+
name: Failed workflow tasks
69+
runs-on: ubuntu-24.04
70+
permissions:
71+
actions: write
72+
needs: [ slack-notifications ]
73+
if: |
74+
always() &&
75+
github.repository == 'WordPress/wordpress-develop' &&
76+
github.event_name != 'pull_request' &&
77+
github.run_attempt < 2 &&
78+
(
79+
contains( needs.*.result, 'cancelled' ) ||
80+
contains( needs.*.result, 'failure' )
81+
)
82+
83+
steps:
84+
- name: Dispatch workflow run
85+
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
86+
with:
87+
retries: 2
88+
retry-exempt-status-codes: 418
89+
script: |
90+
github.rest.actions.createWorkflowDispatch({
91+
owner: context.repo.owner,
92+
repo: context.repo.repo,
93+
workflow_id: 'failed-workflow.yml',
94+
ref: 'trunk',
95+
inputs: {
96+
run_id: `${context.runId}`,
97+
}
98+
});
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
##
2+
# A reusable workflow that runs JavaScript Type Checking.
3+
##
4+
name: JavaScript Type Checking
5+
6+
on:
7+
workflow_call:
8+
inputs:
9+
php-version:
10+
description: 'The PHP version to use.'
11+
required: false
12+
type: 'string'
13+
default: 'latest'
14+
15+
# Disable permissions for all available scopes by default.
16+
# Any needed permissions should be configured at the job level.
17+
permissions: {}
18+
19+
jobs:
20+
# Runs JavaScript type checking.
21+
#
22+
# Violations are reported inline with annotations.
23+
#
24+
# Performs the following steps:
25+
# - Checks out the repository.
26+
# - Sets up Node.js.
27+
# - Sets up PHP.
28+
# - Logs debug information.
29+
# - Installs Composer dependencies.
30+
# - Make Composer packages available globally.
31+
# - Installs npm dependencies.
32+
# - Build WordPress.
33+
# - Configures caching for TypeScript build info.
34+
# - Runs JavaScript type checking.
35+
# - Saves the TypeScript build info.
36+
# - Ensures version-controlled files are not modified or deleted.
37+
typecheck:
38+
name: Run JavaScript type checking
39+
runs-on: ubuntu-24.04
40+
permissions:
41+
contents: read
42+
timeout-minutes: 20
43+
44+
steps:
45+
- name: Checkout repository
46+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
47+
with:
48+
show-progress: ${{ runner.debug == '1' && 'true' || 'false' }}
49+
persist-credentials: false
50+
51+
- name: Set up Node.js
52+
uses: actions/setup-node@2028fbc5c25fe9cf00d9f06a71cc4710d4507903 # v6.0.0
53+
with:
54+
node-version-file: '.nvmrc'
55+
cache: npm
56+
57+
- name: Set up PHP
58+
uses: shivammathur/setup-php@20529878ed81ef8e78ddf08b480401e6101a850f # v2.35.3
59+
with:
60+
php-version: ${{ inputs.php-version }}
61+
coverage: none
62+
63+
# This date is used to ensure that the Composer cache is cleared at least once every week.
64+
# http://man7.org/linux/man-pages/man1/date.1.html
65+
- name: "Get last Monday's date"
66+
id: get-date
67+
run: echo "date=$(/bin/date -u --date='last Mon' "+%F")" >> "$GITHUB_OUTPUT"
68+
69+
- name: Log debug information
70+
run: |
71+
npm --version
72+
node --version
73+
composer --version
74+
75+
# Since Composer dependencies are installed using `composer update` and no lock file is in version control,
76+
# passing a custom cache suffix ensures that the cache is flushed at least once per week.
77+
- name: Install Composer dependencies
78+
uses: ramsey/composer-install@3cf229dc2919194e9e36783941438d17239e8520 # v3.1.1
79+
with:
80+
custom-cache-suffix: ${{ steps.get-date.outputs.date }}
81+
82+
- name: Make Composer packages available globally
83+
run: echo "${PWD}/vendor/bin" >> "$GITHUB_PATH"
84+
85+
- name: Install npm dependencies
86+
run: npm ci --ignore-scripts
87+
88+
- name: Build WordPress
89+
run: npm run build:dev
90+
91+
- name: Cache TypeScript build info
92+
uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
93+
with:
94+
path: |
95+
*.tsbuildinfo
96+
key: "ts-build-info-${{ github.run_id }}"
97+
restore-keys: |
98+
ts-build-info-
99+
100+
- name: Run JavaScript type checking
101+
run: npm run typecheck:js
102+
103+
- name: "Save result cache"
104+
uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
105+
if: ${{ !cancelled() }}
106+
with:
107+
path: |
108+
*.tsbuildinfo
109+
key: "ts-build-info-${{ github.run_id }}"
110+
111+
- name: Ensure version-controlled files are not modified or deleted
112+
run: git diff --exit-code

Gruntfile.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1556,6 +1556,7 @@ module.exports = function(grunt) {
15561556
grunt.registerTask( 'precommit:js', [
15571557
'webpack:prod',
15581558
'jshint:corejs',
1559+
'typecheck:js',
15591560
'uglify:imgareaselect',
15601561
'uglify:jqueryform',
15611562
'uglify:moment',
@@ -2009,6 +2010,18 @@ module.exports = function(grunt) {
20092010

20102011
grunt.registerTask( 'test', 'Runs all QUnit and PHPUnit tasks.', ['qunit:compiled', 'phpunit'] );
20112012

2013+
grunt.registerTask( 'typecheck:js', 'Runs TypeScript type checking.', function() {
2014+
var done = this.async();
2015+
2016+
grunt.util.spawn( {
2017+
cmd: 'npm',
2018+
args: [ 'run', 'typecheck:js' ],
2019+
opts: { stdio: 'inherit' }
2020+
}, function( error ) {
2021+
done( ! error );
2022+
} );
2023+
} );
2024+
20122025
grunt.registerTask( 'phpstan', 'Runs PHPStan on the entire codebase.', function() {
20132026
var done = this.async();
20142027

0 commit comments

Comments
 (0)