-
Notifications
You must be signed in to change notification settings - Fork 0
153 lines (147 loc) · 4.78 KB
/
test.yml
File metadata and controls
153 lines (147 loc) · 4.78 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
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
name: Test
on:
pull_request:
branches: [develop, trunk]
jobs:
changed:
outputs:
plugin: ${{ steps.plugin.outputs.any_changed }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: tj-actions/changed-files@v41
id: plugin
with:
files: |
which-blocks.php
src/**/*.php
tests/**/*
package.json
package-lock.json
composer.json
composer.lock
.wp-env.json
.github/workflows/test.yml
cache:
name: Cache the Node
needs: changed
if: ${{ needs.changed.outputs.plugin == 'true' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'
- name: Get npm cache directory
id: npm-cache-dir
shell: bash
run: echo "node-cache-dir=$(npm config get cache)" >> ${GITHUB_OUTPUT}
- uses: actions/cache@v3
id: npm-cache
with:
path: |
./node_modules
/home/runner/.cache/Cypress
${{ steps.npm-cache-dir.outputs.node-cache-dir }}
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Install dependencies
run: npm ci
phpcs:
name: Lint PHP
needs: changed
if: ${{ needs.changed.outputs.plugin == 'true' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
coverage: none
tools: composer:v2
- name: Install dependencies
run: composer install
- name: Lint PHP
run: composer run lint .
phpunit:
name: PHP Unit
needs: phpcs
if: ${{ needs.changed.outputs.plugin == 'true' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
coverage: none
tools: composer:v2
- name: Install dependencies
run: composer install
- name: Lint PHP
run: composer run unit
cypress:
name: E2E ${{ matrix.core.name }}
needs: [changed, phpcs, phpunit, cache]
if: ${{ needs.changed.outputs.plugin == 'true' }}
runs-on: ubuntu-latest
strategy:
matrix:
core:
- {name: 'WP 6.9', version: 'WordPress/WordPress#6.9'}
- {name: 'WP 6.0', version: 'WordPress/WordPress#6.0'}
- {name: 'WP trunk', version: 'WordPress/WordPress#master'}
steps:
- name: Checkout
uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'
- name: Get npm cache directory
id: npm-cache-dir
shell: bash
run: echo "node-cache-dir=$(npm config get cache)" >> ${GITHUB_OUTPUT}
- uses: actions/cache@v3
id: npm-cache
with:
path: |
./node_modules
/home/runner/.cache/Cypress
${{ steps.npm-cache-dir.outputs.node-cache-dir }}
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Setup docker-compose for wp-env
run: |
echo '#!/bin/bash' | sudo tee /usr/local/bin/docker-compose
echo 'exec docker compose "$@"' | sudo tee -a /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
docker-compose --version
- name: Build (optional)
run: npm run build
- name: Set the core version
run: ./tests/bin/set-core-version.js ${{ matrix.core.version }}
- name: Set up WP environment
run: npm run env:start
- name: Test
run: npm run cypress:run
- name: Update summary
if: always()
run: |
npx mochawesome-merge ./tests/cypress/reports/*.json -o tests/cypress/reports/mochawesome.json
rm -rf ./tests/cypress/reports/mochawesome-*.json
npx mochawesome-report-generator tests/cypress/reports/mochawesome.json -o tests/cypress/reports/
# Skip the markdown conversion if it fails, just generate HTML report
npx mochawesome-json-to-md -p ./tests/cypress/reports/mochawesome.json -o ./tests/cypress/reports/mochawesome.md 2>/dev/null || echo "# Test Results\nSee HTML report in artifacts" >> ./tests/cypress/reports/mochawesome.md
cat ./tests/cypress/reports/mochawesome.md >> $GITHUB_STEP_SUMMARY
- name: Make artifacts available
uses: actions/upload-artifact@v4
if: failure()
with:
name: cypress-artifact
retention-days: 2
path: |
${{ github.workspace }}/tests/cypress/screenshots/
${{ github.workspace }}/tests/cypress/videos/
${{ github.workspace }}/tests/cypress/logs/
${{ github.workspace }}/tests/cypress/reports/