Make WordPress Core


Ignore:
Timestamp:
05/17/2024 05:41:40 PM (14 months ago)
Author:
desrosj
Message:

Build/Test Tools: Convert GitHub action workflows into reusable ones.

With a few exceptions, GitHub Actions workflows run using the version of the workflow file present in the commit SHA or Git ref for the triggering event. This is useful for maintaining different versions of a workflow file.

In the case of WordPress where there are currently 25+ branches that could potentially receive a security fix, it creates a huge maintenance burden. When 3rd party actions are updated or features are deprecated on GitHub Actions, the required changes need to be backported to all of those branches. This takes considerable time and effort.

This change converts Core’s workflow files to reusable ones. This allows the same workflow to be used for all (or most) branches, allowing the described maintenance updates to be made once in trunk.

To keep track of which files are reusable vs. those that are responsible for holding the strategy matrix for that branch, reusable workflows are now prefixed with reusable-.

Props johnbillion, swissspidy, jorbin, desrosj.
Fixes #61213.

File:
1 edited

Legend:

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

    r58076 r58165  
    3030permissions: {}
    3131
    32 env:
    33   PUPPETEER_SKIP_DOWNLOAD: ${{ true }}
    34 
    35   # Performance testing should be performed in an environment reflecting a standard production environment.
    36   LOCAL_WP_DEBUG: false
    37   LOCAL_SCRIPT_DEBUG: false
    38   LOCAL_SAVEQUERIES: false
    39   LOCAL_WP_DEVELOPMENT_MODE: "''"
    40 
    41   # This workflow takes two sets of measurements — one for the current commit,
    42   # and another against a consistent version that is used as a baseline measurement.
    43   # This is done to isolate variance in measurements caused by the GitHub runners
    44   # from differences caused by code changes between commits. The BASE_TAG value here
    45   # represents the version being used for baseline measurements. It should only be
    46   # changed if we want to normalize results against a different baseline.
    47   BASE_TAG: '6.1.1'
    48   LOCAL_DIR: build
    49   TARGET_REF: ${{ github.event_name == 'pull_request' && github.event.pull_request.base.ref || '' }}
    50   TARGET_SHA: ${{ github.event_name == 'pull_request' && github.event.pull_request.base.sha || github.event.before }}
    51 
    5232jobs:
    5333  # Runs the performance test suite.
    54   #
    55   # Performs the following steps:
    56   # - Configure environment variables.
    57   # - Checkout repository.
    58   # - Set up Node.js.
    59   # - Log debug information.
    60   # - Install npm dependencies.
    61   # - Install Playwright browsers.
    62   # - Build WordPress.
    63   # - Start Docker environment.
    64   # - Log running Docker containers.
    65   # - Docker debug information.
    66   # - Install WordPress.
    67   # - Install WordPress Importer plugin.
    68   # - Import mock data.
    69   # - Deactivate WordPress Importer plugin.
    70   # - Update permalink structure.
    71   # - Install additional languages.
    72   # - Disable external HTTP requests.
    73   # - Disable cron.
    74   # - List defined constants.
    75   # - Install MU plugin.
    76   # - Run performance tests (current commit).
    77   # - Download previous build artifact (target branch or previous commit).
    78   # - Download artifact.
    79   # - Unzip the build.
    80   # - Run any database upgrades.
    81   # - Flush cache.
    82   # - Delete expired transients.
    83   # - Run performance tests (previous/target commit).
    84   # - Set the environment to the baseline version.
    85   # - Run any database upgrades.
    86   # - Flush cache.
    87   # - Delete expired transients.
    88   # - Run baseline performance tests.
    89   # - Archive artifacts.
    90   # - Compare results.
    91   # - Add workflow summary.
    92   # - Set the base sha.
    93   # - Set commit details.
    94   # - Publish performance results.
    95   # - Ensure version-controlled files are not modified or deleted.
    9634  performance:
    97     name: Run performance tests ${{ matrix.memcached && '(with memcached)' || '' }}
    98     runs-on: ubuntu-latest
     35    name: Performance tests ${{ matrix.memcached && '(with memcached)' || '' }}
     36    uses: WordPress/wordpress-develop/.github/workflows/reusable-performance.yml@trunk
    9937    permissions:
    10038      contents: read
     
    10442      matrix:
    10543        memcached: [ true, false ]
    106     env:
    107       LOCAL_PHP_MEMCACHED: ${{ matrix.memcached }}
    108     steps:
    109       - name: Configure environment variables
    110         run: |
    111           echo "PHP_FPM_UID=$(id -u)" >> $GITHUB_ENV
    112           echo "PHP_FPM_GID=$(id -g)" >> $GITHUB_ENV
    113 
    114       - name: Checkout repository
    115         uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
    116         with:
    117           show-progress: ${{ runner.debug == '1' && 'true' || 'false' }}
    118 
    119       - name: Set up Node.js
    120         uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2
    121         with:
    122           node-version-file: '.nvmrc'
    123           cache: npm
    124 
    125       - name: Log debug information
    126         run: |
    127           npm --version
    128           node --version
    129           curl --version
    130           git --version
    131           locale -a
    132 
    133       - name: Install npm dependencies
    134         run: npm ci
    135 
    136       - name: Install Playwright browsers
    137         run: npx playwright install --with-deps chromium
    138 
    139       - name: Build WordPress
    140         run: npm run build
    141 
    142       - name: Start Docker environment
    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
    148 
    149       - name: Log running Docker containers
    150         run: docker ps -a
    151 
    152       - name: Docker debug information
    153         run: |
    154           docker -v
    155           docker compose run --rm mysql mysql --version
    156           docker compose run --rm php php --version
    157           docker compose run --rm php php -m
    158           docker compose run --rm php php -i
    159           docker compose run --rm php locale -a
    160 
    161       - name: Install WordPress
    162         run: npm run env:install
    163 
    164       - name: Install WordPress Importer plugin
    165         run: npm run env:cli -- plugin install wordpress-importer --activate --path=/var/www/${{ env.LOCAL_DIR }}
    166 
    167       - name: Import mock data
    168         run: |
    169           curl -O https://raw.githubusercontent.com/WordPress/theme-test-data/b9752e0533a5acbb876951a8cbb5bcc69a56474c/themeunittestdata.wordpress.xml
    170           npm run env:cli -- import themeunittestdata.wordpress.xml --authors=create --path=/var/www/${{ env.LOCAL_DIR }}
    171           rm themeunittestdata.wordpress.xml
    172 
    173       - name: Deactivate WordPress Importer plugin
    174         run: npm run env:cli -- plugin deactivate wordpress-importer --path=/var/www/${{ env.LOCAL_DIR }}
    175 
    176       - name: Update permalink structure
    177         run: npm run env:cli -- rewrite structure '/%year%/%monthnum%/%postname%/' --path=/var/www/${{ env.LOCAL_DIR }}
    178 
    179       - name: Install additional languages
    180         run: |
    181           npm run env:cli -- language core install de_DE --path=/var/www/${{ env.LOCAL_DIR }}
    182           npm run env:cli -- language plugin install de_DE --all --path=/var/www/${{ env.LOCAL_DIR }}
    183           npm run env:cli -- language theme install de_DE --all --path=/var/www/${{ env.LOCAL_DIR }}
    184 
    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 
    196       - name: Install MU plugin
    197         run: |
    198           mkdir ./${{ env.LOCAL_DIR }}/wp-content/mu-plugins
    199           cp ./tests/performance/wp-content/mu-plugins/server-timing.php ./${{ env.LOCAL_DIR }}/wp-content/mu-plugins/server-timing.php
    200 
    201       - name: Run performance tests (current commit)
    202         run: npm run test:performance
    203 
    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
    239 
    240       - name: Run any database upgrades
    241         if: ${{ steps.get-previous-build.outputs.result }}
    242         run: npm run env:cli -- core update-db --path=/var/www/${{ env.LOCAL_DIR }}
    243 
    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 }}
    254         env:
    255           TEST_RESULTS_PREFIX: before
    256         run: npm run test:performance
    257 
    258       - name: Set the environment to the baseline version
    259         if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/trunk' }}
    260         run: |
    261           npm run env:cli -- core update --version=${{ env.BASE_TAG }} --force --path=/var/www/${{ env.LOCAL_DIR }}
    262           npm run env:cli -- core version --path=/var/www/${{ env.LOCAL_DIR }}
    263 
    264       - name: Run any database upgrades
    265         if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/trunk' }}
    266         run: npm run env:cli -- core update-db --path=/var/www/${{ env.LOCAL_DIR }}
    267 
    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 
    276       - name: Run baseline performance tests
    277         if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/trunk' }}
    278         env:
    279           TEST_RESULTS_PREFIX: base
    280         run: npm run test:performance
    281 
    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
    291         run: node ./tests/performance/compare-results.js ${{ runner.temp }}/summary.md
    292 
    293       - name: Add workflow summary
    294         run: cat ${{ runner.temp }}/summary.md >> $GITHUB_STEP_SUMMARY
    295 
    296       - name: Set the base sha
    297         # Only needed when publishing results.
    298         if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/trunk' && ! matrix.memcached }}
    299         uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
    300         id: base-sha
    301         with:
    302             github-token: ${{ secrets.GITHUB_TOKEN }}
    303             script: |
    304                 const baseRef = await github.rest.git.getRef({ owner: context.repo.owner, repo: context.repo.repo, ref: 'tags/${{ env.BASE_TAG }}' });
    305                 return baseRef.data.object.sha;
    306 
    307       - name: Set commit details
    308         # Only needed when publishing results.
    309         if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/trunk' && ! matrix.memcached }}
    310         uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
    311         id: commit-timestamp
    312         with:
    313             github-token: ${{ secrets.GITHUB_TOKEN }}
    314             script: |
    315                 const commit_details = await github.rest.git.getCommit({ owner: context.repo.owner, repo: context.repo.repo, commit_sha: context.sha });
    316                 return parseInt((new Date( commit_details.data.author.date ).getTime() / 1000).toFixed(0))
    317 
    318       - name: Publish performance results
    319         # Only publish results on pushes to trunk.
    320         if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/trunk' && ! matrix.memcached }}
    321         env:
    322             BASE_SHA: ${{ steps.base-sha.outputs.result }}
    323             COMMITTED_AT: ${{ steps.commit-timestamp.outputs.result }}
    324             CODEVITALS_PROJECT_TOKEN: ${{ secrets.CODEVITALS_PROJECT_TOKEN }}
    325             HOST_NAME: "www.codevitals.run"
    326         run: node ./tests/performance/log-results.js $CODEVITALS_PROJECT_TOKEN trunk $GITHUB_SHA $BASE_SHA $COMMITTED_AT $HOST_NAME
    327 
    328       - name: Ensure version-controlled files are not modified or deleted
    329         run: git diff --exit-code
     44    with:
     45      memcached: ${{ matrix.memcached }}
    33046
    33147  slack-notifications:
Note: See TracChangeset for help on using the changeset viewer.