Repository navigation
104 lines (94 loc) · 4.01 KB
/
Copy pathci-test-php.yml
File metadata and controls
104 lines (94 loc) · 4.01 KB
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
name: CI / Test PHP
on:
workflow_call:
inputs:
runs-on:
description: "Runner for every job, as JSON: a label such as \"ubuntu-latest\" or a label list such as [\"self-hosted\"]. rtCamp private repos pass [\"self-hosted\"]."
type: string
default: '"ubuntu-latest"'
php-version:
description: "PHP version. Installed on the host (used directly in standalone mode) and passed to wp-env as WP_ENV_PHP_VERSION so the container runs the same version."
type: string
default: "8.3"
node-version:
description: "Node.js version (used only when use-wp-env is true)."
type: string
default: "22"
wp-version:
description: >-
WordPress core version for wp-env, e.g. '6.8' (resolved as WordPress/WordPress#<version>).
Empty uses the version from the consumer's .wp-env.json. Ignored when use-wp-env is false.
type: string
default: ""
use-wp-env:
description: "Start @wordpress/env before tests for WordPress integration runs."
type: boolean
default: true
test-command:
description: "Shell command that runs PHPUnit. When empty, defaults to 'npm run test:php' if use-wp-env is true, otherwise 'vendor/bin/phpunit'."
type: string
default: ""
composer-flags:
description: "Flags passed to composer install."
type: string
default: "--no-interaction --prefer-dist --no-progress --no-scripts"
working-dir:
description: "Working directory for monorepos."
type: string
default: "."
permissions:
contents: read
jobs:
test-php:
name: PHPUnit
runs-on: ${{ fromJSON(inputs.runs-on) }}
# Pin the wp-env container's PHP/WordPress core via env: (not $GITHUB_ENV, which is
# newline-injectable) at job scope, so start/run/stop resolve the same environment.
# An empty WP_ENV_CORE is ignored by wp-env (falls back to the consumer's .wp-env.json).
env:
WP_ENV_PHP_VERSION: ${{ inputs.use-wp-env && inputs.php-version || '' }}
WP_ENV_CORE: ${{ (inputs.use-wp-env && inputs.wp-version != '') && format('WordPress/WordPress#{0}', inputs.wp-version) || '' }}
defaults:
run:
working-directory: ${{ inputs.working-dir }}
steps:
- name: Checkout repository
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Set up PHP
uses: shivammathur/setup-php@accd6127cb78bee3e8082180cb391013d204ef9f # 2.37.0
with:
php-version: ${{ inputs.php-version }}
coverage: none
tools: composer
# Raises the GitHub API rate limit when composer install resolves a VCS repo.
github-token: ${{ github.token }}
- name: Set up Node.js
if: ${{ inputs.use-wp-env }}
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
with:
node-version: ${{ inputs.node-version }}
cache: npm
# setup-node is a JS action: without this it looks for the lockfile at the repo root.
cache-dependency-path: ${{ inputs.working-dir != '.' && format('{0}/package-lock.json', inputs.working-dir) || '' }}
- name: Install Composer dependencies
shell: bash
env:
COMPOSER_FLAGS: ${{ inputs.composer-flags }}
run: |
set -euo pipefail
read -r -a composer_args <<< "$COMPOSER_FLAGS" || true
composer install "${composer_args[@]}"
- name: Install npm dependencies
if: ${{ inputs.use-wp-env }}
run: npm ci
- name: Start wp-env
if: ${{ inputs.use-wp-env }}
run: npm run wp-env start
- name: Run PHPUnit
shell: bash
env:
TEST_COMMAND: ${{ inputs.test-command != '' && inputs.test-command || (inputs.use-wp-env && 'npm run test:php' || 'vendor/bin/phpunit') }}
run: bash -eo pipefail -c "$TEST_COMMAND"
- name: Stop wp-env
if: ${{ inputs.use-wp-env && always() }}
run: npm run wp-env stop