Skip to content

Commit fa65451

Browse files
committed
Add default GitHub Actions testing config
1 parent 9e1022e commit fa65451

File tree

1 file changed

+146
-0
lines changed

1 file changed

+146
-0
lines changed

.github/workflows/testing.yml

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
name: Testing
2+
3+
on: pull_request
4+
5+
jobs:
6+
7+
unit: #-----------------------------------------------------------------------
8+
name: Unit test / PHP ${{ matrix.php }}
9+
strategy:
10+
fail-fast: false
11+
matrix:
12+
php: ['5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0']
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- name: Check out source code
17+
uses: actions/checkout@v2
18+
19+
- name: Check existence of composer.json file
20+
id: check_files
21+
uses: andstor/file-existence-action@v1
22+
with:
23+
files: "composer.json, phpunit.xml.dist"
24+
25+
- name: Set up PHP environment
26+
if: steps.check_files.outputs.files_exists == 'true'
27+
uses: shivammathur/setup-php@v2
28+
with:
29+
php-version: '${{ matrix.php }}'
30+
coverage: none
31+
tools: composer,cs2pr
32+
33+
- name: Get Composer cache Directory
34+
if: steps.check_files.outputs.files_exists == 'true'
35+
id: composer-cache
36+
run: |
37+
echo "::set-output name=dir::$(composer config cache-files-dir)"
38+
39+
- name: Use Composer cache
40+
if: steps.check_files.outputs.files_exists == 'true'
41+
uses: actions/cache@master
42+
with:
43+
path: ${{ steps['composer-cache'].outputs.dir }}
44+
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
45+
restore-keys: |
46+
${{ runner.os }}-composer-
47+
48+
- name: Install dependencies
49+
if: steps.check_files.outputs.files_exists == 'true'
50+
run: COMPOSER_ROOT_VERSION=dev-master composer install --prefer-dist --no-progress --no-suggest
51+
52+
- name: Setup problem matcher to provide annotations for PHPUnit
53+
if: steps.check_files.outputs.files_exists == 'true'
54+
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
55+
56+
- name: Run PHPUnit
57+
if: steps.check_files.outputs.files_exists == 'true'
58+
run: composer phpunit
59+
60+
functional: #----------------------------------------------------------------------
61+
name: Functional - WP ${{ matrix.wp }} on PHP ${{ matrix.php }}
62+
strategy:
63+
fail-fast: false
64+
matrix:
65+
php: ['5.6', '7.0', '7.1', '7.2', '7.3', '7.4']
66+
wp: ['latest']
67+
test: ["composer behat || composer behat-rerun"]
68+
include:
69+
- php: '5.6'
70+
wp: 'trunk'
71+
test: "composer behat || composer behat-rerun"
72+
- php: '7.4'
73+
wp: 'trunk'
74+
test: "composer behat || composer behat-rerun"
75+
- php: '5.6'
76+
wp: '3.7'
77+
test: "composer behat || composer behat-rerun || true"
78+
runs-on: ubuntu-latest
79+
80+
services:
81+
mysql:
82+
image: mysql:5.7
83+
env:
84+
MYSQL_DATABASE: wp_cli_test
85+
MYSQL_USER: root
86+
MYSQL_ROOT_PASSWORD: root
87+
ports:
88+
- 3306
89+
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
90+
91+
steps:
92+
- name: Check out source code
93+
uses: actions/checkout@v2
94+
95+
- name: Check existence of composer.json & behat.yml files
96+
id: check_files
97+
uses: andstor/file-existence-action@v1
98+
with:
99+
files: "composer.json, behat.yml"
100+
101+
- name: Set up PHP envirnoment
102+
uses: shivammathur/setup-php@v2
103+
with:
104+
php-version: '${{ matrix.php }}'
105+
extensions: mysql, zip
106+
coverage: none
107+
tools: composer
108+
109+
- name: Get Composer cache Directory
110+
if: steps.check_files.outputs.files_exists == 'true'
111+
id: composer-cache
112+
run: |
113+
echo "::set-output name=dir::$(composer config cache-files-dir)"
114+
115+
- name: Use Composer cache
116+
if: steps.check_files.outputs.files_exists == 'true'
117+
uses: actions/cache@master
118+
with:
119+
path: ${{ steps['composer-cache'].outputs.dir }}
120+
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
121+
restore-keys: |
122+
${{ runner.os }}-composer-
123+
124+
- name: Install dependencies
125+
if: steps.check_files.outputs.files_exists == 'true'
126+
run: COMPOSER_ROOT_VERSION=dev-master composer install --prefer-dist --no-progress --no-suggest
127+
128+
- name: Start MySQL server
129+
if: steps.check_files.outputs.files_exists == 'true'
130+
run: sudo service mysql start
131+
132+
- name: Prepare test database
133+
if: steps.check_files.outputs.files_exists == 'true'
134+
run: |
135+
export MYQSL_HOST=127.0.0.1
136+
export MYSQL_TCP_PORT=${{ job.services.mysql.ports['3306'] }}
137+
mysql -e 'CREATE DATABASE IF NOT EXISTS wp_cli_test;' -uroot -proot
138+
mysql -e 'GRANT ALL PRIVILEGES ON wp_cli_test.* TO "wp_cli_test"@"127.0.0.1" IDENTIFIED BY "password1"' -uroot -proot
139+
mysql -e 'GRANT ALL PRIVILEGES ON wp_cli_test_scaffold.* TO "wp_cli_test"@"127.0.0.1" IDENTIFIED BY "password1"' -uroot -proot
140+
141+
- name: Run Behat
142+
if: steps.check_files.outputs.files_exists == 'true'
143+
env:
144+
WP_VERSION: '${{ matrix.wp }}'
145+
run: ${{ matrix.test }}
146+

0 commit comments

Comments
 (0)