-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaction.yml
287 lines (242 loc) · 10.3 KB
/
action.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
name: 'Set up common workflow requirements'
description: 'Prepare environment for testing a WordPress plugin or theme'
inputs:
bitbucket_read_only_ssh_key:
description: 'Read-only SSH key to access repositories on Bitbucket'
required: true
git_checkout_fetch_depth:
description: 'Fetch depth for git checkout'
required: false
default: '1'
github_read_only_ssh_key:
description: 'Read-only SSH keyto access repositories on GitHub'
required: true
nodejs:
description: 'Prepare environment for Node.js'
required: false
default: '0'
php_version:
description: 'PHP version to use'
required: false
default: '8.0'
phpcs:
description: 'Prepare environment for PHPCS'
required: false
default: '0'
phpunit:
description: 'Prepare environment for PHPUnit'
required: false
default: '0'
vip_theme:
description: 'If the theme uses the "vip" subdirectory'
required: true
wordpress_version:
description: ''
required: false
default: '0'
runs:
using: "composite"
steps:
# Shared steps
- name: Check out repository
uses: actions/checkout@v4
with:
fetch-depth: ${{ inputs.git_checkout_fetch_depth }}
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.ref || '' }}
- name: Prepare SSH keys
run: |
echo 'BITBUCKET_READ_ONLY_SSH_KEY<<EOF' >> $GITHUB_ENV
echo "${{ inputs.bitbucket_read_only_ssh_key }}" >> $GITHUB_ENV
echo 'EOF' >> $GITHUB_ENV
echo 'GITHUB_READ_ONLY_SSH_KEY<<EOF' >> $GITHUB_ENV
echo "${{ inputs.github_read_only_ssh_key }}" >> $GITHUB_ENV
echo 'EOF' >> $GITHUB_ENV
shell: bash
- name: Set up SSH
run: ${{ github.action_path }}/scripts/set-up-ssh.sh
shell: bash
- name: Add shared utilities
run: |
${{ github.action_path }}/scripts/add-shared-utilities.sh
echo "${{ github.action_path }}/bin" >> $GITHUB_PATH
shell: bash
- name: Set environment variables
run: |
# For back-compat reasons, this references Bitbucket. Once all repos are moved, we can update references to this.
# Additionally, for "pull request" events, the `$GITHUB_REF_NAME` variable does not match the branch name.
FULL_PATH_REF="${{ github.event.pull_request.head.ref || github.ref }}"
REF=${FULL_PATH_REF#refs\/heads\/}
echo "BITBUCKET_BRANCH=${REF}" >> $GITHUB_ENV
# Set certain static environment variables.
echo "PMC_COMMIT_DIFF_FILE=${RUNNER_TEMP}/diff.txt" >> $GITHUB_ENV
echo "PMC_DIFF_ONLY=true" >> $GITHUB_ENV
echo "PMC_SKIP_INIT_BUILD=true" >> $GITHUB_ENV
# Parse repository slug for use in various commands.
. pmc-setup-git-repo-slug
echo "REPO_SLUG=${REPO_SLUG}" >> $GITHUB_ENV
# Determine if we're testing `pmc-plugins`, as it has special requirements.
PMC_IS_PMC_PLUGINS=''
if [[ "pmc-plugins" == "${REPO_SLUG}" ]]; then
PMC_IS_PMC_PLUGINS=true
fi
echo "PMC_IS_PMC_PLUGINS=${PMC_IS_PMC_PLUGINS}" >> $GITHUB_ENV
# Set VIP_THEME variable
echo "VIP_THEME=${{ inputs.vip_theme }}" >> $GITHUB_ENV
shell: bash
- name: Set environment variables to install WordPress
if: ${{ inputs.wordpress_version != '0' }}
run: bash ${{ github.action_path }}/scripts/set-wordpress-envars.sh
shell: bash
- name: Set WordPress version cache key and cache path
id: set-wp-install-cache-info
if: ${{ inputs.wordpress_version != '0' }}
run: |
echo "path=${TMPDIR}/wp" >> $GITHUB_OUTPUT
if [[ "${{ matrix.wordpress }}" == 'latest' ]]; then
echo "version=$(curl --no-progress-meter https://api.wordpress.org/core/version-check/1.7/ | jq -r '.offers[0].version')" >> $GITHUB_OUTPUT
else
echo "version=$(/bin/date -u '+%F')" >> $GITHUB_OUTPUT
fi
shell: bash
- name: Cache WordPress install
id: cache-wordpress-install
if: ${{ inputs.wordpress_version != '0' }}
uses: actions/cache@v4
with:
path: ${{ steps.set-wp-install-cache-info.outputs.path }}
key: ${{ runner.os }}-version-${{ steps.set-wp-install-cache-info.outputs.version }}-php-${{ matrix.php }}-wp-${{ matrix.wordpress }}-wordpress-install
- name: Start MySQL
id: start-mysql
if: ${{ inputs.wordpress_version != '0' }}
run: |
MYSQL_USER=root
MYSQL_PASSWORD=root
MYSQL_HOST=127.0.0.1
MYSQL_DATABASE=wordpress
sudo systemctl start mysql.service
echo "user=${MYSQL_USER}" >> $GITHUB_OUTPUT
echo "password=${MYSQL_PASSWORD}" >> $GITHUB_OUTPUT
echo "host=${MYSQL_HOST}" >> $GITHUB_OUTPUT
echo "database=${MYSQL_DATABASE}" >> $GITHUB_OUTPUT
# If WP wasn't installed, ensure database exists.
if [[ "${{ steps.cache-wordpress-install.outputs.cache-hit }}" == true ]]; then
mysql --user=${MYSQL_USER} --password=${MYSQL_PASSWORD} --host=${MYSQL_HOST} --protocol=tcp "--execute=CREATE DATABASE IF NOT EXISTS ${MYSQL_DATABASE};"
fi
shell: bash
- name: Install WordPress
if: ${{ inputs.wordpress_version != '0' && steps.cache-wordpress-install.outputs.cache-hit != 'true' }}
run: |
sudo apt-get update && sudo apt-get install -y subversion && sudo apt-get clean && sudo rm -rf /var/lib/apt/lists/*
SCRIPT_PATH="/usr/local/bin/install-wp-tests"
curl --no-progress-meter -o "${SCRIPT_PATH}" https://raw.githubusercontent.com/wp-cli/scaffold-command/master/templates/install-wp-tests.sh
chmod +x "${SCRIPT_PATH}"
"${SCRIPT_PATH}" ${{ steps.start-mysql.outputs.database }} ${{ steps.start-mysql.outputs.user }} ${{ steps.start-mysql.outputs.password }} ${{ steps.start-mysql.outputs.host }} ${{ matrix.wordpress }}
shell: bash
- name: Create plugin loader
if: ${{ inputs.wordpress_version != '0' }}
run: cp "${{ github.action_path }}/templates/plugin-loader.php" "${RUNNER_TEMP}"
shell: bash
- name: Install WordPress dependencies
if: ${{ inputs.wordpress_version != '0' }}
run: ${{ github.action_path }}/scripts/set-up-wordpress-dependencies.sh
shell: bash
# Prepare for PHPCS or PHPUnit
- name: Determine PHP coverage mode
id: php-coverage-mode
if: ${{ inputs.phpcs == '1' || inputs.phpunit == '1' }}
run: |
if [[ '${{ inputs.phpunit }}' == '1' ]]; then
echo "mode=xdebug" >> $GITHUB_OUTPUT
else
echo "mode=none" >> $GITHUB_OUTPUT
fi
shell: bash
- name: Set up PHP
uses: shivammathur/setup-php@v2
if: ${{ inputs.phpcs == '1' || inputs.phpunit == '1' }}
with:
php-version: ${{ inputs.php_version }}
coverage: ${{ steps.php-coverage-mode.outputs.mode }}
tools: composer:1
- name: Log debug information
if: ${{ inputs.phpcs == '1' || inputs.phpunit == '1' }}
run: php --version
shell: bash
# This date is used to ensure that caches are cleared weekly.
# http://man7.org/linux/man-pages/man1/date.1.html
- name: Get last Monday's date
id: get-date
if: ${{ inputs.phpcs == 1 || inputs.phpunit == 1 || inputs.nodejs == 1 }}
run: echo "date=$(/bin/date -u --date='last Sun' '+%F')" >> $GITHUB_OUTPUT
shell: bash
- name: Get composer global path
id: composer-global-path
if: ${{ inputs.phpcs == '1' || inputs.phpunit == '1' }}
run: echo "path=$(composer --global config home)" >> $GITHUB_OUTPUT
shell: bash
- name: Ensure composer global bin is in path
id: composer-global-bin-path
if: ${{ inputs.phpcs == '1' || inputs.phpunit == '1' }}
run: echo "$(composer --global config home)/$(composer --global config bin-dir)" >> $GITHUB_PATH
shell: bash
- name: Cache global composer dependencies
id: composer-cache-global
if: ${{ inputs.phpcs == '1' || inputs.phpunit == '1' }}
uses: actions/cache@v4
with:
path: ${{ steps.composer-global-path.outputs.path }}
key: ${{ runner.os }}-date-${{ steps.get-date.outputs.date }}-php-${{ inputs.php_version }}-phpcs-${{ inputs.phpcs }}-phpunit-${{ inputs.phpunit }}-composer-global
- name: Install diffFilter
if: ${{ ( inputs.phpcs == '1' || inputs.phpunit == '1' ) && steps.composer-cache-global.outputs.cache-hit != 'true' }}
run: composer global require exussum12/coverage-checker
shell: bash
# Prepare for PHPUnit
- name: Install PHPUnit
if: ${{ inputs.phpunit == '1' && steps.composer-cache-global.outputs.cache-hit != 'true' }}
run: |
if [[ $(php -v) =~ "PHP 8." ]]; then
composer global require "phpunit/phpunit=9.*"
elif [[ $(php -v) =~ "PHP 7." ]]; then
composer global require "phpunit/phpunit=7.*"
fi
composer global require yoast/phpunit-polyfills
shell: bash
- name: Log PHPUnit debug information
if: ${{ inputs.phpunit == '1' }}
run: phpunit --version
shell: bash
- name: Set unit-test constants
if: ${{ inputs.phpunit == '1' }}
run: |
WP_CONFIG_PATH="${WP_TESTS_DIR}/wp-tests-config.php"
echo "define( 'IS_UNIT_TEST', true );" >> "${WP_CONFIG_PATH}"
echo "define( 'WPCOM_VIP_JETPACK_LOCAL', true );" >> "${WP_CONFIG_PATH}"
sed -i 's/example\.org/pmcdev\.local/g' "${WP_CONFIG_PATH}"
shell: bash
# Prepare for PHPCS
- name: Install PHPCS and PMC standards
if: ${{ inputs.phpcs == '1' }}
run: |
git clone --depth 1 [email protected]:penske-media-corp/pmc-codesniffer.git "${RUNNER_TEMP}/phpcs"
composer --working-dir="${RUNNER_TEMP}/phpcs" install
echo "${RUNNER_TEMP}/phpcs/vendor/bin" >> $GITHUB_PATH
shell: bash
- name: Log PHPCS debug information
if: ${{ inputs.phpcs == '1' }}
run: |
phpcs -i
phpcs --config-show
shell: bash
# Prepare for Node.js
- name: Set nvm-versions cache path
id: set-nvm-cache-info
if: ${{ inputs.nodejs == 1 }}
run: echo "path=${NVM_DIR}/versions" >> $GITHUB_OUTPUT
shell: bash
- name: Cache nvm versions
id: cache-nvm-versions
if: ${{ inputs.nodejs == 1 }}
uses: actions/cache@v4
with:
path: ${{ steps.set-nvm-cache-info.outputs.path }}
key: ${{ runner.os }}-nvm-versions-${{ steps.get-date.outputs.date }}