-
Notifications
You must be signed in to change notification settings - Fork 3
168 lines (164 loc) · 6.53 KB
/
ci.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
name: CI
on:
push:
branches:
- main
pull_request:
types: [opened, synchronize, reopened]
env:
MAIN_PHP_VERSION: '8.3'
jobs:
unit-tests:
name: Unit tests (PHP ${{ matrix.php-versions }})
runs-on: ubuntu-22.04
continue-on-error: ${{ matrix.experimental }}
strategy:
fail-fast: false
matrix:
php-versions: ['7.4', '8.0', '8.1', '8.2', '8.3']
experimental: [false]
include:
- php-versions: '8.4'
experimental: true
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
# Disabling shallow clone is recommended for improving relevancy of reporting
fetch-depth: 0
- name: Setup PHP, with Composer and extensions
uses: shivammathur/setup-php@v2 #https://github.com/shivammathur/setup-php
with:
php-version: ${{ matrix.php-versions }}
coverage: none
extensions: gd
- name: Setup problem matchers for PHPUnit
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
- name: Remove unused Composer dependencies
run: composer remove humbug/php-scoper sirbrillig/phpcs-import-detection phpstan/phpstan szepeviktor/phpstan-wordpress --dev --no-interaction --no-update
- name: Remove PHP 8.4 workaround dependency
if: ${{ matrix.php-versions < '8.2' }}
run: composer remove shish/safe --dev --no-interaction --no-update
- name: Get composer cache directory
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
- name: Cache dependencies
uses: actions/cache@v3
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-
- name: Install dependencies
run: composer install --prefer-dist
- name: Run PHPUnit tests
run: composer test
coverage:
name: Coverage & SonarCloud
runs-on: ubuntu-22.04
strategy:
fail-fast: true
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
# Disabling shallow clone is recommended for improving relevancy of reporting
fetch-depth: 0
- name: Setup PHP, with Composer and extensions
uses: shivammathur/setup-php@v2 #https://github.com/shivammathur/setup-php
with:
php-version: ${{ env.MAIN_PHP_VERSION }}
coverage: xdebug
extensions: gd
- name: Remove unused Composer dependencies
run: composer remove humbug/php-scoper sirbrillig/phpcs-import-detection szepeviktor/phpstan-wordpress --dev --no-interaction --no-update
- name: Get composer cache directory
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
- name: Cache dependencies
uses: actions/cache@v3
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-
- name: Install dependencies
run: composer install --prefer-dist
- name: Run PHPUnit tests with coverage generation
run: |
mkdir -p build/logs
composer test -- --coverage-clover build/logs/phpunit.coverage.xml --log-junit=build/logs/phpunit.test-report.xml
- name: Fix code coverage paths for SonarCloud
working-directory: ./build/logs/
run: |
sed -i 's@'$GITHUB_WORKSPACE'@/github/workspace/@g' phpunit.coverage.xml
sed -i 's@'$GITHUB_WORKSPACE'@/github/workspace/@g' phpunit.test-report.xml
- name: Extract version number
run: |
echo "AVATAR_PRIVACY_VERSION=$(sed -n 's/^.*Version: \(.*\)$/\1/p' avatar-privacy.php)" >> $GITHUB_ENV
- name: SonarCloud Scan
uses: SonarSource/sonarqube-scan-action@master
with:
args: >
-Dsonar.projectVersion=${{ env.AVATAR_PRIVACY_VERSION }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
if: env.SONAR_TOKEN != ''
phpcs:
name: Check Coding Standards
runs-on: ubuntu-22.04
strategy:
fail-fast: true
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Setup PHP, with Composer and extensions
uses: shivammathur/setup-php@v2 #https://github.com/shivammathur/setup-php
with:
php-version: ${{ env.MAIN_PHP_VERSION }}
coverage: none
extensions: gd
tools: cs2pr
- name: Remove unused Composer dependencies
run: composer remove humbug/php-scoper --dev --no-interaction --no-update
- name: Get composer cache directory
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
- name: Cache dependencies
uses: actions/cache@v3
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-
- name: Install dependencies
run: composer install --prefer-dist
- name: Run PHPCS checks
run: vendor/bin/phpcs -q *.php includes/ admin/ public/ --extensions=php --report=checkstyle | cs2pr
phpstan:
name: Static Analysis
runs-on: ubuntu-22.04
strategy:
fail-fast: true
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Setup PHP, with Composer and extensions
uses: shivammathur/setup-php@v2 #https://github.com/shivammathur/setup-php
with:
php-version: ${{ env.MAIN_PHP_VERSION }}
coverage: none
extensions: gd
- name: Remove unused Composer dependencies
run: composer remove humbug/php-scoper sirbrillig/phpcs-import-detection --dev --no-interaction --no-update
- name: Get composer cache directory
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
- name: Cache dependencies
uses: actions/cache@v3
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-
- name: Install dependencies
run: composer install --prefer-dist
- name: Run PHPStan
run: composer run-script phpstan