Make WordPress Core


Ignore:
Timestamp:
09/02/2026 06:21:17 PM (2 weeks ago)
Author:
lancewillett
Message:

Build/Test Tools: Allow PHPUnit workflows to test other repositories.

Add optional repository and ref inputs to the reusable PHPUnit and Gutenberg preparation workflows. Add a same-run overlay artifact for caller-provided tests.

Name prepared Gutenberg artifacts by ref, reject refs that cannot form artifact names, and retry Gutenberg downloads for older branches. Existing callers retain their current behavior.

Developed in: https://github.com/WordPress/wordpress-develop/pull/12862

Props lucatume.
Fixes #65964.

File:
1 edited

Legend:

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

    r63412 r63438  
    1414        type: 'string'
    1515        default: 'ubuntu-24.04'
     16      repository:
     17        description: 'The repository to check out and test. Defaults to the repository calling this workflow.'
     18        required: false
     19        type: 'string'
     20        default: ''
     21      # Also composes the Gutenberg build name, under the producer's constraint: a valid
     22      # artifact name, so no slashes and none of : < > | * ? "
     23      ref:
     24        description: 'The branch, tag, or SHA to check out. Defaults to the ref that triggered the calling workflow.'
     25        required: false
     26        type: 'string'
     27        default: ''
    1628      php:
    1729        description: 'The version of PHP to use, in the format of X.Y'
     
    8092      gutenberg-sha:
    8193        description: 'The immutable Gutenberg source SHA verified by the calling workflow.'
     94        required: false
     95        type: string
     96        default: ''
     97      overlay-artifact:
     98        description: 'The name of a same-workflow artifact whose contents are unpacked over the checkout. Optional: for callers whose test files are not part of the repository being tested.'
    8299        required: false
    83100        type: string
     
    113130  #
    114131  # Performs the following steps:
     132  # - Requires a ref when the caller points at another repository.
    115133  # - Sets environment variables.
    116134  # - Checks out the repository.
     135  # - Unpacks the caller-provided overlay artifact over the checkout, if any.
    117136  # - Downloads the prepared Gutenberg build provided by the calling workflow.
    118137  # - Sets up Node.js.
     
    141160
    142161    steps:
     162      # `ref` otherwise falls back to checkout's own default, which for another repository is
     163      # its default branch: a "WordPress 6.2" job would test trunk and report green.
     164      - name: Require a ref when testing another repository
     165        if: ${{ inputs.repository != '' && inputs.ref == '' }}
     166        run: |
     167          echo 'Testing another repository needs an explicit ref.' >&2
     168          exit 1
     169
     170      # `ref` also composes the Gutenberg artifact name, so reject what that name cannot carry
     171      # here rather than at a download step the job only reaches minutes later.
     172      - name: Require a ref the artifact name accepts
     173        if: ${{ inputs.ref != '' }}
     174        env:
     175          REF: ${{ inputs.ref }}
     176        run: |
     177          invalid='[/:<>|*?"\]'
     178          if [[ "$REF" =~ $invalid ]]; then
     179            echo "A ref that names an artifact cannot contain / : < > | * ? \" \\ - received: $REF" >&2
     180            exit 1
     181          fi
     182
    143183      - name: Configure environment variables
    144184        run: |
     
    149189        uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
    150190        with:
     191          repository: ${{ inputs.repository || github.repository }}
     192          ref: ${{ inputs.ref }}
    151193          show-progress: ${{ runner.debug == '1' && 'true' || 'false' }}
    152194          persist-credentials: false
     195
     196      # If the caller specifies an overlay artifact then unpack it over the checkout.
     197      - name: Download overlay artifact
     198        if: inputs.overlay-artifact != ''
     199        uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
     200        with:
     201          # Without a run ID, this action reads only from the caller's current workflow run.
     202          name: ${{ inputs.overlay-artifact }}
     203          path: .
     204          digest-mismatch: error
    153205
    154206      # Only WordPress 7.0+ include Gutenberg-maintained assets from a built zip file.
     
    157209        uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
    158210        with:
    159           name: gutenberg-build
     211          # Every branch in a run shares one artifact namespace, so the producer names each
     212          # build after the ref it came from. Compose the same name here rather than taking
     213          # it as an input: the two sides already agree on `ref`.
     214          name: gutenberg-build${{ inputs.ref && format( '-{0}', inputs.ref ) || '' }}
    160215          path: gutenberg
    161216          digest-mismatch: error
Note: See TracChangeset for help on using the changeset viewer.