Make WordPress Core


Ignore:
Timestamp:
10/24/2024 03:07:06 PM (7 months ago)
Author:
desrosj
Message:

Build/Test Tools: Use the reusable PHPUnit test workflow for coverage.

This updates the Test Coverage workflow to make use of the reusable PHPUnit test workflow to avoid having duplicate code.

concurrency has also been configured for the workflow, and 4 test jobs have been consolidated into 2.

Props jrf.
Fixes #62296.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/.github/workflows/reusable-phpunit-tests-v3.yml

    r59251 r59287  
    5353        type: 'string'
    5454        default: 'example.org'
     55      coverage-report:
     56        description: 'Whether to generate a code coverage report.'
     57        required: false
     58        type: boolean
     59        default: false
    5560      report:
    5661        description: 'Whether to report results to WordPress.org Hosting Tests'
     
    6368        type: boolean
    6469        default: false
     70    secrets:
     71      CODECOV_TOKEN:
     72        description: 'The Codecov token required for uploading reports.'
     73        required: false
    6574env:
    6675  LOCAL_PHP: ${{ inputs.php }}-fpm
     76  LOCAL_PHP_XDEBUG: ${{ inputs.coverage-report || false }}
     77  LOCAL_PHP_XDEBUG_MODE: ${{ inputs.coverage-report && 'coverage' || 'develop,debug' }}
    6778  LOCAL_DB_TYPE: ${{ inputs.db-type }}
    6879  LOCAL_DB_VERSION: ${{ inputs.db-version }}
     
    89100  # - Install WordPress within the Docker container.
    90101  # - Run the PHPUnit tests.
     102  # - Upload the code coverage report to Codecov.io.
     103  # - Upload the HTML code coverage report as an artifact.
    91104  # - Ensures version-controlled files are not modified or deleted.
    92105  # - Checks out the WordPress Test reporter repository.
    93106  # - Submit the test results to the WordPress.org host test results.
    94107  phpunit-tests:
    95     name: PHP ${{ inputs.php }} / ${{ 'mariadb' == inputs.db-type && 'MariaDB' || 'MySQL' }} ${{ inputs.db-version }}${{ inputs.multisite && ' multisite' || '' }}${{ inputs.phpunit-test-groups && format( ' ({0})', inputs.phpunit-test-groups ) || '' }}${{ inputs.memcached && ' with memcached' || '' }}${{ inputs.report && ' (test reporting enabled)' || '' }} ${{ 'example.org' != inputs.tests-domain && inputs.tests-domain || '' }}
     108    name: PHP ${{ inputs.php }} ${{ ! inputs.coverage-report && '/ ' || 'with ' }}${{ 'mariadb' == inputs.db-type && 'MariaDB' || 'MySQL' }} ${{ inputs.db-version }}${{ inputs.multisite && ' multisite' || '' }}${{ inputs.phpunit-test-groups && format( ' ({0})', inputs.phpunit-test-groups ) || '' }}${{ inputs.memcached && ' with memcached' || '' }}${{ inputs.report && ' (test reporting enabled)' || '' }} ${{ 'example.org' != inputs.tests-domain && inputs.tests-domain || '' }}
    96109    runs-on: ${{ inputs.os }}
    97     timeout-minutes: 20
     110    timeout-minutes: ${{ inputs.coverage-report && 120 || 20 }}
    98111
    99112    steps:
     
    168181        run: npm run env:install
    169182
    170       - name: Run PHPUnit tests${{ inputs.phpunit-test-groups && format( ' ({0} groups)', inputs.phpunit-test-groups ) || '' }}
    171         continue-on-error: ${{ inputs.allow-errors }}
    172         run: node ./tools/local-env/scripts/docker.js run php ./vendor/bin/phpunit --verbose -c ${{ env.PHPUNIT_CONFIG }}${{ inputs.phpunit-test-groups && format( ' --group {0}', inputs.phpunit-test-groups ) || '' }}
     183      - name: Run PHPUnit tests${{ inputs.phpunit-test-groups && format( ' ({0} groups)', inputs.phpunit-test-groups ) || '' }}${{ inputs.coverage-report && ' with coverage report' || '' }}
     184        continue-on-error: ${{ inputs.allow-errors }}
     185        run: node ./tools/local-env/scripts/docker.js run php ./vendor/bin/phpunit --verbose -c ${{ env.PHPUNIT_CONFIG }}${{ inputs.phpunit-test-groups && format( ' --group {0}', inputs.phpunit-test-groups ) || '' }}${{ inputs.coverage-report && format( ' --coverage-clover wp-code-coverage-{0}-{1}.xml --coverage-html wp-code-coverage-{0}-{1}', ( inputs.multisite && 'multisite' || 'single' ), github.sha ) || '' }}
    173186
    174187      - name: Run AJAX tests
    175         if: ${{ ! inputs.phpunit-test-groups }}
     188        if: ${{ ! inputs.phpunit-test-groups && ! inputs.coverage-report }}
    176189        continue-on-error: ${{ inputs.allow-errors }}
    177190        run: node ./tools/local-env/scripts/docker.js run php ./vendor/bin/phpunit --verbose -c ${{ env.PHPUNIT_CONFIG }} --group ajax
    178191
    179192      - name: Run ms-files tests as a multisite install
    180         if: ${{ inputs.multisite && ! inputs.phpunit-test-groups }}
     193        if: ${{ inputs.multisite && ! inputs.phpunit-test-groups && ! inputs.coverage-report }}
    181194        continue-on-error: ${{ inputs.allow-errors }}
    182195        run: node ./tools/local-env/scripts/docker.js run php ./vendor/bin/phpunit --verbose -c ${{ env.PHPUNIT_CONFIG }} --group ms-files
    183196
    184197      - name: Run external HTTP tests
    185         if: ${{ ! inputs.multisite && ! inputs.phpunit-test-groups }}
     198        if: ${{ ! inputs.multisite && ! inputs.phpunit-test-groups && ! inputs.coverage-report }}
    186199        continue-on-error: ${{ inputs.allow-errors }}
    187200        run: node ./tools/local-env/scripts/docker.js run php ./vendor/bin/phpunit --verbose -c ${{ env.PHPUNIT_CONFIG }} --group external-http
     
    189202      # __fakegroup__ is excluded to force PHPUnit to ignore the <exclude> settings in phpunit.xml.dist.
    190203      - name: Run (Xdebug) tests
    191         if: ${{ inputs.php != '8.4' && ! inputs.phpunit-test-groups }}
     204        if: ${{ inputs.php != '8.4' && ! inputs.phpunit-test-groups && ! inputs.coverage-report }}
    192205        continue-on-error: ${{ inputs.allow-errors }}
    193206        run: LOCAL_PHP_XDEBUG=true node ./tools/local-env/scripts/docker.js run php ./vendor/bin/phpunit -v --group xdebug --exclude-group __fakegroup__
     207
     208      - name: Upload test coverage report to Codecov
     209        if: ${{ inputs.coverage-report }}
     210        uses: codecov/codecov-action@b9fd7d16f6d7d1b5d2bec1a2887e65ceed900238 # v4.6.0
     211        with:
     212          token: ${{ secrets.CODECOV_TOKEN }}
     213          file: wp-code-coverage${{ inputs.multisite && '-multisite' || '-single' }}-${{ github.sha }}.xml
     214          flags: ${{ inputs.multisite && 'multisite' || 'single' }},php
     215          fail_ci_if_error: true
     216
     217      - name: Upload HTML coverage report as artifact
     218        if: ${{ inputs.coverage-report }}
     219        uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
     220        with:
     221          name: wp-code-coverage${{ inputs.multisite && '-multisite' || '-single' }}-${{ github.sha }}
     222          path: wp-code-coverage${{ inputs.multisite && '-multisite' || '-single' }}-${{ github.sha }}
     223          overwrite: true
    194224
    195225      - name: Ensure version-controlled files are not modified or deleted
Note: See TracChangeset for help on using the changeset viewer.