diff --git a/.github/workflows/coding-standards.yml b/.github/workflows/coding-standards.yml index 0f70aa565b2e0..c255070266897 100644 --- a/.github/workflows/coding-standards.yml +++ b/.github/workflows/coding-standards.yml @@ -45,132 +45,21 @@ concurrency: permissions: {} jobs: - # Runs PHP coding standards checks. - # - # Violations are reported inline with annotations. - # - # Performs the following steps: - # - Checks out the repository. - # - Sets up PHP. - # - Configures caching for PHPCS scans. - # - Installs Composer dependencies. - # - Make Composer packages available globally. - # - Runs PHPCS on the full codebase with warnings suppressed. - # - Generate a report for displaying issues as pull request annotations. - # - Runs PHPCS on the `tests` directory without warnings suppressed. - # - Generate a report for displaying `test` directory issues as pull request annotations. - # - Ensures version-controlled files are not modified or deleted. + # Runs the PHP coding standards checks. phpcs: name: PHP coding standards - runs-on: ubuntu-latest + uses: WordPress/wordpress-develop/.github/workflows/reusable-coding-standards-php.yml@trunk permissions: contents: read - timeout-minutes: 20 if: ${{ github.repository == 'WordPress/wordpress-develop' || github.event_name == 'pull_request' }} - steps: - - name: Checkout repository - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 - with: - show-progress: ${{ runner.debug == '1' && 'true' || 'false' }} - - - name: Set up PHP - uses: shivammathur/setup-php@a4e22b60bbb9c1021113f2860347b0759f66fe5d # v2.30.0 - with: - php-version: 'latest' - coverage: none - tools: cs2pr - - # This date is used to ensure that the PHPCS cache is cleared at least once every week. - # http://man7.org/linux/man-pages/man1/date.1.html - - name: "Get last Monday's date" - id: get-date - run: echo "date=$(/bin/date -u --date='last Mon' "+%F")" >> $GITHUB_OUTPUT - - - name: Cache PHPCS scan cache - uses: actions/cache@ab5e6d0c87105b4c9c2047343972218f562e4319 # v4.0.1 - with: - path: | - .cache/phpcs-src.json - .cache/phpcs-tests.json - key: ${{ runner.os }}-date-${{ steps.get-date.outputs.date }}-phpcs-cache-${{ hashFiles('**/composer.json', 'phpcs.xml.dist') }} - - # Since Composer dependencies are installed using `composer update` and no lock file is in version control, - # passing a custom cache suffix ensures that the cache is flushed at least once per week. - - name: Install Composer dependencies - uses: ramsey/composer-install@57532f8be5bda426838819c5ee9afb8af389d51a # v3.0.0 - with: - custom-cache-suffix: ${{ steps.get-date.outputs.date }} - - - name: Make Composer packages available globally - run: echo "${PWD}/vendor/bin" >> $GITHUB_PATH - - - name: Run PHPCS on all Core files - id: phpcs-core - run: phpcs -n --report-full --cache=./.cache/phpcs-src.json --report-checkstyle=./.cache/phpcs-report.xml - - - name: Show PHPCS results in PR - if: ${{ always() && steps.phpcs-core.outcome == 'failure' }} - run: cs2pr ./.cache/phpcs-report.xml - - - name: Check test suite files for warnings - id: phpcs-tests - run: phpcs tests --report-full --cache=./.cache/phpcs-tests.json --report-checkstyle=./.cache/phpcs-tests-report.xml - - - name: Show test suite scan results in PR - if: ${{ always() && steps.phpcs-tests.outcome == 'failure' }} - run: cs2pr ./.cache/phpcs-tests-report.xml - - - name: Ensure version-controlled files are not modified during the tests - run: git diff --exit-code - # Runs the JavaScript coding standards checks. - # - # JSHint violations are not currently reported inline with annotations. - # - # Performs the following steps: - # - Checks out the repository. - # - Sets up Node.js. - # - Logs debug information about the GitHub Action runner. - # - Installs npm dependencies. - # - Run the WordPress JSHint checks. - # - Ensures version-controlled files are not modified or deleted. jshint: name: JavaScript coding standards - runs-on: ubuntu-latest + uses: WordPress/wordpress-develop/.github/workflows/reusable-coding-standards-javascript.yml@trunk permissions: contents: read - timeout-minutes: 20 if: ${{ github.repository == 'WordPress/wordpress-develop' || github.event_name == 'pull_request' }} - env: - PUPPETEER_SKIP_DOWNLOAD: ${{ true }} - - steps: - - name: Checkout repository - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 - with: - show-progress: ${{ runner.debug == '1' && 'true' || 'false' }} - - - name: Set up Node.js - uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2 - with: - node-version-file: '.nvmrc' - cache: npm - - - name: Log debug information - run: | - npm --version - node --version - git --version - - - name: Install npm Dependencies - run: npm ci - - - name: Run JSHint - run: npm run grunt jshint - - - name: Ensure version-controlled files are not modified or deleted - run: git diff --exit-code slack-notifications: name: Slack Notifications diff --git a/.github/workflows/end-to-end-tests.yml b/.github/workflows/end-to-end-tests.yml index 757de1f9a42a1..d77e439b2964c 100644 --- a/.github/workflows/end-to-end-tests.yml +++ b/.github/workflows/end-to-end-tests.yml @@ -36,105 +36,18 @@ env: jobs: # Runs the end-to-end test suite. - # - # Performs the following steps: - # - Sets environment variables. - # - Checks out the repository. - # - Sets up Node.js. - # - Logs debug information about the GitHub Action runner. - # - Installs npm dependencies. - # - Install Playwright browsers. - # - Builds WordPress to run from the `build` directory. - # - Starts the WordPress Docker container. - # - Logs the running Docker containers. - # - Logs Docker debug information (about both the Docker installation within the runner and the WordPress container). - # - Install WordPress within the Docker container. - # - Install Gutenberg. - # - Run the E2E tests. - # - Ensures version-controlled files are not modified or deleted. e2e-tests: - name: E2E Tests with SCRIPT_DEBUG ${{ matrix.LOCAL_SCRIPT_DEBUG && 'enabled' || 'disabled' }} - runs-on: ubuntu-latest + name: Test with SCRIPT_DEBUG ${{ matrix.LOCAL_SCRIPT_DEBUG && 'enabled' || 'disabled' }} + uses: WordPress/wordpress-develop/.github/workflows/reusable-end-to-end-tests.yml@trunk permissions: contents: read - timeout-minutes: 20 if: ${{ github.repository == 'WordPress/wordpress-develop' || github.event_name == 'pull_request' }} strategy: fail-fast: false matrix: LOCAL_SCRIPT_DEBUG: [ true, false ] - - steps: - - name: Configure environment variables - run: | - echo "PHP_FPM_UID=$(id -u)" >> $GITHUB_ENV - echo "PHP_FPM_GID=$(id -g)" >> $GITHUB_ENV - - - name: Checkout repository - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 - with: - show-progress: ${{ runner.debug == '1' && 'true' || 'false' }} - - - name: Set up Node.js - uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2 - with: - node-version-file: '.nvmrc' - cache: npm - - - name: Log debug information - run: | - npm --version - node --version - curl --version - git --version - locale -a - - - name: Install npm Dependencies - run: npm ci - - - name: Install Playwright browsers - run: npx playwright install --with-deps - - - name: Build WordPress - run: npm run build - - - name: Start Docker environment - run: | - npm run env:start - - - name: Log running Docker containers - run: docker ps -a - - - name: Docker debug information - run: | - docker -v - docker compose run --rm mysql mysql --version - docker compose run --rm php php --version - docker compose run --rm php php -m - docker compose run --rm php php -i - docker compose run --rm php locale -a - - - name: Install WordPress - env: - LOCAL_SCRIPT_DEBUG: ${{ matrix.LOCAL_SCRIPT_DEBUG }} - run: npm run env:install - - - name: Install Gutenberg - run: npm run env:cli -- plugin install gutenberg --path=/var/www/${{ env.LOCAL_DIR }} - - - name: Run E2E tests - run: npm run test:e2e - - - name: Archive debug artifacts (screenshots, HTML snapshots) - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - if: always() - with: - name: failures-artifacts${{ matrix.LOCAL_SCRIPT_DEBUG && '-SCRIPT_DEBUG' || '' }}-${{ github.run_id }} - path: artifacts - if-no-files-found: ignore - - - name: Ensure version-controlled files are not modified or deleted - run: git diff --exit-code + with: + LOCAL_SCRIPT_DEBUG: ${{ matrix.LOCAL_SCRIPT_DEBUG }} slack-notifications: name: Slack Notifications diff --git a/.github/workflows/javascript-tests.yml b/.github/workflows/javascript-tests.yml index b301866834eff..6eec2ac604fb4 100644 --- a/.github/workflows/javascript-tests.yml +++ b/.github/workflows/javascript-tests.yml @@ -43,50 +43,14 @@ concurrency: permissions: {} jobs: - # Runs the QUnit tests for WordPress. - # - # Performs the following steps: - # - Checks out the repository. - # - Sets up Node.js. - # - Logs debug information about the GitHub Action runner. - # - Installs npm dependencies. - # - Run the WordPress QUnit tests. - # - Ensures version-controlled files are not modified or deleted. + # Runs the WordPress Core JavaScript tests. test-js: name: QUnit Tests - runs-on: ubuntu-latest + uses: WordPress/wordpress-develop/.github/workflows/reusable-javascript-tests.yml@trunk permissions: contents: read - timeout-minutes: 20 if: ${{ github.repository == 'WordPress/wordpress-develop' || github.event_name == 'pull_request' }} - steps: - - name: Checkout repository - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 - with: - show-progress: ${{ runner.debug == '1' && 'true' || 'false' }} - - - name: Set up Node.js - uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2 - with: - node-version-file: '.nvmrc' - cache: npm - - - name: Log debug information - run: | - npm --version - node --version - git --version - - - name: Install npm Dependencies - run: npm ci - - - name: Run QUnit tests - run: npm run grunt qunit:compiled - - - name: Ensure version-controlled files are not modified or deleted - run: git diff --exit-code - slack-notifications: name: Slack Notifications uses: WordPress/wordpress-develop/.github/workflows/slack-notifications.yml@trunk diff --git a/.github/workflows/performance.yml b/.github/workflows/performance.yml index d79ae5f8012e7..dcd6010ad2c97 100644 --- a/.github/workflows/performance.yml +++ b/.github/workflows/performance.yml @@ -29,73 +29,11 @@ concurrency: # Any needed permissions should be configured at the job level. permissions: {} -env: - PUPPETEER_SKIP_DOWNLOAD: ${{ true }} - - # Performance testing should be performed in an environment reflecting a standard production environment. - LOCAL_WP_DEBUG: false - LOCAL_SCRIPT_DEBUG: false - LOCAL_SAVEQUERIES: false - LOCAL_WP_DEVELOPMENT_MODE: "''" - - # This workflow takes two sets of measurements — one for the current commit, - # and another against a consistent version that is used as a baseline measurement. - # This is done to isolate variance in measurements caused by the GitHub runners - # from differences caused by code changes between commits. The BASE_TAG value here - # represents the version being used for baseline measurements. It should only be - # changed if we want to normalize results against a different baseline. - BASE_TAG: '6.1.1' - LOCAL_DIR: build - TARGET_REF: ${{ github.event_name == 'pull_request' && github.event.pull_request.base.ref || '' }} - TARGET_SHA: ${{ github.event_name == 'pull_request' && github.event.pull_request.base.sha || github.event.before }} - jobs: # Runs the performance test suite. - # - # Performs the following steps: - # - Configure environment variables. - # - Checkout repository. - # - Set up Node.js. - # - Log debug information. - # - Install npm dependencies. - # - Install Playwright browsers. - # - Build WordPress. - # - Start Docker environment. - # - Log running Docker containers. - # - Docker debug information. - # - Install WordPress. - # - Install WordPress Importer plugin. - # - Import mock data. - # - Deactivate WordPress Importer plugin. - # - Update permalink structure. - # - Install additional languages. - # - Disable external HTTP requests. - # - Disable cron. - # - List defined constants. - # - Install MU plugin. - # - Run performance tests (current commit). - # - Download previous build artifact (target branch or previous commit). - # - Download artifact. - # - Unzip the build. - # - Run any database upgrades. - # - Flush cache. - # - Delete expired transients. - # - Run performance tests (previous/target commit). - # - Set the environment to the baseline version. - # - Run any database upgrades. - # - Flush cache. - # - Delete expired transients. - # - Run baseline performance tests. - # - Archive artifacts. - # - Compare results. - # - Add workflow summary. - # - Set the base sha. - # - Set commit details. - # - Publish performance results. - # - Ensure version-controlled files are not modified or deleted. performance: - name: Run performance tests ${{ matrix.memcached && '(with memcached)' || '' }} - runs-on: ubuntu-latest + name: Performance tests ${{ matrix.memcached && '(with memcached)' || '' }} + uses: WordPress/wordpress-develop/.github/workflows/reusable-performance.yml@trunk permissions: contents: read if: ${{ ( github.repository == 'WordPress/wordpress-develop' || github.event_name == 'pull_request' ) && ! contains( github.event.before, '00000000' ) }} @@ -103,230 +41,8 @@ jobs: fail-fast: false matrix: memcached: [ true, false ] - env: - LOCAL_PHP_MEMCACHED: ${{ matrix.memcached }} - steps: - - name: Configure environment variables - run: | - echo "PHP_FPM_UID=$(id -u)" >> $GITHUB_ENV - echo "PHP_FPM_GID=$(id -g)" >> $GITHUB_ENV - - - name: Checkout repository - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 - with: - show-progress: ${{ runner.debug == '1' && 'true' || 'false' }} - - - name: Set up Node.js - uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2 - with: - node-version-file: '.nvmrc' - cache: npm - - - name: Log debug information - run: | - npm --version - node --version - curl --version - git --version - locale -a - - - name: Install npm dependencies - run: npm ci - - - name: Install Playwright browsers - run: npx playwright install --with-deps chromium - - - name: Build WordPress - run: npm run build - - - name: Start Docker environment - run: npm run env:start - - - name: Install object cache drop-in - if: ${{ matrix.memcached }} - run: cp src/wp-content/object-cache.php build/wp-content/object-cache.php - - - name: Log running Docker containers - run: docker ps -a - - - name: Docker debug information - run: | - docker -v - docker compose run --rm mysql mysql --version - docker compose run --rm php php --version - docker compose run --rm php php -m - docker compose run --rm php php -i - docker compose run --rm php locale -a - - - name: Install WordPress - run: npm run env:install - - - name: Install WordPress Importer plugin - run: npm run env:cli -- plugin install wordpress-importer --activate --path=/var/www/${{ env.LOCAL_DIR }} - - - name: Import mock data - run: | - curl -O https://raw.githubusercontent.com/WordPress/theme-test-data/b9752e0533a5acbb876951a8cbb5bcc69a56474c/themeunittestdata.wordpress.xml - npm run env:cli -- import themeunittestdata.wordpress.xml --authors=create --path=/var/www/${{ env.LOCAL_DIR }} - rm themeunittestdata.wordpress.xml - - - name: Deactivate WordPress Importer plugin - run: npm run env:cli -- plugin deactivate wordpress-importer --path=/var/www/${{ env.LOCAL_DIR }} - - - name: Update permalink structure - run: npm run env:cli -- rewrite structure '/%year%/%monthnum%/%postname%/' --path=/var/www/${{ env.LOCAL_DIR }} - - - name: Install additional languages - run: | - npm run env:cli -- language core install de_DE --path=/var/www/${{ env.LOCAL_DIR }} - npm run env:cli -- language plugin install de_DE --all --path=/var/www/${{ env.LOCAL_DIR }} - npm run env:cli -- language theme install de_DE --all --path=/var/www/${{ env.LOCAL_DIR }} - - # Prevent background update checks from impacting test stability. - - name: Disable external HTTP requests - run: npm run env:cli -- config set WP_HTTP_BLOCK_EXTERNAL true --raw --type=constant --path=/var/www/${{ env.LOCAL_DIR }} - - # Prevent background tasks from impacting test stability. - - name: Disable cron - run: npm run env:cli -- config set DISABLE_WP_CRON true --raw --type=constant --path=/var/www/${{ env.LOCAL_DIR }} - - - name: List defined constants - run: npm run env:cli -- config list --path=/var/www/${{ env.LOCAL_DIR }} - - - name: Install MU plugin - run: | - mkdir ./${{ env.LOCAL_DIR }}/wp-content/mu-plugins - cp ./tests/performance/wp-content/mu-plugins/server-timing.php ./${{ env.LOCAL_DIR }}/wp-content/mu-plugins/server-timing.php - - - name: Run performance tests (current commit) - run: npm run test:performance - - - name: Download previous build artifact (target branch or previous commit) - uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 - id: get-previous-build - with: - script: | - const artifacts = await github.rest.actions.listArtifactsForRepo({ - owner: context.repo.owner, - repo: context.repo.repo, - name: 'wordpress-build-' + process.env.TARGET_SHA, - }); - - const matchArtifact = artifacts.data.artifacts[0]; - - if ( ! matchArtifact ) { - core.setFailed( 'No artifact found!' ); - return false; - } - - const download = await github.rest.actions.downloadArtifact( { - owner: context.repo.owner, - repo: context.repo.repo, - artifact_id: matchArtifact.id, - archive_format: 'zip', - } ); - - const fs = require( 'fs' ); - fs.writeFileSync( '${{ github.workspace }}/before.zip', Buffer.from( download.data ) ) - - return true; - - - name: Unzip the build - if: ${{ steps.get-previous-build.outputs.result }} - run: | - unzip ${{ github.workspace }}/before.zip - unzip -o ${{ github.workspace }}/wordpress.zip - - - name: Run any database upgrades - if: ${{ steps.get-previous-build.outputs.result }} - run: npm run env:cli -- core update-db --path=/var/www/${{ env.LOCAL_DIR }} - - - name: Flush cache - if: ${{ steps.get-previous-build.outputs.result }} - run: npm run env:cli -- cache flush --path=/var/www/${{ env.LOCAL_DIR }} - - - name: Delete expired transients - if: ${{ steps.get-previous-build.outputs.result }} - run: npm run env:cli -- transient delete --expired --path=/var/www/${{ env.LOCAL_DIR }} - - - name: Run target performance tests (previous/target commit) - if: ${{ steps.get-previous-build.outputs.result }} - env: - TEST_RESULTS_PREFIX: before - run: npm run test:performance - - - name: Set the environment to the baseline version - if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/trunk' }} - run: | - npm run env:cli -- core update --version=${{ env.BASE_TAG }} --force --path=/var/www/${{ env.LOCAL_DIR }} - npm run env:cli -- core version --path=/var/www/${{ env.LOCAL_DIR }} - - - name: Run any database upgrades - if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/trunk' }} - run: npm run env:cli -- core update-db --path=/var/www/${{ env.LOCAL_DIR }} - - - name: Flush cache - if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/trunk' }} - run: npm run env:cli -- cache flush --path=/var/www/${{ env.LOCAL_DIR }} - - - name: Delete expired transients - if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/trunk' }} - run: npm run env:cli -- transient delete --expired --path=/var/www/${{ env.LOCAL_DIR }} - - - name: Run baseline performance tests - if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/trunk' }} - env: - TEST_RESULTS_PREFIX: base - run: npm run test:performance - - - name: Archive artifacts - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - if: always() - with: - name: performance-artifacts${{ matrix.memcached && '-memcached' || '' }}-${{ github.run_id }} - path: artifacts - if-no-files-found: ignore - - - name: Compare results - run: node ./tests/performance/compare-results.js ${{ runner.temp }}/summary.md - - - name: Add workflow summary - run: cat ${{ runner.temp }}/summary.md >> $GITHUB_STEP_SUMMARY - - - name: Set the base sha - # Only needed when publishing results. - if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/trunk' && ! matrix.memcached }} - uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 - id: base-sha - with: - github-token: ${{ secrets.GITHUB_TOKEN }} - script: | - const baseRef = await github.rest.git.getRef({ owner: context.repo.owner, repo: context.repo.repo, ref: 'tags/${{ env.BASE_TAG }}' }); - return baseRef.data.object.sha; - - - name: Set commit details - # Only needed when publishing results. - if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/trunk' && ! matrix.memcached }} - uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 - id: commit-timestamp - with: - github-token: ${{ secrets.GITHUB_TOKEN }} - script: | - const commit_details = await github.rest.git.getCommit({ owner: context.repo.owner, repo: context.repo.repo, commit_sha: context.sha }); - return parseInt((new Date( commit_details.data.author.date ).getTime() / 1000).toFixed(0)) - - - name: Publish performance results - # Only publish results on pushes to trunk. - if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/trunk' && ! matrix.memcached }} - env: - BASE_SHA: ${{ steps.base-sha.outputs.result }} - COMMITTED_AT: ${{ steps.commit-timestamp.outputs.result }} - CODEVITALS_PROJECT_TOKEN: ${{ secrets.CODEVITALS_PROJECT_TOKEN }} - HOST_NAME: "www.codevitals.run" - run: node ./tests/performance/log-results.js $CODEVITALS_PROJECT_TOKEN trunk $GITHUB_SHA $BASE_SHA $COMMITTED_AT $HOST_NAME - - - name: Ensure version-controlled files are not modified or deleted - run: git diff --exit-code + with: + memcached: ${{ matrix.memcached }} slack-notifications: name: Slack Notifications diff --git a/.github/workflows/php-compatibility.yml b/.github/workflows/php-compatibility.yml index bc3363aee8f59..d84a372da8f29 100644 --- a/.github/workflows/php-compatibility.yml +++ b/.github/workflows/php-compatibility.yml @@ -40,79 +40,14 @@ concurrency: permissions: {} jobs: - # Runs PHP compatibility testing. - # - # Violations are reported inline with annotations. - # - # Performs the following steps: - # - Checks out the repository. - # - Sets up PHP. - # - Logs debug information. - # - Configures caching for PHP compatibility scans. - # - Installs Composer dependencies. - # - Make Composer packages available globally. - # - Runs the PHP compatibility tests. - # - Generate a report for displaying issues as pull request annotations. - # - Ensures version-controlled files are not modified or deleted. php-compatibility: name: Check PHP compatibility - runs-on: ubuntu-latest + uses: WordPress/wordpress-develop/.github/workflows/reusable-php-compatibility.yml@trunk permissions: contents: read - timeout-minutes: 20 if: ${{ github.repository == 'WordPress/wordpress-develop' || github.event_name == 'pull_request' }} - steps: - - name: Checkout repository - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 - with: - show-progress: ${{ runner.debug == '1' && 'true' || 'false' }} - - - name: Set up PHP - uses: shivammathur/setup-php@a4e22b60bbb9c1021113f2860347b0759f66fe5d # v2.30.0 - with: - php-version: '7.4' - coverage: none - tools: cs2pr - - - name: Log debug information - run: | - composer --version - - # This date is used to ensure that the PHP compatibility cache is cleared at least once every week. - # http://man7.org/linux/man-pages/man1/date.1.html - - name: "Get last Monday's date" - id: get-date - run: echo "date=$(/bin/date -u --date='last Mon' "+%F")" >> $GITHUB_OUTPUT - - - name: Cache PHP compatibility scan cache - uses: actions/cache@ab5e6d0c87105b4c9c2047343972218f562e4319 # v4.0.1 - with: - path: .cache/phpcompat.json - key: ${{ runner.os }}-date-${{ steps.get-date.outputs.date }}-phpcompat-cache-${{ hashFiles('**/composer.json', 'phpcompat.xml.dist') }} - - # Since Composer dependencies are installed using `composer update` and no lock file is in version control, - # passing a custom cache suffix ensures that the cache is flushed at least once per week. - - name: Install Composer dependencies - uses: ramsey/composer-install@57532f8be5bda426838819c5ee9afb8af389d51a # v3.0.0 - with: - custom-cache-suffix: ${{ steps.get-date.outputs.date }} - - - name: Make Composer packages available globally - run: echo "${PWD}/vendor/bin" >> $GITHUB_PATH - - - name: Run PHP compatibility tests - id: phpcs - run: phpcs --standard=phpcompat.xml.dist --report-full --report-checkstyle=./.cache/phpcs-compat-report.xml - - - name: Show PHPCompatibility results in PR - if: ${{ always() && steps.phpcs.outcome == 'failure' }} - run: cs2pr ./.cache/phpcs-compat-report.xml - - - name: Ensure version-controlled files are not modified or deleted - run: git diff --exit-code - slack-notifications: name: Slack Notifications uses: WordPress/wordpress-develop/.github/workflows/slack-notifications.yml@trunk diff --git a/.github/workflows/phpunit-tests.yml b/.github/workflows/phpunit-tests.yml index 3bc72f8e8c528..b40237f82802d 100644 --- a/.github/workflows/phpunit-tests.yml +++ b/.github/workflows/phpunit-tests.yml @@ -36,7 +36,7 @@ jobs: # test-with-mysql: name: PHP ${{ matrix.php }} - uses: WordPress/wordpress-develop/.github/workflows/phpunit-tests-run.yml@trunk + uses: WordPress/wordpress-develop/.github/workflows/reusable-phpunit-tests.yml@trunk permissions: contents: read secrets: inherit @@ -108,7 +108,7 @@ jobs: # test-with-mariadb: name: PHP ${{ matrix.php }} - uses: WordPress/wordpress-develop/.github/workflows/phpunit-tests-run.yml@trunk + uses: WordPress/wordpress-develop/.github/workflows/reusable-phpunit-tests.yml@trunk permissions: contents: read secrets: inherit diff --git a/.github/workflows/reusable-coding-standards-javascript.yml b/.github/workflows/reusable-coding-standards-javascript.yml new file mode 100644 index 0000000000000..a424f80630887 --- /dev/null +++ b/.github/workflows/reusable-coding-standards-javascript.yml @@ -0,0 +1,56 @@ +## +# A reusable workflow that checks the JavaScript coding standards. +## +name: JavaScript coding standards + +on: + workflow_call: + +env: + PUPPETEER_SKIP_DOWNLOAD: ${{ true }} + +jobs: + # Runs the JavaScript coding standards checks. + # + # JSHint violations are not currently reported inline with annotations. + # + # Performs the following steps: + # - Checks out the repository. + # - Sets up Node.js. + # - Logs debug information about the GitHub Action runner. + # - Installs npm dependencies. + # - Run the WordPress JSHint checks. + # - Ensures version-controlled files are not modified or deleted. + jshint: + name: Run coding standards checks + runs-on: ubuntu-latest + permissions: + contents: read + timeout-minutes: 20 + + steps: + - name: Checkout repository + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 + with: + show-progress: ${{ runner.debug == '1' && 'true' || 'false' }} + + - name: Set up Node.js + uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2 + with: + node-version-file: '.nvmrc' + cache: npm + + - name: Log debug information + run: | + npm --version + node --version + git --version + + - name: Install npm Dependencies + run: npm ci + + - name: Run JSHint + run: npm run grunt jshint + + - name: Ensure version-controlled files are not modified or deleted + run: git diff --exit-code diff --git a/.github/workflows/reusable-coding-standards-php.yml b/.github/workflows/reusable-coding-standards-php.yml new file mode 100644 index 0000000000000..3f8520c2f74d7 --- /dev/null +++ b/.github/workflows/reusable-coding-standards-php.yml @@ -0,0 +1,92 @@ +## +# A reusable workflow that checks the PHP coding standards. +## +name: PHP coding standards + +on: + workflow_call: + inputs: + php-version: + description: 'The PHP version to use.' + required: false + type: 'string' + default: 'latest' + +jobs: + # Runs the PHP coding standards checks. + # + # Violations are reported inline with annotations. + # + # Performs the following steps: + # - Checks out the repository. + # - Sets up PHP. + # - Configures caching for PHPCS scans. + # - Installs Composer dependencies. + # - Make Composer packages available globally. + # - Runs PHPCS on the full codebase (warnings excluded). + # - Generate a report for displaying issues as pull request annotations. + # - Runs PHPCS on the `tests` directory without (warnings included). + # - Generate a report for displaying `test` directory issues as pull request annotations. + # - Ensures version-controlled files are not modified or deleted. + phpcs: + name: Run coding standards checks + runs-on: ubuntu-latest + permissions: + contents: read + timeout-minutes: 20 + + steps: + - name: Checkout repository + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 + with: + show-progress: ${{ runner.debug == '1' && 'true' || 'false' }} + + - name: Set up PHP + uses: shivammathur/setup-php@a4e22b60bbb9c1021113f2860347b0759f66fe5d # v2.30.0 + with: + php-version: ${{ inputs.php-version }} + coverage: none + tools: cs2pr + + # This date is used to ensure that the PHPCS cache is cleared at least once every week. + # http://man7.org/linux/man-pages/man1/date.1.html + - name: "Get last Monday's date" + id: get-date + run: echo "date=$(/bin/date -u --date='last Mon' "+%F")" >> $GITHUB_OUTPUT + + - name: Cache PHPCS scan cache + uses: actions/cache@ab5e6d0c87105b4c9c2047343972218f562e4319 # v4.0.1 + with: + path: | + .cache/phpcs-src.json + .cache/phpcs-tests.json + key: ${{ runner.os }}-date-${{ steps.get-date.outputs.date }}-php-${{ inputs.php-version }}-phpcs-cache-${{ hashFiles('**/composer.json', 'phpcs.xml.dist') }} + + # Since Composer dependencies are installed using `composer update` and no lock file is in version control, + # passing a custom cache suffix ensures that the cache is flushed at least once per week. + - name: Install Composer dependencies + uses: ramsey/composer-install@57532f8be5bda426838819c5ee9afb8af389d51a # v3.0.0 + with: + custom-cache-suffix: ${{ steps.get-date.outputs.date }} + + - name: Make Composer packages available globally + run: echo "${PWD}/vendor/bin" >> $GITHUB_PATH + + - name: Run PHPCS on all Core files + id: phpcs-core + run: phpcs -n --report-full --cache=./.cache/phpcs-src.json --report-checkstyle=./.cache/phpcs-report.xml + + - name: Show PHPCS results in PR + if: ${{ always() && steps.phpcs-core.outcome == 'failure' }} + run: cs2pr ./.cache/phpcs-report.xml + + - name: Check test suite files for warnings + id: phpcs-tests + run: phpcs tests --report-full --cache=./.cache/phpcs-tests.json --report-checkstyle=./.cache/phpcs-tests-report.xml + + - name: Show test suite scan results in PR + if: ${{ always() && steps.phpcs-tests.outcome == 'failure' }} + run: cs2pr ./.cache/phpcs-tests-report.xml + + - name: Ensure version-controlled files are not modified during the tests + run: git diff --exit-code diff --git a/.github/workflows/reusable-end-to-end-tests.yml b/.github/workflows/reusable-end-to-end-tests.yml new file mode 100644 index 0000000000000..70609e8a65359 --- /dev/null +++ b/.github/workflows/reusable-end-to-end-tests.yml @@ -0,0 +1,123 @@ +## +# A reusable workflow that runs end-to-end tests. +# +# Branches 6.3 and earlier used Puppeteer instead of Playwright. +# Use https://github.com/WordPress/wordpress-develop/tree/6.3/.github/workflows/reusable-end-to-end-tests.yml instead. +## +name: End-to-end Tests + +on: + workflow_call: + inputs: + LOCAL_SCRIPT_DEBUG: + description: 'Whether to enable script debugging.' + required: false + type: 'boolean' + default: false + install-gutenberg: + description: 'Whether to install the Gutenberg plugin.' + required: false + type: 'boolean' + default: true + +env: + LOCAL_DIR: build + +jobs: + # Runs the end-to-end test suite. + # + # Performs the following steps: + # - Sets environment variables. + # - Checks out the repository. + # - Sets up Node.js. + # - Logs debug information about the GitHub Action runner. + # - Installs npm dependencies. + # - Install Playwright browsers. + # - Builds WordPress to run from the `build` directory. + # - Starts the WordPress Docker container. + # - Logs the running Docker containers. + # - Logs Docker debug information (about both the Docker installation within the runner and the WordPress container). + # - Install WordPress within the Docker container. + # - Install Gutenberg. + # - Run the E2E tests. + # - Uploads screenshots and HTML snapshots as an artifact. + # - Ensures version-controlled files are not modified or deleted. + e2e-tests: + name: Run E2E tests + runs-on: ubuntu-latest + permissions: + contents: read + timeout-minutes: 20 + + steps: + - name: Configure environment variables + run: | + echo "PHP_FPM_UID=$(id -u)" >> $GITHUB_ENV + echo "PHP_FPM_GID=$(id -g)" >> $GITHUB_ENV + + - name: Checkout repository + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 + with: + show-progress: ${{ runner.debug == '1' && 'true' || 'false' }} + + - name: Set up Node.js + uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2 + with: + node-version-file: '.nvmrc' + cache: npm + + - name: Log debug information + run: | + npm --version + node --version + curl --version + git --version + locale -a + + - name: Install npm Dependencies + run: npm ci + + - name: Install Playwright browsers + run: npx playwright install --with-deps + + - name: Build WordPress + run: npm run build + + - name: Start Docker environment + run: | + npm run env:start + + - name: Log running Docker containers + run: docker ps -a + + - name: Docker debug information + run: | + docker -v + docker compose run --rm mysql mysql --version + docker compose run --rm php php --version + docker compose run --rm php php -m + docker compose run --rm php php -i + docker compose run --rm php locale -a + + - name: Install WordPress + env: + LOCAL_SCRIPT_DEBUG: ${{ inputs.LOCAL_SCRIPT_DEBUG }} + run: npm run env:install + + - name: Install Gutenberg + if: ${{ inputs.install-gutenberg }} + run: npm run env:cli -- plugin install gutenberg --path=/var/www/${{ env.LOCAL_DIR }} + + - name: Run E2E tests + run: npm run test:e2e + + - name: Archive debug artifacts (screenshots, HTML snapshots) + uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 + if: always() + with: + name: failures-artifacts${{ inputs.LOCAL_SCRIPT_DEBUG && '-SCRIPT_DEBUG' || '' }}-${{ github.run_id }} + path: artifacts + if-no-files-found: ignore + + - name: Ensure version-controlled files are not modified or deleted + run: git diff --exit-code diff --git a/.github/workflows/reusable-javascript-tests.yml b/.github/workflows/reusable-javascript-tests.yml new file mode 100644 index 0000000000000..0d7b674fb932a --- /dev/null +++ b/.github/workflows/reusable-javascript-tests.yml @@ -0,0 +1,51 @@ +## +# A reusable workflow that runs JavaScript tests. +## +name: JavaScript tests + +on: + workflow_call: + +jobs: + # Runs the QUnit test suite. + # + # Performs the following steps: + # - Checks out the repository. + # - Sets up Node.js. + # - Logs debug information about the GitHub Action runner. + # - Installs npm dependencies. + # - Run the WordPress QUnit tests. + # - Ensures version-controlled files are not modified or deleted. + test-js: + name: Run QUnit tests + runs-on: ubuntu-latest + permissions: + contents: read + timeout-minutes: 20 + + steps: + - name: Checkout repository + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 + with: + show-progress: ${{ runner.debug == '1' && 'true' || 'false' }} + + - name: Set up Node.js + uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2 + with: + node-version-file: '.nvmrc' + cache: npm + + - name: Log debug information + run: | + npm --version + node --version + git --version + + - name: Install npm Dependencies + run: npm ci + + - name: Run QUnit tests + run: npm run grunt qunit:compiled + + - name: Ensure version-controlled files are not modified or deleted + run: git diff --exit-code diff --git a/.github/workflows/reusable-performance.yml b/.github/workflows/reusable-performance.yml new file mode 100644 index 0000000000000..0eb3f30543eb3 --- /dev/null +++ b/.github/workflows/reusable-performance.yml @@ -0,0 +1,317 @@ +## +# A reusable workflow that runs the performance test suite. +## +name: Performance Tests + +on: + workflow_call: + inputs: + LOCAL_DIR: + description: 'Where to run WordPress from.' + required: false + type: 'string' + default: 'build' + BASE_TAG: + description: 'The version being used for baseline measurements.' + required: false + type: 'string' + default: '6.1.1' + memcached: + description: 'Whether to enable memcached.' + required: false + type: 'boolean' + default: false + +env: + PUPPETEER_SKIP_DOWNLOAD: ${{ true }} + + # Performance testing should be performed in an environment reflecting a standard production environment. + LOCAL_WP_DEBUG: false + LOCAL_SCRIPT_DEBUG: false + LOCAL_SAVEQUERIES: false + LOCAL_WP_DEVELOPMENT_MODE: "''" + + # This workflow takes two sets of measurements — one for the current commit, + # and another against a consistent version that is used as a baseline measurement. + # This is done to isolate variance in measurements caused by the GitHub runners + # from differences caused by code changes between commits. The BASE_TAG value here + # represents the version being used for baseline measurements. It should only be + # changed if we want to normalize results against a different baseline. + BASE_TAG: ${{ inputs.BASE_TAG }} + LOCAL_DIR: ${{ inputs.LOCAL_DIR }} + TARGET_REF: ${{ github.event_name == 'pull_request' && github.event.pull_request.base.ref || '' }} + TARGET_SHA: ${{ github.event_name == 'pull_request' && github.event.pull_request.base.sha || github.event.before }} + + LOCAL_PHP_MEMCACHED: ${{ inputs.memcached }} + +jobs: + # Performs the following steps: + # - Configure environment variables. + # - Checkout repository. + # - Set up Node.js. + # - Log debug information. + # - Install npm dependencies. + # - Install Playwright browsers. + # - Build WordPress. + # - Start Docker environment. + # - Log running Docker containers. + # - Docker debug information. + # - Install WordPress. + # - Install WordPress Importer plugin. + # - Import mock data. + # - Deactivate WordPress Importer plugin. + # - Update permalink structure. + # - Install additional languages. + # - Disable external HTTP requests. + # - Disable cron. + # - List defined constants. + # - Install MU plugin. + # - Run performance tests (current commit). + # - Download previous build artifact (target branch or previous commit). + # - Download artifact. + # - Unzip the build. + # - Run any database upgrades. + # - Flush cache. + # - Delete expired transients. + # - Run performance tests (previous/target commit). + # - Set the environment to the baseline version. + # - Run any database upgrades. + # - Flush cache. + # - Delete expired transients. + # - Run baseline performance tests. + # - Archive artifacts. + # - Compare results. + # - Add workflow summary. + # - Set the base sha. + # - Set commit details. + # - Publish performance results. + # - Ensure version-controlled files are not modified or deleted. + performance: + name: Run tests + runs-on: ubuntu-latest + permissions: + contents: read + if: ${{ ( github.repository == 'WordPress/wordpress-develop' || github.event_name == 'pull_request' ) && ! contains( github.event.before, '00000000' ) }} + + steps: + - name: Configure environment variables + run: | + echo "PHP_FPM_UID=$(id -u)" >> $GITHUB_ENV + echo "PHP_FPM_GID=$(id -g)" >> $GITHUB_ENV + + - name: Checkout repository + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 + with: + show-progress: ${{ runner.debug == '1' && 'true' || 'false' }} + + - name: Set up Node.js + uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2 + with: + node-version-file: '.nvmrc' + cache: npm + + - name: Log debug information + run: | + npm --version + node --version + curl --version + git --version + locale -a + + - name: Install npm dependencies + run: npm ci + + - name: Install Playwright browsers + run: npx playwright install --with-deps chromium + + - name: Build WordPress + run: npm run build + + - name: Start Docker environment + run: npm run env:start + + - name: Install object cache drop-in + if: ${{ inputs.memcached }} + run: cp src/wp-content/object-cache.php build/wp-content/object-cache.php + + - name: Log running Docker containers + run: docker ps -a + + - name: Docker debug information + run: | + docker -v + docker compose run --rm mysql mysql --version + docker compose run --rm php php --version + docker compose run --rm php php -m + docker compose run --rm php php -i + docker compose run --rm php locale -a + + - name: Install WordPress + run: npm run env:install + + - name: Install WordPress Importer plugin + run: npm run env:cli -- plugin install wordpress-importer --activate --path=/var/www/${{ env.LOCAL_DIR }} + + - name: Import mock data + run: | + curl -O https://raw.githubusercontent.com/WordPress/theme-test-data/b9752e0533a5acbb876951a8cbb5bcc69a56474c/themeunittestdata.wordpress.xml + npm run env:cli -- import themeunittestdata.wordpress.xml --authors=create --path=/var/www/${{ env.LOCAL_DIR }} + rm themeunittestdata.wordpress.xml + + - name: Deactivate WordPress Importer plugin + run: npm run env:cli -- plugin deactivate wordpress-importer --path=/var/www/${{ env.LOCAL_DIR }} + + - name: Update permalink structure + run: npm run env:cli -- rewrite structure '/%year%/%monthnum%/%postname%/' --path=/var/www/${{ env.LOCAL_DIR }} + + - name: Install additional languages + run: | + npm run env:cli -- language core install de_DE --path=/var/www/${{ env.LOCAL_DIR }} + npm run env:cli -- language plugin install de_DE --all --path=/var/www/${{ env.LOCAL_DIR }} + npm run env:cli -- language theme install de_DE --all --path=/var/www/${{ env.LOCAL_DIR }} + + # Prevent background update checks from impacting test stability. + - name: Disable external HTTP requests + run: npm run env:cli -- config set WP_HTTP_BLOCK_EXTERNAL true --raw --type=constant --path=/var/www/${{ env.LOCAL_DIR }} + + # Prevent background tasks from impacting test stability. + - name: Disable cron + run: npm run env:cli -- config set DISABLE_WP_CRON true --raw --type=constant --path=/var/www/${{ env.LOCAL_DIR }} + + - name: List defined constants + run: npm run env:cli -- config list --path=/var/www/${{ env.LOCAL_DIR }} + + - name: Install MU plugin + run: | + mkdir ./${{ env.LOCAL_DIR }}/wp-content/mu-plugins + cp ./tests/performance/wp-content/mu-plugins/server-timing.php ./${{ env.LOCAL_DIR }}/wp-content/mu-plugins/server-timing.php + + - name: Run performance tests (current commit) + run: npm run test:performance + + - name: Download previous build artifact (target branch or previous commit) + uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 + id: get-previous-build + with: + script: | + const artifacts = await github.rest.actions.listArtifactsForRepo({ + owner: context.repo.owner, + repo: context.repo.repo, + name: 'wordpress-build-' + process.env.TARGET_SHA, + }); + + const matchArtifact = artifacts.data.artifacts[0]; + + if ( ! matchArtifact ) { + core.setFailed( 'No artifact found!' ); + return false; + } + + const download = await github.rest.actions.downloadArtifact( { + owner: context.repo.owner, + repo: context.repo.repo, + artifact_id: matchArtifact.id, + archive_format: 'zip', + } ); + + const fs = require( 'fs' ); + fs.writeFileSync( '${{ github.workspace }}/before.zip', Buffer.from( download.data ) ) + + return true; + + - name: Unzip the build + if: ${{ steps.get-previous-build.outputs.result }} + run: | + unzip ${{ github.workspace }}/before.zip + unzip -o ${{ github.workspace }}/wordpress.zip + + - name: Run any database upgrades + if: ${{ steps.get-previous-build.outputs.result }} + run: npm run env:cli -- core update-db --path=/var/www/${{ env.LOCAL_DIR }} + + - name: Flush cache + if: ${{ steps.get-previous-build.outputs.result }} + run: npm run env:cli -- cache flush --path=/var/www/${{ env.LOCAL_DIR }} + + - name: Delete expired transients + if: ${{ steps.get-previous-build.outputs.result }} + run: npm run env:cli -- transient delete --expired --path=/var/www/${{ env.LOCAL_DIR }} + + - name: Run target performance tests (previous/target commit) + if: ${{ steps.get-previous-build.outputs.result }} + env: + TEST_RESULTS_PREFIX: before + run: npm run test:performance + + - name: Set the environment to the baseline version + if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/trunk' }} + run: | + npm run env:cli -- core update --version=${{ env.BASE_TAG }} --force --path=/var/www/${{ env.LOCAL_DIR }} + npm run env:cli -- core version --path=/var/www/${{ env.LOCAL_DIR }} + + - name: Run any database upgrades + if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/trunk' }} + run: npm run env:cli -- core update-db --path=/var/www/${{ env.LOCAL_DIR }} + + - name: Flush cache + if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/trunk' }} + run: npm run env:cli -- cache flush --path=/var/www/${{ env.LOCAL_DIR }} + + - name: Delete expired transients + if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/trunk' }} + run: npm run env:cli -- transient delete --expired --path=/var/www/${{ env.LOCAL_DIR }} + + - name: Run baseline performance tests + if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/trunk' }} + env: + TEST_RESULTS_PREFIX: base + run: npm run test:performance + + - name: Archive artifacts + uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 + if: always() + with: + name: performance-artifacts${{ inputs.memcached && '-memcached' || '' }}-${{ github.run_id }} + path: artifacts + if-no-files-found: ignore + + - name: Compare results + run: node ./tests/performance/compare-results.js ${{ runner.temp }}/summary.md + + - name: Add workflow summary + run: cat ${{ runner.temp }}/summary.md >> $GITHUB_STEP_SUMMARY + + - name: Set the base sha + # Only needed when publishing results. + if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/trunk' && ! inputs.memcached }} + uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 + id: base-sha + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + const baseRef = await github.rest.git.getRef({ owner: context.repo.owner, repo: context.repo.repo, ref: 'tags/${{ env.BASE_TAG }}' }); + return baseRef.data.object.sha; + + - name: Set commit details + # Only needed when publishing results. + if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/trunk' && ! inputs.memcached }} + uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 + id: commit-timestamp + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + const commit_details = await github.rest.git.getCommit({ owner: context.repo.owner, repo: context.repo.repo, commit_sha: context.sha }); + return parseInt((new Date( commit_details.data.author.date ).getTime() / 1000).toFixed(0)) + + - name: Publish performance results + # Only publish results on pushes to trunk. + if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/trunk' && ! inputs.memcached }} + env: + BASE_SHA: ${{ steps.base-sha.outputs.result }} + COMMITTED_AT: ${{ steps.commit-timestamp.outputs.result }} + CODEVITALS_PROJECT_TOKEN: ${{ secrets.CODEVITALS_PROJECT_TOKEN }} + HOST_NAME: "www.codevitals.run" + run: node ./tests/performance/log-results.js $CODEVITALS_PROJECT_TOKEN trunk $GITHUB_SHA $BASE_SHA $COMMITTED_AT $HOST_NAME + + - name: Ensure version-controlled files are not modified or deleted + run: git diff --exit-code diff --git a/.github/workflows/reusable-php-compatibility.yml b/.github/workflows/reusable-php-compatibility.yml new file mode 100644 index 0000000000000..1a6a6b128747b --- /dev/null +++ b/.github/workflows/reusable-php-compatibility.yml @@ -0,0 +1,85 @@ +## +# A reusable workflow that runs PHP compatibility tests. +## +name: PHP Compatibility + +on: + workflow_call: + inputs: + php-version: + description: 'The PHP version to use.' + required: false + type: 'string' + default: 'latest' + +jobs: + # Runs PHP compatibility tests. + # + # Violations are reported inline with annotations. + # + # Performs the following steps: + # - Checks out the repository. + # - Sets up PHP. + # - Logs debug information. + # - Configures caching for PHP compatibility scans. + # - Installs Composer dependencies. + # - Make Composer packages available globally. + # - Runs the PHP compatibility tests. + # - Generate a report for displaying issues as pull request annotations. + # - Ensures version-controlled files are not modified or deleted. + php-compatibility: + name: Run compatibility checks + runs-on: ubuntu-latest + permissions: + contents: read + timeout-minutes: 20 + + steps: + - name: Checkout repository + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 + with: + show-progress: ${{ runner.debug == '1' && 'true' || 'false' }} + + - name: Set up PHP + uses: shivammathur/setup-php@a4e22b60bbb9c1021113f2860347b0759f66fe5d # v2.30.0 + with: + php-version: ${{ inputs.php-version }} + coverage: none + tools: cs2pr + + - name: Log debug information + run: | + composer --version + + # This date is used to ensure that the PHP compatibility cache is cleared at least once every week. + # http://man7.org/linux/man-pages/man1/date.1.html + - name: "Get last Monday's date" + id: get-date + run: echo "date=$(/bin/date -u --date='last Mon' "+%F")" >> $GITHUB_OUTPUT + + - name: Cache PHP compatibility scan cache + uses: actions/cache@ab5e6d0c87105b4c9c2047343972218f562e4319 # v4.0.1 + with: + path: .cache/phpcompat.json + key: ${{ runner.os }}-date-${{ steps.get-date.outputs.date }}-php-${{ inputs.php-version }}-phpcompat-cache-${{ hashFiles('**/composer.json', 'phpcompat.xml.dist') }} + + # Since Composer dependencies are installed using `composer update` and no lock file is in version control, + # passing a custom cache suffix ensures that the cache is flushed at least once per week. + - name: Install Composer dependencies + uses: ramsey/composer-install@57532f8be5bda426838819c5ee9afb8af389d51a # v3.0.0 + with: + custom-cache-suffix: ${{ steps.get-date.outputs.date }} + + - name: Make Composer packages available globally + run: echo "${PWD}/vendor/bin" >> $GITHUB_PATH + + - name: Run PHP compatibility tests + id: phpcs + run: phpcs --standard=phpcompat.xml.dist --report-full --report-checkstyle=./.cache/phpcs-compat-report.xml + + - name: Show PHPCompatibility results in PR + if: ${{ always() && steps.phpcs.outcome == 'failure' }} + run: cs2pr ./.cache/phpcs-compat-report.xml + + - name: Ensure version-controlled files are not modified or deleted + run: git diff --exit-code diff --git a/.github/workflows/phpunit-tests-run.yml b/.github/workflows/reusable-phpunit-tests.yml similarity index 99% rename from .github/workflows/phpunit-tests-run.yml rename to .github/workflows/reusable-phpunit-tests.yml index 9978fd9bf70fb..60949915e4d1c 100644 --- a/.github/workflows/phpunit-tests-run.yml +++ b/.github/workflows/reusable-phpunit-tests.yml @@ -1,5 +1,5 @@ ## -# A callable workflow that runs the PHPUnit test suite with the specified configuration. +# A reusable workflow that runs the PHPUnit test suite with the specified configuration. ## name: Run PHPUnit tests diff --git a/.github/workflows/callable-test-core-build-process.yml b/.github/workflows/reusable-test-core-build-process.yml similarity index 92% rename from .github/workflows/callable-test-core-build-process.yml rename to .github/workflows/reusable-test-core-build-process.yml index 7c2bd9c80c75f..caeb7afab7555 100644 --- a/.github/workflows/callable-test-core-build-process.yml +++ b/.github/workflows/reusable-test-core-build-process.yml @@ -1,5 +1,5 @@ ## -# A callable workflow that tests the WordPress Core build process. +# A reusable workflow that tests the WordPress Core build process. ## name: Test the WordPress Build Process @@ -16,6 +16,11 @@ on: required: false type: 'string' default: 'src' + test-emoji: + description: 'Whether to run the grunt precommit:emoji script.' + required: false + type: 'boolean' + default: true env: PUPPETEER_SKIP_DOWNLOAD: ${{ true }} @@ -62,6 +67,7 @@ jobs: run: npm ci - name: Run Emoji precommit task + if: ${{ inputs.test-emoji }} run: npm run grunt precommit:emoji env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/callable-test-gutenberg-build-process.yml b/.github/workflows/reusable-test-gutenberg-build-process.yml similarity index 98% rename from .github/workflows/callable-test-gutenberg-build-process.yml rename to .github/workflows/reusable-test-gutenberg-build-process.yml index 755b169caee92..150e40d109119 100644 --- a/.github/workflows/callable-test-gutenberg-build-process.yml +++ b/.github/workflows/reusable-test-gutenberg-build-process.yml @@ -1,5 +1,5 @@ ## -# A callable workflow that tests the Gutenberg plugin build process when run within a wordpress-develop checkout. +# A reusable workflow that tests the Gutenberg plugin build process when run within a wordpress-develop checkout. ## name: Test the Gutenberg plugin Build Process diff --git a/.github/workflows/upgrade-testing-run.yml b/.github/workflows/reusable-upgrade-testing.yml similarity index 98% rename from .github/workflows/upgrade-testing-run.yml rename to .github/workflows/reusable-upgrade-testing.yml index 0235d38f95b76..8e467c20ccbc9 100644 --- a/.github/workflows/upgrade-testing-run.yml +++ b/.github/workflows/reusable-upgrade-testing.yml @@ -1,4 +1,4 @@ -# A callable workflow that runs WordPress upgrade testing under the conditions provided. +# A reusable workflow that runs WordPress upgrade testing under the conditions provided. name: Upgrade Tests on: diff --git a/.github/workflows/test-build-processes.yml b/.github/workflows/test-build-processes.yml index e768c01a0b3e0..6e8ee69ec6770 100644 --- a/.github/workflows/test-build-processes.yml +++ b/.github/workflows/test-build-processes.yml @@ -31,7 +31,7 @@ jobs: # Tests the WordPress Core build process on multiple operating systems. test-core-build-process: name: Core running from ${{ matrix.directory }} - uses: WordPress/wordpress-develop/.github/workflows/callable-test-core-build-process.yml@trunk + uses: WordPress/wordpress-develop/.github/workflows/reusable-test-core-build-process.yml@trunk permissions: contents: read if: ${{ github.repository == 'WordPress/wordpress-develop' || github.event_name == 'pull_request' }} @@ -54,7 +54,7 @@ jobs: # See https://docs.github.com/en/actions/learn-github-actions/contexts#context-availability. test-core-build-process-macos: name: Core running from ${{ matrix.directory }} - uses: WordPress/wordpress-develop/.github/workflows/callable-test-core-build-process.yml@trunk + uses: WordPress/wordpress-develop/.github/workflows/reusable-test-core-build-process.yml@trunk permissions: contents: read if: ${{ github.repository == 'WordPress/wordpress-develop' }} @@ -70,7 +70,7 @@ jobs: # Tests the Gutenberg plugin build process on multiple operating systems when run within a wordpress-develop checkout. test-gutenberg-build-process: name: Gutenberg running from ${{ matrix.directory }} - uses: WordPress/wordpress-develop/.github/workflows/callable-test-gutenberg-build-process.yml@trunk + uses: WordPress/wordpress-develop/.github/workflows/reusable-test-gutenberg-build-process.yml@trunk permissions: contents: read if: ${{ github.repository == 'WordPress/wordpress-develop' || github.event_name == 'pull_request' }} @@ -93,7 +93,7 @@ jobs: # See https://docs.github.com/en/actions/learn-github-actions/contexts#context-availability. test-gutenberg-build-process-macos: name: Gutenberg running from ${{ matrix.directory }} - uses: WordPress/wordpress-develop/.github/workflows/callable-test-gutenberg-build-process.yml@trunk + uses: WordPress/wordpress-develop/.github/workflows/reusable-test-gutenberg-build-process.yml@trunk permissions: contents: read if: ${{ github.repository == 'WordPress/wordpress-develop' }} diff --git a/.github/workflows/upgrade-testing.yml b/.github/workflows/upgrade-testing.yml index fe2d4dc24fae5..1ffe4bfc585ac 100644 --- a/.github/workflows/upgrade-testing.yml +++ b/.github/workflows/upgrade-testing.yml @@ -35,7 +35,7 @@ jobs: # Spawns upgrade testing from WordPress 6.x versions with MySQL. upgrade-tests-wp-6x-mysql: name: ${{ matrix.wp }} to ${{ inputs.new-version && inputs.new-version || 'latest' }} - uses: WordPress/wordpress-develop/.github/workflows/upgrade-testing-run.yml@trunk + uses: WordPress/wordpress-develop/.github/workflows/reusable-upgrade-testing.yml@trunk if: ${{ github.repository == 'WordPress/wordpress-develop' || github.event_name == 'pull_request' }} permissions: contents: read @@ -60,7 +60,7 @@ jobs: # Spawns upgrade testing from WordPress 5.x versions on PHP 7.x with MySQL. upgrade-tests-wp-5x-php-7x-mysql: name: ${{ matrix.wp }} to ${{ inputs.new-version && inputs.new-version || 'latest' }} - uses: WordPress/wordpress-develop/.github/workflows/upgrade-testing-run.yml@trunk + uses: WordPress/wordpress-develop/.github/workflows/reusable-upgrade-testing.yml@trunk if: ${{ github.repository == 'WordPress/wordpress-develop' || github.event_name == 'pull_request' }} strategy: fail-fast: false @@ -87,7 +87,7 @@ jobs: # - array/string offset with curly braces. upgrade-tests-wp-5x-php-8x-mysql: name: ${{ matrix.wp }} to ${{ inputs.new-version && inputs.new-version || 'latest' }} - uses: WordPress/wordpress-develop/.github/workflows/upgrade-testing-run.yml@trunk + uses: WordPress/wordpress-develop/.github/workflows/reusable-upgrade-testing.yml@trunk if: ${{ github.repository == 'WordPress/wordpress-develop' || github.event_name == 'pull_request' }} strategy: fail-fast: false @@ -110,7 +110,7 @@ jobs: # Spawns upgrade testing from WordPress 4.x versions on PHP 7.x with MySQL. upgrade-tests-wp-4x-php-7x-mysql: name: ${{ matrix.wp }} to ${{ inputs.new-version && inputs.new-version || 'latest' }} - uses: WordPress/wordpress-develop/.github/workflows/upgrade-testing-run.yml@trunk + uses: WordPress/wordpress-develop/.github/workflows/reusable-upgrade-testing.yml@trunk if: ${{ github.repository == 'WordPress/wordpress-develop' || github.event_name == 'pull_request' }} strategy: fail-fast: false @@ -137,7 +137,7 @@ jobs: # - array/string offset with curly braces. upgrade-tests-wp-4x-php-8x-mysql: name: ${{ matrix.wp }} to ${{ inputs.new-version && inputs.new-version || 'latest' }} - uses: WordPress/wordpress-develop/.github/workflows/upgrade-testing-run.yml@trunk + uses: WordPress/wordpress-develop/.github/workflows/reusable-upgrade-testing.yml@trunk if: ${{ github.repository == 'WordPress/wordpress-develop' || github.event_name == 'pull_request' }} strategy: fail-fast: false