Make WordPress Core


Ignore:
Timestamp:
05/02/2024 01:57:49 PM (14 months ago)
Author:
swissspidy
Message:

Build/Test Tools: Overhaul performance tests to improve stability and cover more scenarios.

Simplifies the tests setup by leveraging a test matrix, improving maintenance and making it much easier to test more scenarios. With this change, tests are now also run with an external object cache (Memcached). Additional information such as memory usage and the number of database queries is now collected as well.

Improves test setup and cleanup by disabling external HTTP requests and cron for the tests, as well as deleting expired transients and flushing the cache in-between. This should aid the test stability.

When testing the previous commit / target branch, this now leverages the already built artifact from the build process workflow. Raw test results are now also uploaded as artifacts to aid debugging.

Props swissspidy, adamsilverstein, joemcgill, mukesh27, desrosj, youknowriad, flixos90.
Fixes #59900

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/.github/workflows/performance.yml

    r57918 r58076  
    6767  # - Install WordPress Importer plugin.
    6868  # - Import mock data.
     69  # - Deactivate WordPress Importer plugin.
    6970  # - Update permalink structure.
     71  # - Install additional languages.
     72  # - Disable external HTTP requests.
     73  # - Disable cron.
     74  # - List defined constants.
    7075  # - Install MU plugin.
    7176  # - Run performance tests (current commit).
    72   # - Print performance tests results.
    73   # - Check out target commit (target branch or previous commit).
    74   # - Switch Node.js versions if necessary.
    75   # - Install npm dependencies.
    76   # - Build WordPress.
     77  # - Download previous build artifact (target branch or previous commit).
     78  # - Download artifact.
     79  # - Unzip the build.
    7780  # - Run any database upgrades.
     81  # - Flush cache.
     82  # - Delete expired transients.
    7883  # - Run performance tests (previous/target commit).
    79   # - Print target performance tests results.
    80   # - Reset to original commit.
    81   # - Switch Node.js versions if necessary.
    82   # - Install npm dependencies.
    8384  # - Set the environment to the baseline version.
    8485  # - Run any database upgrades.
     86  # - Flush cache.
     87  # - Delete expired transients.
    8588  # - Run baseline performance tests.
    86   # - Print baseline performance tests results.
    87   # - Compare results with base.
     89  # - Archive artifacts.
     90  # - Compare results.
    8891  # - Add workflow summary.
    8992  # - Set the base sha.
     
    9194  # - Publish performance results.
    9295  # - Ensure version-controlled files are not modified or deleted.
    93   # - Dispatch workflow run.
    9496  performance:
    95     name: Run performance tests
     97    name: Run performance tests ${{ matrix.memcached && '(with memcached)' || '' }}
    9698    runs-on: ubuntu-latest
    9799    permissions:
    98100      contents: read
    99101    if: ${{ ( github.repository == 'WordPress/wordpress-develop' || github.event_name == 'pull_request' ) && ! contains( github.event.before, '00000000' ) }}
    100 
     102    strategy:
     103      fail-fast: false
     104      matrix:
     105        memcached: [ true, false ]
     106    env:
     107      LOCAL_PHP_MEMCACHED: ${{ matrix.memcached }}
    101108    steps:
    102109      - name: Configure environment variables
     
    128135
    129136      - name: Install Playwright browsers
    130         run: npx playwright install --with-deps
     137        run: npx playwright install --with-deps chromium
    131138
    132139      - name: Build WordPress
     
    134141
    135142      - name: Start Docker environment
    136         run: |
    137           npm run env:start
     143        run: npm run env:start
     144
     145      - name: Install object cache drop-in
     146        if: ${{ matrix.memcached }}
     147        run: cp src/wp-content/object-cache.php build/wp-content/object-cache.php
    138148
    139149      - name: Log running Docker containers
     
    161171          rm themeunittestdata.wordpress.xml
    162172
     173      - name: Deactivate WordPress Importer plugin
     174        run: npm run env:cli -- plugin deactivate wordpress-importer --path=/var/www/${{ env.LOCAL_DIR }}
     175
    163176      - name: Update permalink structure
    164         run: |
    165           npm run env:cli -- rewrite structure '/%year%/%monthnum%/%postname%/' --path=/var/www/${{ env.LOCAL_DIR }}
     177        run: npm run env:cli -- rewrite structure '/%year%/%monthnum%/%postname%/' --path=/var/www/${{ env.LOCAL_DIR }}
    166178
    167179      - name: Install additional languages
     
    171183          npm run env:cli -- language theme install de_DE --all --path=/var/www/${{ env.LOCAL_DIR }}
    172184
     185      # Prevent background update checks from impacting test stability.
     186      - name: Disable external HTTP requests
     187        run: npm run env:cli -- config set WP_HTTP_BLOCK_EXTERNAL true --raw --type=constant --path=/var/www/${{ env.LOCAL_DIR }}
     188
     189      # Prevent background tasks from impacting test stability.
     190      - name: Disable cron
     191        run: npm run env:cli -- config set DISABLE_WP_CRON true --raw --type=constant --path=/var/www/${{ env.LOCAL_DIR }}
     192
     193      - name: List defined constants
     194        run: npm run env:cli -- config list --path=/var/www/${{ env.LOCAL_DIR }}
     195
    173196      - name: Install MU plugin
    174197        run: |
     
    179202        run: npm run test:performance
    180203
    181       - name: Print performance tests results
    182         run: node ./tests/performance/results.js
    183 
    184       - name: Check out target commit (target branch or previous commit)
    185         run: |
    186           if [[ -z "$TARGET_REF" ]]; then
    187             git fetch -n origin $TARGET_SHA
    188           else
    189             git fetch -n origin $TARGET_REF
    190           fi
    191           git reset --hard $TARGET_SHA
    192 
    193       - name: Set up Node.js
    194         uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2
    195         with:
    196           node-version-file: '.nvmrc'
    197           cache: npm
    198 
    199       - name: Install npm dependencies
    200         run: npm ci
    201 
    202       - name: Build WordPress
    203         run: npm run build
     204      - name: Download previous build artifact (target branch or previous commit)
     205        uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
     206        id: get-previous-build
     207        with:
     208          script: |
     209            const artifacts = await github.rest.actions.listArtifactsForRepo({
     210              owner: context.repo.owner,
     211              repo: context.repo.repo,
     212              name: 'wordpress-build-' + process.env.TARGET_SHA,
     213            });
     214
     215            const matchArtifact = artifacts.data.artifacts[0];
     216
     217            if ( ! matchArtifact ) {
     218              core.setFailed( 'No artifact found!' );
     219              return false;
     220            }
     221
     222            const download = await github.rest.actions.downloadArtifact( {
     223              owner: context.repo.owner,
     224              repo: context.repo.repo,
     225              artifact_id: matchArtifact.id,
     226              archive_format: 'zip',
     227            } );
     228
     229            const fs = require( 'fs' );
     230            fs.writeFileSync( '${{ github.workspace }}/before.zip', Buffer.from( download.data ) )
     231
     232            return true;
     233
     234      - name: Unzip the build
     235        if: ${{ steps.get-previous-build.outputs.result }}
     236        run: |
     237          unzip ${{ github.workspace }}/before.zip
     238          unzip -o ${{ github.workspace }}/wordpress.zip
    204239
    205240      - name: Run any database upgrades
     241        if: ${{ steps.get-previous-build.outputs.result }}
    206242        run: npm run env:cli -- core update-db --path=/var/www/${{ env.LOCAL_DIR }}
    207243
    208       - name: Run target performance tests (base/previous commit)
     244      - name: Flush cache
     245        if: ${{ steps.get-previous-build.outputs.result }}
     246        run: npm run env:cli -- cache flush --path=/var/www/${{ env.LOCAL_DIR }}
     247
     248      - name: Delete expired transients
     249        if: ${{ steps.get-previous-build.outputs.result }}
     250        run: npm run env:cli -- transient delete --expired --path=/var/www/${{ env.LOCAL_DIR }}
     251
     252      - name: Run target performance tests (previous/target commit)
     253        if: ${{ steps.get-previous-build.outputs.result }}
    209254        env:
    210255          TEST_RESULTS_PREFIX: before
    211256        run: npm run test:performance
    212257
    213       - name: Print target performance tests results
    214         env:
    215           TEST_RESULTS_PREFIX: before
    216         run: node ./tests/performance/results.js
    217 
    218       - name: Reset to original commit
    219         run: git reset --hard $GITHUB_SHA
    220 
    221       - name: Set up Node.js
    222         uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2
    223         with:
    224           node-version-file: '.nvmrc'
    225           cache: npm
    226 
    227       - name: Install npm dependencies
    228         run: npm ci
    229 
    230258      - name: Set the environment to the baseline version
     259        if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/trunk' }}
    231260        run: |
    232261          npm run env:cli -- core update --version=${{ env.BASE_TAG }} --force --path=/var/www/${{ env.LOCAL_DIR }}
     
    234263
    235264      - name: Run any database upgrades
     265        if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/trunk' }}
    236266        run: npm run env:cli -- core update-db --path=/var/www/${{ env.LOCAL_DIR }}
    237267
     268      - name: Flush cache
     269        if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/trunk' }}
     270        run: npm run env:cli -- cache flush --path=/var/www/${{ env.LOCAL_DIR }}
     271
     272      - name: Delete expired transients
     273        if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/trunk' }}
     274        run: npm run env:cli -- transient delete --expired --path=/var/www/${{ env.LOCAL_DIR }}
     275
    238276      - name: Run baseline performance tests
     277        if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/trunk' }}
    239278        env:
    240279          TEST_RESULTS_PREFIX: base
    241280        run: npm run test:performance
    242281
    243       - name: Print baseline performance tests results
    244         env:
    245           TEST_RESULTS_PREFIX: base
    246         run: node ./tests/performance/results.js
    247 
    248       - name: Compare results with base
     282      - name: Archive artifacts
     283        uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1
     284        if: always()
     285        with:
     286          name: performance-artifacts${{ matrix.memcached && '-memcached' || '' }}-${{ github.run_id }}
     287          path: artifacts
     288          if-no-files-found: ignore
     289
     290      - name: Compare results
    249291        run: node ./tests/performance/compare-results.js ${{ runner.temp }}/summary.md
    250292
     
    254296      - name: Set the base sha
    255297        # Only needed when publishing results.
    256         if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/trunk' }}
     298        if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/trunk' && ! matrix.memcached }}
    257299        uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
    258300        id: base-sha
     
    265307      - name: Set commit details
    266308        # Only needed when publishing results.
    267         if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/trunk' }}
     309        if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/trunk' && ! matrix.memcached }}
    268310        uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
    269311        id: commit-timestamp
     
    276318      - name: Publish performance results
    277319        # Only publish results on pushes to trunk.
    278         if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/trunk' }}
     320        if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/trunk' && ! matrix.memcached }}
    279321        env:
    280322            BASE_SHA: ${{ steps.base-sha.outputs.result }}
Note: See TracChangeset for help on using the changeset viewer.