Skip to content

Commit 29ec312

Browse files
committed
Build/Test Tools: Introduce workflow for testing the local Docker environment.
While the PHPUnit workflow currently relies on the local Docker environment and provides some safety checks that the environment works as expected, this may not always be true and does not test all of the available commands related to the environment. This introduces a basic workflow for testing the related scripts for the various supported combinations of PHP and database software with the environment to confirm everything is working as expected. Ideally this would also be run on Windows and MacOS to catch platform specific bugs. Unfortunately, Docker is not supported within the GitHub Action runner images, so not all bugs will be caught by this workflow. Props johnbillion, Clorith. See #62221. git-svn-id: https://develop.svn.wordpress.org/trunk@59492 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 2d8d21f commit 29ec312

File tree

2 files changed

+314
-0
lines changed

2 files changed

+314
-0
lines changed
Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
name: Local Docker Environment
2+
3+
on:
4+
push:
5+
branches:
6+
- trunk
7+
- '6.[8-9]'
8+
- '[7-9].[0-9]'
9+
paths:
10+
# Any changes to Docker related files.
11+
- '.env.example'
12+
- 'docker-compose.yml'
13+
# Any changes to local environment related files
14+
- 'tools/local-env/**'
15+
# These files manage packages used by the local environment.
16+
- 'package*.json'
17+
# These files configure Composer. Changes could affect the local environment.
18+
- 'composer.*'
19+
# These files define the versions to test.
20+
- '.version-support-*.json'
21+
# Changes to this and related workflow files should always be verified.
22+
- '.github/workflows/local-docker-environment.yml'
23+
- '.github/workflows/reusable-support-json-reader-v1.yml'
24+
- '.github/workflows/reusable-test-docker-environment-v1.yml'
25+
pull_request:
26+
branches:
27+
- trunk
28+
- '6.[8-9]'
29+
- '[7-9].[0-9]'
30+
paths:
31+
# Any changes to Docker related files.
32+
- '.env.example'
33+
- 'docker-compose.yml'
34+
# Any changes to local environment related files
35+
- 'tools/local-env/**'
36+
# These files manage packages used by the local environment.
37+
- 'package*.json'
38+
# These files configure Composer. Changes could affect the local environment.
39+
- 'composer.*'
40+
# These files define the versions to test.
41+
- '.version-support-*.json'
42+
# Changes to this and related workflow files should always be verified.
43+
- '.github/workflows/local-docker-environment.yml'
44+
- '.github/workflows/reusable-support-json-reader-v1.yml'
45+
- '.github/workflows/reusable-test-docker-environment-v1.yml'
46+
workflow_dispatch:
47+
48+
# Cancels all previous workflow runs for pull requests that have not completed.
49+
concurrency:
50+
# The concurrency group contains the workflow name and the branch name for pull requests
51+
# or the commit hash for any other events.
52+
group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.head_ref || github.sha }}
53+
cancel-in-progress: true
54+
55+
# Disable permissions for all available scopes by default.
56+
# Any needed permissions should be configured at the job level.
57+
permissions: {}
58+
59+
jobs:
60+
#
61+
# Determines the appropriate supported values for PHP and database versions based on the WordPress
62+
# version being tested.
63+
#
64+
build-test-matrix:
65+
name: Build Test Matrix
66+
uses: WordPress/wordpress-develop/.github/workflows/reusable-support-json-reader-v1.yml@trunk
67+
permissions:
68+
contents: read
69+
secrets: inherit
70+
if: ${{ github.repository == 'WordPress/wordpress-develop' || github.event_name == 'pull_request' }}
71+
with:
72+
wp-version: ${{ github.event_name == 'pull_request' && github.base_ref || github.ref_name }}
73+
74+
# Tests the local Docker environment.
75+
environment-tests-mysql:
76+
name: PHP ${{ matrix.php }}
77+
uses: WordPress/wordpress-develop/.github/workflows/reusable-test-local-docker-environment-v1.yml@trunk
78+
permissions:
79+
contents: read
80+
if: ${{ github.repository == 'WordPress/wordpress-develop' || github.event_name == 'pull_request' }}
81+
needs: [ build-test-matrix ]
82+
strategy:
83+
fail-fast: false
84+
matrix:
85+
os: [ ubuntu-latest ]
86+
memcached: [ false, true ]
87+
php: ${{ fromJSON( needs.build-test-matrix.outputs.php-versions ) }}
88+
db-version: ${{ fromJSON( needs.build-test-matrix.outputs.mysql-versions ) }}
89+
90+
exclude:
91+
# The MySQL 5.5 containers will not start.
92+
- db-version: '5.5'
93+
# MySQL 9.0+ will not work on PHP 7.2 & 7.3
94+
- php: '7.2'
95+
db-version: '9.0'
96+
- php: '7.3'
97+
db-version: '9.0'
98+
99+
with:
100+
os: ${{ matrix.os }}
101+
php: ${{ matrix.php }}
102+
db-type: 'mysql'
103+
db-version: ${{ matrix.db-version }}
104+
memcached: ${{ matrix.memcached }}
105+
tests-domain: ${{ matrix.tests-domain }}
106+
107+
slack-notifications:
108+
name: Slack Notifications
109+
uses: WordPress/wordpress-develop/.github/workflows/slack-notifications.yml@trunk
110+
permissions:
111+
actions: read
112+
contents: read
113+
needs: [ build-test-matrix, environment-tests-mysql ]
114+
if: ${{ github.repository == 'WordPress/wordpress-develop' && github.event_name != 'pull_request' && always() }}
115+
with:
116+
calling_status: ${{ contains( needs.*.result, 'cancelled' ) && 'cancelled' || contains( needs.*.result, 'failure' ) && 'failure' || 'success' }}
117+
secrets:
118+
SLACK_GHA_SUCCESS_WEBHOOK: ${{ secrets.SLACK_GHA_SUCCESS_WEBHOOK }}
119+
SLACK_GHA_CANCELLED_WEBHOOK: ${{ secrets.SLACK_GHA_CANCELLED_WEBHOOK }}
120+
SLACK_GHA_FIXED_WEBHOOK: ${{ secrets.SLACK_GHA_FIXED_WEBHOOK }}
121+
SLACK_GHA_FAILURE_WEBHOOK: ${{ secrets.SLACK_GHA_FAILURE_WEBHOOK }}
122+
123+
failed-workflow:
124+
name: Failed workflow tasks
125+
runs-on: ubuntu-latest
126+
permissions:
127+
actions: write
128+
needs: [ build-test-matrix, environment-tests-mysql, slack-notifications ]
129+
if: |
130+
always() &&
131+
github.repository == 'WordPress/wordpress-develop' &&
132+
github.event_name != 'pull_request' &&
133+
github.run_attempt < 2 &&
134+
(
135+
contains( needs.*.result, 'cancelled' ) ||
136+
contains( needs.*.result, 'failure' )
137+
)
138+
139+
steps:
140+
- name: Dispatch workflow run
141+
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
142+
with:
143+
retries: 2
144+
retry-exempt-status-codes: 418
145+
script: |
146+
github.rest.actions.createWorkflowDispatch({
147+
owner: context.repo.owner,
148+
repo: context.repo.repo,
149+
workflow_id: 'failed-workflow.yml',
150+
ref: 'trunk',
151+
inputs: {
152+
run_id: '${{ github.run_id }}'
153+
}
154+
});
Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
##
2+
# A reusable workflow that ensures the local Docker environment is working properly.
3+
#
4+
# This workflow is used by `trunk` and branches >= 6.8.
5+
##
6+
name: Test local Docker environment
7+
8+
on:
9+
workflow_call:
10+
inputs:
11+
os:
12+
description: 'Operating system to test'
13+
required: false
14+
type: 'string'
15+
default: 'ubuntu-latest'
16+
php:
17+
description: 'The version of PHP to use, in the format of X.Y'
18+
required: false
19+
type: 'string'
20+
default: 'latest'
21+
db-type:
22+
description: 'Database type. Valid types are mysql and mariadb'
23+
required: false
24+
type: 'string'
25+
default: 'mysql'
26+
db-version:
27+
description: 'Database version'
28+
required: false
29+
type: 'string'
30+
default: '8.0'
31+
memcached:
32+
description: 'Whether to enable memcached'
33+
required: false
34+
type: 'boolean'
35+
default: false
36+
tests-domain:
37+
description: 'The domain to use for the tests'
38+
required: false
39+
type: 'string'
40+
default: 'example.org'
41+
42+
env:
43+
LOCAL_PHP: ${{ inputs.php == 'latest' && 'latest' || format( '{0}-fpm', inputs.php ) }}
44+
LOCAL_DB_TYPE: ${{ inputs.db-type }}
45+
LOCAL_DB_VERSION: ${{ inputs.db-version }}
46+
LOCAL_PHP_MEMCACHED: ${{ inputs.memcached }}
47+
LOCAL_WP_TESTS_DOMAIN: ${{ inputs.tests-domain }}
48+
PUPPETEER_SKIP_DOWNLOAD: ${{ true }}
49+
50+
jobs:
51+
# Tests the local Docker environment.
52+
#
53+
# Performs the following steps:
54+
# - Sets environment variables.
55+
# - Checks out the repository.
56+
# - Sets up Node.js.
57+
# - Sets up PHP.
58+
# - Installs Composer dependencies.
59+
# - Installs npm dependencies
60+
# - Logs general debug information about the runner.
61+
# - Logs Docker debug information (about the Docker installation within the runner).
62+
# - Starts the WordPress Docker container.
63+
# - Logs the running Docker containers.
64+
# - Logs debug information about what's installed within the WordPress Docker containers.
65+
# - Install WordPress within the Docker container.
66+
# - Restarts the Docker environment.
67+
# - Runs a WP CLI command.
68+
# - Tests the logs command.
69+
# - Tests the reset command.
70+
# - Ensures version-controlled files are not modified or deleted.
71+
local-docker-environment-tests:
72+
name: PHP ${{ inputs.php }} / ${{ 'mariadb' == inputs.db-type && 'MariaDB' || 'MySQL' }} ${{ inputs.db-version }}${{ inputs.memcached && ' with memcached' || '' }}${{ 'example.org' != inputs.tests-domain && format( ' {0}', inputs.tests-domain ) || '' }}
73+
runs-on: ${{ inputs.os }}
74+
timeout-minutes: 20
75+
76+
steps:
77+
- name: Configure environment variables
78+
run: |
79+
echo "PHP_FPM_UID=$(id -u)" >> $GITHUB_ENV
80+
echo "PHP_FPM_GID=$(id -g)" >> $GITHUB_ENV
81+
82+
- name: Checkout repository
83+
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
84+
with:
85+
show-progress: ${{ runner.debug == '1' && 'true' || 'false' }}
86+
87+
- name: Set up Node.js
88+
uses: actions/setup-node@1e60f620b9541d16bece96c5465dc8ee9832be0b # v4.0.3
89+
with:
90+
node-version-file: '.nvmrc'
91+
cache: npm
92+
93+
##
94+
# This allows Composer dependencies to be installed using a single step.
95+
#
96+
# Since tests are currently run within the Docker containers where the PHP version varies,
97+
# the same PHP version needs to be configured for the action runner machine so that the correct
98+
# dependency versions are installed and cached.
99+
##
100+
- name: Set up PHP
101+
uses: shivammathur/setup-php@c541c155eee45413f5b09a52248675b1a2575231 # v2.31.1
102+
with:
103+
php-version: '${{ inputs.php }}'
104+
coverage: none
105+
106+
# Since Composer dependencies are installed using `composer update` and no lock file is in version control,
107+
# passing a custom cache suffix ensures that the cache is flushed at least once per week.
108+
- name: Install Composer dependencies
109+
uses: ramsey/composer-install@57532f8be5bda426838819c5ee9afb8af389d51a # v3.0.0
110+
with:
111+
custom-cache-suffix: $(/bin/date -u --date='last Mon' "+%F")
112+
113+
- name: Install npm dependencies
114+
run: npm ci
115+
116+
- name: General debug information
117+
run: |
118+
npm --version
119+
node --version
120+
curl --version
121+
git --version
122+
composer --version
123+
locale -a
124+
125+
- name: Docker debug information
126+
run: |
127+
docker -v
128+
129+
- name: Start Docker environment
130+
run: |
131+
npm run env:start
132+
133+
- name: Log running Docker containers
134+
run: docker ps -a
135+
136+
- name: WordPress Docker container debug information
137+
run: |
138+
docker compose run --rm mysql ${{ env.LOCAL_DB_TYPE }} --version
139+
docker compose run --rm php php --version
140+
docker compose run --rm php php -m
141+
docker compose run --rm php php -i
142+
docker compose run --rm php locale -a
143+
144+
- name: Install WordPress
145+
run: npm run env:install
146+
147+
- name: Restart Docker environment
148+
run: npm run env:restart
149+
150+
- name: Test a CLI command
151+
run: npm run env:cli wp option get siteurl
152+
153+
- name: Test logs command
154+
run: npm run env:logs
155+
156+
- name: Reset the Docker environment
157+
run: npm run env:reset
158+
159+
- name: Ensure version-controlled files are not modified or deleted
160+
run: git diff --exit-code

0 commit comments

Comments
 (0)