Skip to content

Commit 42734c9

Browse files
JeroenDeDauwclaude
andcommitted
Add GitHub Actions CI
Add CI workflow with PHPUnit tests (MW 1.43 + 1.44), PHPStan static analysis, and PHPCS code style checks. Uses the same approach as the Rules extension. Also adds Makefile, phpcs.xml, phpstan.neon configuration, and updates composer.json with dev dependencies and PHP >=8.1 requirement. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 5263336 commit 42734c9

7 files changed

Lines changed: 328 additions & 7 deletions

File tree

.github/workflows/ci.yml

Lines changed: 204 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,204 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
pull_request:
6+
7+
jobs:
8+
test:
9+
name: "PHPUnit: MW ${{ matrix.mw }}, PHP ${{ matrix.php }}"
10+
continue-on-error: ${{ matrix.experimental }}
11+
12+
strategy:
13+
matrix:
14+
include:
15+
- mw: 'REL1_43'
16+
php: '8.1'
17+
experimental: false
18+
coverage: false
19+
- mw: 'REL1_43'
20+
php: '8.2'
21+
experimental: false
22+
coverage: true
23+
- mw: 'REL1_44'
24+
php: '8.3'
25+
experimental: false
26+
coverage: false
27+
28+
runs-on: ubuntu-latest
29+
30+
defaults:
31+
run:
32+
working-directory: mediawiki
33+
34+
steps:
35+
- name: Setup PHP
36+
uses: shivammathur/setup-php@v2
37+
with:
38+
php-version: ${{ matrix.php }}
39+
extensions: mbstring, intl
40+
tools: composer
41+
42+
- name: Cache MediaWiki
43+
id: cache-mediawiki
44+
uses: actions/cache@v4
45+
with:
46+
path: |
47+
mediawiki
48+
!mediawiki/extensions/
49+
!mediawiki/vendor/
50+
key: mw_${{ matrix.mw }}-php${{ matrix.php }}_v2
51+
52+
- name: Cache Composer cache
53+
uses: actions/cache@v4
54+
with:
55+
path: ~/.composer/cache
56+
key: composer-php${{ matrix.php }}
57+
58+
- uses: actions/checkout@v4
59+
with:
60+
path: EarlyCopy
61+
62+
- name: Install MediaWiki
63+
if: steps.cache-mediawiki.outputs.cache-hit != 'true'
64+
working-directory: ~
65+
run: bash EarlyCopy/.github/workflows/installMediaWiki.sh ${{ matrix.mw }} SubPageList
66+
67+
- uses: actions/checkout@v4
68+
with:
69+
path: mediawiki/extensions/SubPageList
70+
71+
- run: composer update
72+
73+
- name: Run update.php
74+
run: php maintenance/update.php --quick
75+
76+
- name: Run PHPUnit
77+
run: php tests/phpunit/phpunit.php -c extensions/SubPageList/
78+
if: ${{ ! matrix.coverage }}
79+
80+
- name: Run PHPUnit with code coverage
81+
run: php tests/phpunit/phpunit.php -c extensions/SubPageList/ --coverage-clover coverage.xml
82+
if: ${{ matrix.coverage }}
83+
84+
- name: Upload code coverage
85+
uses: codecov/codecov-action@v5
86+
with:
87+
token: ${{ secrets.CODECOV_GLOBAL_TOKEN }}
88+
if: ${{ matrix.coverage }}
89+
90+
PHPStan:
91+
name: "PHPStan: MW ${{ matrix.mw }}, PHP ${{ matrix.php }}"
92+
93+
strategy:
94+
matrix:
95+
include:
96+
- mw: 'REL1_43'
97+
php: '8.3'
98+
99+
runs-on: ubuntu-latest
100+
101+
defaults:
102+
run:
103+
working-directory: mediawiki
104+
105+
steps:
106+
- name: Setup PHP
107+
uses: shivammathur/setup-php@v2
108+
with:
109+
php-version: ${{ matrix.php }}
110+
extensions: mbstring
111+
tools: composer, cs2pr
112+
113+
- name: Cache MediaWiki
114+
id: cache-mediawiki
115+
uses: actions/cache@v4
116+
with:
117+
path: |
118+
mediawiki
119+
mediawiki/extensions/
120+
mediawiki/vendor/
121+
key: mw_${{ matrix.mw }}-php${{ matrix.php }}_v2
122+
123+
- name: Cache Composer cache
124+
uses: actions/cache@v4
125+
with:
126+
path: ~/.composer/cache
127+
key: composer_static_analysis
128+
129+
- uses: actions/checkout@v4
130+
with:
131+
path: EarlyCopy
132+
133+
- name: Install MediaWiki
134+
if: steps.cache-mediawiki.outputs.cache-hit != 'true'
135+
working-directory: ~
136+
run: bash EarlyCopy/.github/workflows/installMediaWiki.sh ${{ matrix.mw }} SubPageList
137+
138+
- uses: actions/checkout@v4
139+
with:
140+
path: mediawiki/extensions/SubPageList
141+
142+
- name: Composer allow-plugins
143+
run: composer config --no-plugins allow-plugins.composer/installers true
144+
145+
- run: composer update
146+
147+
- name: Composer install
148+
run: cd extensions/SubPageList && composer install --no-progress --no-interaction --prefer-dist --optimize-autoloader
149+
150+
- name: PHPStan
151+
run: cd extensions/SubPageList && php vendor/bin/phpstan analyse --error-format=checkstyle --no-progress | cs2pr
152+
153+
phpcs:
154+
name: "Code style: MW ${{ matrix.mw }}, PHP ${{ matrix.php }}"
155+
156+
strategy:
157+
matrix:
158+
include:
159+
- mw: 'REL1_43'
160+
php: '8.2'
161+
162+
runs-on: ubuntu-latest
163+
164+
defaults:
165+
run:
166+
working-directory: mediawiki/extensions/SubPageList
167+
168+
steps:
169+
- name: Setup PHP
170+
uses: shivammathur/setup-php@v2
171+
with:
172+
php-version: ${{ matrix.php }}
173+
extensions: mbstring, intl, php-ast
174+
tools: composer
175+
176+
- name: Cache MediaWiki
177+
id: cache-mediawiki
178+
uses: actions/cache@v4
179+
with:
180+
path: |
181+
mediawiki
182+
!mediawiki/extensions/
183+
!mediawiki/vendor/
184+
key: mw_static_analysis
185+
186+
- name: Cache Composer cache
187+
uses: actions/cache@v4
188+
with:
189+
path: ~/.composer/cache
190+
key: mw_${{ matrix.mw }}-php${{ matrix.php }}_v2
191+
192+
- name: Install MediaWiki
193+
if: steps.cache-mediawiki.outputs.cache-hit != 'true'
194+
working-directory: ~
195+
run: curl EarlyCopy/.github/workflows/installMediaWiki.sh | bash -s ${{ matrix.mw }} SubPageList
196+
197+
- uses: actions/checkout@v4
198+
with:
199+
path: mediawiki/extensions/SubPageList
200+
201+
- name: Composer install
202+
run: composer install --no-progress --no-interaction --prefer-dist --optimize-autoloader
203+
204+
- run: vendor/bin/phpcs -p -s
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#! /bin/bash
2+
3+
MW_BRANCH=$1
4+
EXTENSION_NAME=$2
5+
6+
wget "https://github.com/wikimedia/mediawiki/archive/refs/heads/$MW_BRANCH.tar.gz" -nv
7+
8+
tar -zxf $MW_BRANCH.tar.gz
9+
mv mediawiki-$MW_BRANCH mediawiki
10+
11+
cd mediawiki
12+
13+
composer install
14+
php maintenance/install.php --dbtype sqlite --dbuser root --dbname mw --dbpath $(pwd) --pass AdminPassword WikiName AdminUser
15+
16+
cat <<'EOT' >> LocalSettings.php
17+
error_reporting(E_ALL| E_STRICT);
18+
ini_set("display_errors", "1");
19+
$wgShowExceptionDetails = true;
20+
$wgShowDBErrorBacktrace = true;
21+
$wgDevelopmentWarnings = true;
22+
EOT
23+
24+
cat <<EOT >> LocalSettings.php
25+
wfLoadExtension( "$EXTENSION_NAME" );
26+
EOT
27+
28+
cat <<EOT >> composer.local.json
29+
{
30+
"extra": {
31+
"merge-plugin": {
32+
"merge-dev": true,
33+
"include": [
34+
"extensions/$EXTENSION_NAME/composer.json"
35+
]
36+
}
37+
}
38+
}
39+
EOT

Makefile

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Commands run from inside the MediaWiki container ##########################################################
2+
3+
ci: test cs
4+
test: phpunit
5+
cs: phpcs stan
6+
7+
phpunit:
8+
ifdef filter
9+
php ../../tests/phpunit/phpunit.php -c phpunit.xml.dist --filter $(filter)
10+
else
11+
php ../../tests/phpunit/phpunit.php -c phpunit.xml.dist
12+
endif
13+
14+
perf:
15+
php ../../tests/phpunit/phpunit.php -c phpunit.xml.dist --group Performance
16+
17+
phpcs:
18+
vendor/bin/phpcs -p -s --standard=$(shell pwd)/phpcs.xml
19+
20+
stan:
21+
vendor/bin/phpstan analyse --configuration=phpstan.neon --memory-limit=2G
22+
23+
stan-baseline:
24+
vendor/bin/phpstan analyse --configuration=phpstan.neon --memory-limit=2G --generate-baseline

composer.json

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,21 @@
2626
"irc": "irc://irc.libera.chat/mediawiki"
2727
},
2828
"require": {
29-
"php": ">=7.3",
29+
"php": ">=8.1",
3030
"composer/installers": "^2|^1.0.1",
3131
"mediawiki/parser-hooks": "~1.3"
3232
},
33-
"config": {
34-
"allow-plugins": {
35-
"composer/installers": true
36-
}
33+
"require-dev": {
34+
"phpstan/phpstan": "^2.0.1",
35+
"mediawiki/mediawiki-codesniffer": "^45.0.0"
3736
},
3837
"extra": {
39-
"branch-alias": {
40-
"dev-master": "3.x-dev"
38+
"installer-name": "SubPageList"
39+
},
40+
"config": {
41+
"allow-plugins": {
42+
"composer/installers": true,
43+
"dealerdirect/phpcodesniffer-composer-installer": true
4144
}
4245
}
4346
}

phpcs.xml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?xml version="1.0"?>
2+
<ruleset>
3+
<file>src/</file>
4+
<file>tests/</file>
5+
6+
<arg name="extensions" value="php"/>
7+
8+
<rule ref="./vendor/mediawiki/mediawiki-codesniffer/MediaWiki">
9+
<exclude name="Generic.Files.LineLength.TooLong" />
10+
<exclude name="Generic.WhiteSpace.LanguageConstructSpacing.IncorrectSingle" />
11+
<exclude name="MediaWiki.Commenting.FunctionComment" />
12+
<exclude name="MediaWiki.Commenting.PropertyDocumentation" />
13+
<exclude name="MediaWiki.Commenting.FunctionAnnotations.UnrecognizedAnnotation" />
14+
<exclude name="MediaWiki.Commenting.MissingCovers.MissingCovers" />
15+
<exclude name="MediaWiki.ControlStructures.IfElseStructure.SpaceBeforeElse" />
16+
<exclude name="MediaWiki.WhiteSpace.SpaceBeforeSingleLineComment" />
17+
<exclude name="MediaWiki.WhiteSpace.DisallowEmptyLineFunctions.NoEmptyLine" />
18+
<exclude name="MediaWiki.WhiteSpace.SpaceAfterClosure.NoWhitespaceAfterClosure" />
19+
<exclude name="MediaWiki.WhiteSpace.SameLineCatch.CatchNotOnSameLine" />
20+
<exclude name="MediaWiki.WhiteSpace.SpaceAfterClosure.NoWhitespaceAfterArrow" />
21+
<exclude name="MediaWiki.Classes.UnusedUseStatement.UnusedUse" />
22+
<exclude name="MediaWiki.Classes.UnsortedUseStatements.UnsortedUse" />
23+
<exclude name="MediaWiki.Usage.StaticClosure.StaticClosure" />
24+
<exclude name="MediaWiki.PHPUnit.MockBoilerplate.ConstraintEqualTo" />
25+
<exclude name="Squiz.WhiteSpace.SuperfluousWhitespace.EndLine" />
26+
<exclude name="Squiz.ControlStructures.ControlSignature.SpaceAfterCloseBrace" />
27+
<exclude name="Universal.WhiteSpace.CommaSpacing.SpaceBeforeInFunctionCall" />
28+
<exclude name="Generic.Functions.OpeningFunctionBraceKernighanRitchie.ContentAfterBrace" />
29+
</rule>
30+
31+
<rule ref="Generic.Formatting.NoSpaceAfterCast" />
32+
<rule ref="Generic.Metrics.CyclomaticComplexity">
33+
</rule>
34+
<rule ref="Generic.Metrics.NestingLevel" />
35+
<rule ref="Squiz.Operators.ValidLogicalOperators" />
36+
</ruleset>

phpstan-baseline.neon

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
parameters:
2+
ignoreErrors:

phpstan.neon

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
includes:
2+
- phpstan-baseline.neon
3+
4+
parameters:
5+
level: 9
6+
paths:
7+
- src
8+
scanDirectories:
9+
- ../../includes
10+
- ../../tests/phpunit
11+
- ../../vendor
12+
bootstrapFiles:
13+
- ../../includes/AutoLoader.php

0 commit comments

Comments
 (0)