diff --git a/.github/workflows/javascript-type-checking.yml b/.github/workflows/javascript-type-checking.yml new file mode 100644 index 0000000000000..2cafb4c8d04fd --- /dev/null +++ b/.github/workflows/javascript-type-checking.yml @@ -0,0 +1,100 @@ +name: JavaScript Type Checking + +on: + # JavaScript type checking was introduced in 7.0.0. + push: + branches: + - trunk + - '[7-9].[0-9]' + tags: + - '[7-9].[0-9]' + - '[7-9]+.[0-9].[0-9]+' + pull_request: + branches: + - trunk + - '[7-9].[0-9]' + paths: + # This workflow only scans JavaScript files. + - '**.js' + - '**.ts' + - '**.tsx' + # These files configure npm. Changes could affect the outcome. + - 'package*.json' + - '.nvmrc' + # This file configures TypeScript. Changes could affect the outcome. + - 'tsconfig.json' + # This directory contains TypeScript definitions. Changes could affect the outcome. + - 'typings/**' + # Confirm any changes to relevant workflow files. + - '.github/workflows/javascript-type-checking.yml' + - '.github/workflows/reusable-javascript-type-checking.yml' + workflow_dispatch: + +# Cancels all previous workflow runs for pull requests that have not completed. +concurrency: + # The concurrency group contains the workflow name and the branch name for pull requests + # or the commit hash for any other events. + group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.head_ref || github.sha }} + cancel-in-progress: true + +# Disable permissions for all available scopes by default. +# Any needed permissions should be configured at the job level. +permissions: {} + +jobs: + # Runs JavaScript type checking. + typecheck: + name: JavaScript type checking + uses: ./.github/workflows/reusable-javascript-type-checking.yml + permissions: + contents: read + if: ${{ github.repository == 'WordPress/wordpress-develop' || ( github.event_name == 'pull_request' && github.actor != 'dependabot[bot]' ) }} + + slack-notifications: + name: Slack Notifications + uses: ./.github/workflows/slack-notifications.yml + permissions: + actions: read + contents: read + needs: [ typecheck ] + if: ${{ github.repository == 'WordPress/wordpress-develop' && github.event_name != 'pull_request' && always() }} + with: + calling_status: ${{ contains( needs.*.result, 'cancelled' ) && 'cancelled' || contains( needs.*.result, 'failure' ) && 'failure' || 'success' }} + secrets: + SLACK_GHA_SUCCESS_WEBHOOK: ${{ secrets.SLACK_GHA_SUCCESS_WEBHOOK }} + SLACK_GHA_CANCELLED_WEBHOOK: ${{ secrets.SLACK_GHA_CANCELLED_WEBHOOK }} + SLACK_GHA_FIXED_WEBHOOK: ${{ secrets.SLACK_GHA_FIXED_WEBHOOK }} + SLACK_GHA_FAILURE_WEBHOOK: ${{ secrets.SLACK_GHA_FAILURE_WEBHOOK }} + + failed-workflow: + name: Failed workflow tasks + runs-on: ubuntu-24.04 + permissions: + actions: write + needs: [ slack-notifications ] + if: | + always() && + github.repository == 'WordPress/wordpress-develop' && + github.event_name != 'pull_request' && + github.run_attempt < 2 && + ( + contains( needs.*.result, 'cancelled' ) || + contains( needs.*.result, 'failure' ) + ) + + steps: + - name: Dispatch workflow run + uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0 + with: + retries: 2 + retry-exempt-status-codes: 418 + script: | + github.rest.actions.createWorkflowDispatch({ + owner: context.repo.owner, + repo: context.repo.repo, + workflow_id: 'failed-workflow.yml', + ref: 'trunk', + inputs: { + run_id: `${context.runId}`, + } + }); diff --git a/.github/workflows/phpstan-static-analysis.yml b/.github/workflows/phpstan-static-analysis.yml index 9bb12e40927e2..85f492e5f13af 100644 --- a/.github/workflows/phpstan-static-analysis.yml +++ b/.github/workflows/phpstan-static-analysis.yml @@ -81,7 +81,7 @@ jobs: steps: - name: Dispatch workflow run - uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 + uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0 with: retries: 2 retry-exempt-status-codes: 418 diff --git a/.github/workflows/reusable-javascript-type-checking.yml b/.github/workflows/reusable-javascript-type-checking.yml new file mode 100644 index 0000000000000..3737bba6abb74 --- /dev/null +++ b/.github/workflows/reusable-javascript-type-checking.yml @@ -0,0 +1,76 @@ +## +# A reusable workflow that runs JavaScript Type Checking. +## +name: JavaScript Type Checking + +on: + workflow_call: + +# Disable permissions for all available scopes by default. +# Any needed permissions should be configured at the job level. +permissions: {} + +jobs: + # Runs JavaScript type checking. + # + # Violations are reported inline with annotations. + # + # Performs the following steps: + # - Checks out the repository. + # - Sets up Node.js. + # - Logs debug information. + # - Installs npm dependencies. + # - Configures caching for TypeScript build info. + # - Runs JavaScript type checking. + # - Saves the TypeScript build info. + # - Ensures version-controlled files are not modified or deleted. + typecheck: + name: Run JavaScript type checking + runs-on: ubuntu-24.04 + permissions: + contents: read + timeout-minutes: 10 + + steps: + - name: Checkout repository + uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 + with: + show-progress: ${{ runner.debug == '1' && 'true' || 'false' }} + persist-credentials: false + + - name: Set up Node.js + uses: actions/setup-node@2028fbc5c25fe9cf00d9f06a71cc4710d4507903 # v6.0.0 + with: + node-version-file: '.nvmrc' + cache: npm + + - name: Log debug information + run: | + npm --version + node --version + + - name: Install npm dependencies + run: npm ci --ignore-scripts + + - name: Cache TypeScript build info + uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0 + with: + path: | + *.tsbuildinfo + key: "ts-build-info-${{ github.run_id }}" + restore-keys: | + ts-build-info- + + - name: Run JavaScript type checking + run: npm run typecheck:js + + - name: "Save result cache" + uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0 + if: ${{ !cancelled() }} + with: + path: | + *.tsbuildinfo + key: "ts-build-info-${{ github.run_id }}" + + - name: Ensure version-controlled files are not modified or deleted + run: git diff --exit-code diff --git a/Gruntfile.js b/Gruntfile.js index 2fe7dac819c6c..b5c69553f3f0d 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -1556,6 +1556,7 @@ module.exports = function(grunt) { grunt.registerTask( 'precommit:js', [ 'webpack:prod', 'jshint:corejs', + 'typecheck:js', 'uglify:imgareaselect', 'uglify:jqueryform', 'uglify:moment', @@ -2009,6 +2010,18 @@ module.exports = function(grunt) { grunt.registerTask( 'test', 'Runs all QUnit and PHPUnit tasks.', ['qunit:compiled', 'phpunit'] ); + grunt.registerTask( 'typecheck:js', 'Runs TypeScript type checking.', function() { + var done = this.async(); + + grunt.util.spawn( { + cmd: 'npm', + args: [ 'run', 'typecheck:js' ], + opts: { stdio: 'inherit' } + }, function( error ) { + done( ! error ); + } ); + } ); + grunt.registerTask( 'phpstan', 'Runs PHPStan on the entire codebase.', function() { var done = this.async();