-
Notifications
You must be signed in to change notification settings - Fork 72
Add GitHub action for easy remote test execution via GitHub Actions #245
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,139 @@ | ||||||||||||||||||||
| name: WordPress Host Test | ||||||||||||||||||||
| description: > | ||||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||
| Run the WordPress Host Test on a remote system reachable via SSH | ||||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||
|
|
||||||||||||||||||||
| inputs: | ||||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we list all |
||||||||||||||||||||
| report-api-key: | ||||||||||||||||||||
| description: > | ||||||||||||||||||||
| API key for reporting test results back to wordpress.org; if omitted, | ||||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While wordpress.org is the default, reports can be submitted to any site running the https://github.com/WordPress/phpunit-test-reporter plugin. |
||||||||||||||||||||
| test result reporting will be skipped. | ||||||||||||||||||||
| required: false | ||||||||||||||||||||
| remote-test-dir: | ||||||||||||||||||||
| description: > | ||||||||||||||||||||
| Remote directory in which tests will be run | ||||||||||||||||||||
| required: true | ||||||||||||||||||||
| database-host: | ||||||||||||||||||||
| description: > | ||||||||||||||||||||
| Database host for running the unit tests | ||||||||||||||||||||
| required: true | ||||||||||||||||||||
| database-user: | ||||||||||||||||||||
| description: > | ||||||||||||||||||||
| Database user for running the unit tests | ||||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we end all descriptions with periods, please? |
||||||||||||||||||||
| required: true | ||||||||||||||||||||
| database-password: | ||||||||||||||||||||
| description: > | ||||||||||||||||||||
| Database password for running the unit tests | ||||||||||||||||||||
| required: true | ||||||||||||||||||||
| database-name: | ||||||||||||||||||||
| description: > | ||||||||||||||||||||
| Database name for running the unit tests | ||||||||||||||||||||
| required: true | ||||||||||||||||||||
| ssh-connect: | ||||||||||||||||||||
| description: > | ||||||||||||||||||||
| SSH connection string (in the format username@host) for connecting to the | ||||||||||||||||||||
| hosting environment under test. | ||||||||||||||||||||
| required: true | ||||||||||||||||||||
| ssh-private-key: | ||||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
All other inputs match the corresponding environment variable name consumed by the runner itself. The exceptions to this are the |
||||||||||||||||||||
| description: > | ||||||||||||||||||||
| A base64-encoded SSH private key. | ||||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The description for each |
||||||||||||||||||||
| required: true | ||||||||||||||||||||
| test-filter: | ||||||||||||||||||||
| description: A regular expression to filter tests that should be run. | ||||||||||||||||||||
| default: '.*' | ||||||||||||||||||||
| runs: | ||||||||||||||||||||
| using: "composite" | ||||||||||||||||||||
| steps: | ||||||||||||||||||||
| - name: Checkout repository | ||||||||||||||||||||
| uses: actions/checkout@v4 | ||||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Third-party actions should always be pinned to a specific SHA value, which is currently the only immutable release supported (🤞 GH public roadmap). |
||||||||||||||||||||
| with: | ||||||||||||||||||||
| repository: WordPress/phpunit-test-runner | ||||||||||||||||||||
| path: runner | ||||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Unless credentials are explicitly required later in the job, credential persistence should always be disabled. |
||||||||||||||||||||
|
|
||||||||||||||||||||
| - name: Set up PHP | ||||||||||||||||||||
| uses: shivammathur/setup-php@cf4cade2721270509d5b1c766ab3549210a39a2a # v2.33.0 | ||||||||||||||||||||
| with: | ||||||||||||||||||||
| php-version: '8.4' | ||||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this should be configurable through an optional I think that |
||||||||||||||||||||
| coverage: none | ||||||||||||||||||||
|
|
||||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ideally, the version of Node.js used here will always match the version being used in https://github.com/wordpress/wordpress-develop at the commit being tested. I believe that this should checkout only the
Suggested change
This would allow the |
||||||||||||||||||||
| - name: Install NodeJS | ||||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there any reason not to pass |
||||||||||||||||||||
| uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0 | ||||||||||||||||||||
| with: | ||||||||||||||||||||
| node-version: 20 | ||||||||||||||||||||
|
|
||||||||||||||||||||
| - name: Prepare SSH private key | ||||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Curious if there was a reason why you decided to configure the key here instead of relying on the |
||||||||||||||||||||
| shell: bash | ||||||||||||||||||||
| if: ${{ inputs.ssh-private-key }} | ||||||||||||||||||||
| run: | | ||||||||||||||||||||
| mkdir -p ~/.ssh | ||||||||||||||||||||
| echo '${{ inputs.ssh-private-key }}' | base64 -d > ~/.ssh/id_rsa | ||||||||||||||||||||
| chmod 600 ~/.ssh/id_rsa | ||||||||||||||||||||
|
|
||||||||||||||||||||
| # This is added as a separate step to catch SSH connection errors (bad | ||||||||||||||||||||
| # credentials, or similar) early, since prepare.php takes a while before | ||||||||||||||||||||
| # even attempting an SSH connection. | ||||||||||||||||||||
| - name: Test SSH connectivity | ||||||||||||||||||||
| shell: bash | ||||||||||||||||||||
| run: | | ||||||||||||||||||||
| ssh -o StrictHostKeyChecking=no ${{ inputs.ssh-connect }} whoami | ||||||||||||||||||||
|
|
||||||||||||||||||||
| - name: Prepare environment | ||||||||||||||||||||
| env: | ||||||||||||||||||||
| WPT_PREPARE_DIR: /tmp/wp-tests | ||||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would the |
||||||||||||||||||||
| WPT_TEST_DIR: ${{ inputs.remote-test-dir }} | ||||||||||||||||||||
| WPT_DB_NAME: ${{ inputs.database-name }} | ||||||||||||||||||||
| WPT_DB_USER: ${{ inputs.database-user }} | ||||||||||||||||||||
| WPT_DB_PASSWORD: ${{ inputs.database-password }} | ||||||||||||||||||||
| WPT_DB_HOST: ${{ inputs.database-host }} | ||||||||||||||||||||
| WPT_SSH_CONNECT: ${{ inputs.ssh-connect }} | ||||||||||||||||||||
| run: php prepare.php | ||||||||||||||||||||
| shell: bash | ||||||||||||||||||||
| working-directory: ./runner | ||||||||||||||||||||
|
|
||||||||||||||||||||
| - name: Run unit tests | ||||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||
| run: php test.php | ||||||||||||||||||||
| continue-on-error: true | ||||||||||||||||||||
| shell: bash | ||||||||||||||||||||
| working-directory: ./runner | ||||||||||||||||||||
| env: | ||||||||||||||||||||
| WPT_PREPARE_DIR: /tmp/wp-tests | ||||||||||||||||||||
| WPT_TEST_DIR: ${{ inputs.remote-test-dir }} | ||||||||||||||||||||
| WPT_DB_NAME: ${{ inputs.database-name }} | ||||||||||||||||||||
| WPT_DB_USER: ${{ inputs.database-user }} | ||||||||||||||||||||
| WPT_DB_PASSWORD: ${{ inputs.database-password }} | ||||||||||||||||||||
| WPT_DB_HOST: ${{ inputs.database-host }} | ||||||||||||||||||||
| WPT_SSH_CONNECT: ${{ inputs.ssh-connect }} | ||||||||||||||||||||
| WPT_PHPUNIT_CMD: > | ||||||||||||||||||||
| cd ${{ inputs.remote-test-dir }} && | ||||||||||||||||||||
| ./vendor/phpunit/phpunit/phpunit | ||||||||||||||||||||
| --dont-report-useless-tests | ||||||||||||||||||||
| -c tests/phpunit/multisite.xml | ||||||||||||||||||||
| --filter '${{ inputs.test-filter }}' | ||||||||||||||||||||
|
|
||||||||||||||||||||
| - name: Report the results | ||||||||||||||||||||
| run: php report.php | ||||||||||||||||||||
| continue-on-error: true | ||||||||||||||||||||
| if: ${{ inputs.report-api-key }} | ||||||||||||||||||||
| shell: bash | ||||||||||||||||||||
| working-directory: ./runner | ||||||||||||||||||||
| env: | ||||||||||||||||||||
| WPT_REPORT_API_KEY: ${{ inputs.report-api-key }} | ||||||||||||||||||||
| WPT_PREPARE_DIR: /tmp/wp-tests | ||||||||||||||||||||
| WPT_TEST_DIR: ${{ inputs.remote-test-dir }} | ||||||||||||||||||||
| WPT_DB_NAME: ${{ inputs.database-name }} | ||||||||||||||||||||
| WPT_DB_USER: ${{ inputs.database-user }} | ||||||||||||||||||||
| WPT_DB_PASSWORD: ${{ inputs.database-password }} | ||||||||||||||||||||
| WPT_DB_HOST: ${{ inputs.database-host }} | ||||||||||||||||||||
| WPT_SSH_CONNECT: ${{ inputs.ssh-connect }} | ||||||||||||||||||||
|
|
||||||||||||||||||||
| - name: Cleanup | ||||||||||||||||||||
| run: php cleanup.php | ||||||||||||||||||||
| shell: bash | ||||||||||||||||||||
| working-directory: ./runner | ||||||||||||||||||||
| env: | ||||||||||||||||||||
| WPT_PREPARE_DIR: /tmp/wp-tests | ||||||||||||||||||||
| WPT_TEST_DIR: ${{ inputs.remote-test-dir }} | ||||||||||||||||||||
| WPT_DB_NAME: ${{ inputs.database-name }} | ||||||||||||||||||||
| WPT_DB_USER: ${{ inputs.database-user }} | ||||||||||||||||||||
| WPT_DB_PASSWORD: ${{ inputs.database-password }} | ||||||||||||||||||||
| WPT_DB_HOST: ${{ inputs.database-host }} | ||||||||||||||||||||
| WPT_SSH_CONNECT: ${{ inputs.ssh-connect }} | ||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Possible follow-up: Since the pipeline in
.github/workflows/tests.ymlalso appears to be intended as a template to be adopted by hosting providers in their own pipelines, that might possibly be dropped when/if this PR gets merged.