-
Notifications
You must be signed in to change notification settings - Fork 70
142 lines (121 loc) · 4.6 KB
/
php-unit-tests.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
name: PHP Unit Tests
on:
push:
branches:
- trunk
paths:
- "**.php"
- composer.json
- composer.lock
- .github/workflows/php-unit-tests.yml
pull_request:
paths:
- "**.php"
- composer.json
- composer.lock
- .github/workflows/php-unit-tests.yml
workflow_dispatch:
inputs:
php-version:
description: 'PHP Version'
default: '8.2'
wp-rc-version:
description: 'WordPress version for Release Candidate (ex. 6.5-RC3)'
default: 'latest'
wc-rc-version:
description: 'WooCommerce version for Release Candidate (ex. 8.7.0-rc.1)'
default: 'latest'
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
GetMatrix:
if: github.event_name != 'workflow_dispatch'
name: Get WP and WC version Matrix
runs-on: ubuntu-latest
outputs:
wp-versions: ${{ steps.wp.outputs.versions }}
wc-versions: ${{ steps.wc.outputs.versions }}
steps:
- name: Get Release versions from Wordpress
id: wp
uses: woocommerce/grow/get-plugin-releases@actions-v2
with:
slug: wordpress
- name: Get Release versions from WooCommerce
id: wc
uses: woocommerce/grow/get-plugin-releases@actions-v2
with:
slug: woocommerce
UnitTests:
if: github.event_name != 'workflow_dispatch'
name: PHP unit tests - PHP ${{ matrix.php }}, WP ${{ matrix.wp-version || 'latest' }}, WC ${{ matrix.wc-versions || 'latest' }}
runs-on: ubuntu-latest
needs: GetMatrix
strategy:
matrix:
php: [8.2]
wp-version: [latest]
# Please note that wc-versions is a string containing versions separated by commas.
# It will be split and loop within the run unit test step below to reduce the time spent.
wc-versions: [ '${{ join(fromJson(needs.GetMatrix.outputs.wc-versions)) }}' ]
include:
- php: 7.4
wp-version: ${{ fromJson(needs.GetMatrix.outputs.wp-versions)[2] }} # L-2 WP Version support
wc-versions: ${{ fromJson(needs.GetMatrix.outputs.wc-versions)[2] }} # L-2 WC Version support
- php: 8.3
wp-version: latest
wc-versions: latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Prepare PHP
uses: woocommerce/grow/prepare-php@actions-v2
with:
php-version: "${{ matrix.php }}"
- name: Set up MySQL
uses: woocommerce/grow/prepare-mysql@actions-v2
- name: Install svn (used for installing WP versions)
run: sudo apt-get -y install subversion
- name: Run PHP unit tests
run: |
WC_VERSIONS=$(echo "${{ matrix.wc-versions }}" | sed -r "s/ *, */ /g")
WC_VERSIONS=($WC_VERSIONS)
URL_CONFIG="url.https://${{ secrets.BOT_GH_TOKEN }}:[email protected]/.insteadOf [email protected]:"
git config --global $URL_CONFIG
INIT_INSTALL=true
for WC_VERSION in "${WC_VERSIONS[@]}"; do
if [ "$INIT_INSTALL" = true ]; then
echo "::group::Install WP ${{ matrix.wp-version }} and WC ${WC_VERSION}"
./bin/install-unit-tests.sh wordpress_test root root localhost ${{ matrix.wp-version }} $WC_VERSION
INIT_INSTALL=false
else
echo "::group::Switch to WP ${{ matrix.wp-version }} and WC ${WC_VERSION}"
./bin/switch-wp-wc-in-unit-tests.sh wordpress_test root root localhost ${{ matrix.wp-version }} $WC_VERSION
fi
echo "::endgroup::"
vendor/bin/phpunit
done
git config --global --unset $URL_CONFIG
ReleaseCandidateUnitTests:
if: github.event_name == 'workflow_dispatch'
name: PHP unit tests (for Release Candidates)
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Prepare PHP
uses: woocommerce/grow/prepare-php@actions-v2
with:
php-version: "${{ inputs.php-version }}"
- name: Prepare MySQL
uses: woocommerce/grow/prepare-mysql@actions-v2
- name: Install svn (used for installing WP versions)
run: sudo apt-get -y install subversion
- name: Install WP tests
env:
INPUT_WP_RC_VERSION: ${{ inputs.wp-rc-version }}
INPUT_WC_RC_VERSION: ${{ inputs.wc-rc-version }}
run: ./bin/install-unit-tests.sh wordpress_test root root localhost "${INPUT_WP_RC_VERSION}" "${INPUT_WC_RC_VERSION}"
- name: Run PHP unit tests
run: vendor/bin/phpunit