Skip to content
This repository was archived by the owner on Jun 30, 2024. It is now read-only.

Commit 713e8ff

Browse files
Improve CI (#261)
* test: assert only the specific achiv. * selenium: run tests concurrently from femiwiki/.github@10c783c Co-authored-by: femiwiki-bot <[email protected]> Co-authored-by: Lens0021 <[email protected]>
1 parent 72516e3 commit 713e8ff

File tree

4 files changed

+127
-56
lines changed

4 files changed

+127
-56
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# If you see this message on 'femiwiki/.github' repository, please keep in mind that all changes of
2+
# this workflow file is for being copied to other repositories. If you see this message on any other
3+
# repositories, DO NOT EDIT this file itself. You should edit
4+
# https://github.com/femiwiki/.github/blob/main/workflow-templates/.github/workflows/create-pr-updating-extension-test.yml
5+
# Instead of this.
6+
7+
name: Create PR updating extension test
8+
9+
on:
10+
push:
11+
branches:
12+
- '*-update-extension-test'
13+
14+
jobs:
15+
create-pr:
16+
runs-on: ubuntu-latest
17+
18+
steps:
19+
- uses: actions/checkout@v3
20+
21+
- run: |
22+
echo 'CREATE_PR_BASE='$(echo "${{ github.ref_name }}" | cut -d'-' -f1 ) >> $GITHUB_ENV
23+
- name: Create Pull Request
24+
uses: repo-sync/pull-request@v2
25+
with:
26+
github_token: ${{ secrets.GITHUB_TOKEN }}
27+
pr_title: Update extension test workflow on ${{ env.CREATE_PR_BASE }} branch
28+
destination_branch: ${{ env.CREATE_PR_BASE }}

.github/workflows/test.yml .github/workflows/extension-test.yml

+69-32
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# If you see this message on 'femiwiki/.github' repository, please keep in mind that all changes of
2-
# this workflow file is for being copied to other repositories.
3-
# If you see this message on any other repositories, DO NOT EDIT this file itself. You should
4-
# edit https://github.com/femiwiki/.github/blob/main/workflows-template/extension-test.yml Instead
5-
# of this.
2+
# this workflow file is for being copied to other repositories. If you see this message on any other
3+
# repositories, DO NOT EDIT this file itself. You should edit
4+
# https://github.com/femiwiki/.github/blob/main/workflow-templates/.github/workflows/extension-test.yml
5+
# Instead of this.
66

77
name: Quibble and Phan
88

@@ -18,7 +18,8 @@ env:
1818
DOCKER_REGISTRY: docker-registry.wikimedia.org
1919
DOCKER_ORG: releng
2020
QUIBBLE_DOCKER_IMAGE: quibble-buster-php74
21-
COVERAGE_DOCKER_IMAGE: quibble-coverage
21+
# There is no quibble-buster-php74-coverage yet
22+
COVERAGE_DOCKER_IMAGE: quibble-buster-php73-coverage
2223
PHAN_DOCKER_IMAGE: mediawiki-phan-php74
2324

2425
jobs:
@@ -44,11 +45,21 @@ jobs:
4445

4546
# /home/runner/cache/ Cache
4647
# /home/runner/src/ Mediawiki installation
47-
# /home/runner/src/extensions/EXTENSION_NAME/ Clone of the extension repository
48+
# /home/runner/src/<TYPE>s/<EXTENSION_NAME>/ Clone of the extension repository
4849
# /home/runner/docker-images/ Docker images which exported with docker-save command
49-
# $GITHUB_WORKSPACE/.github/workflows/dependencies Used by actions/cache
50+
# $GITHUB_WORKSPACE/.github/workflows/dependencies Dependency extensions and skins
5051
- name: Set up
5152
run: |
53+
if [ -e skin.json ]; then
54+
echo "TYPE=skin" >> $GITHUB_ENV
55+
echo "EXTENSION_NAME=$(cat skin.json |
56+
python3 -c 'import json;import sys;print(json.loads("".join(sys.stdin.readlines()))["name"])')" >> $GITHUB_ENV
57+
else
58+
echo "TYPE=extension" >> $GITHUB_ENV
59+
echo "EXTENSION_NAME=$(cat extension.json |
60+
python3 -c 'import json;import sys;print(json.loads("".join(sys.stdin.readlines()))["name"])')" >> $GITHUB_ENV
61+
fi
62+
5263
# Export the target version of MediaWiki
5364
# An example of GITHUB_REF: refs/heads/feature-branch-1
5465
BRANCH_NAME=$(echo "$GITHUB_REF" | cut -d'/' -f3 | cut -d'-' -f1)
@@ -94,7 +105,7 @@ jobs:
94105
fi
95106
96107
- name: Cache docker image
97-
uses: actions/cache@v2
108+
uses: actions/cache@v3
98109
with:
99110
path: /home/runner/docker-images/${{ env.DOCKER_IMAGE }}
100111
key: ${{ env.DOCKER_IMAGE }}:${{ env.DOCKER_LATEST_TAG }}
@@ -104,7 +115,7 @@ jobs:
104115
docker pull "${DOCKER_REGISTRY}/${DOCKER_ORG}/${DOCKER_IMAGE}:${DOCKER_LATEST_TAG}"
105116
- name: Cache quibble docker image
106117
if: ${{ matrix.stage == 'coverage' || matrix.stage == 'phan' }}
107-
uses: actions/cache@v2
118+
uses: actions/cache@v3
108119
with:
109120
path: /home/runner/docker-images/${{ env.QUIBBLE_DOCKER_IMAGE }}
110121
key: ${{ env.QUIBBLE_DOCKER_IMAGE }}:${{ env.QUIBBLE_DOCKER_LATEST_TAG }}
@@ -115,10 +126,10 @@ jobs:
115126
docker pull "${DOCKER_REGISTRY}/${DOCKER_ORG}/${QUIBBLE_DOCKER_IMAGE}:${QUIBBLE_DOCKER_LATEST_TAG}"
116127
117128
- name: Cache MediaWiki installation
118-
uses: actions/cache@v2
129+
uses: actions/cache@v3
119130
with:
120131
path: /home/runner/src
121-
key: ${{ runner.os }}-${{ env.MEDIAWIKI_VERSION }}-b42e1abf-${{ hashFiles('.github/workflows/dependencies') }}
132+
key: ${{ runner.os }}-${{ env.MEDIAWIKI_VERSION }}-${{ hashFiles('.github/workflows/dependencies') }}
122133
- name: Download MediaWiki and extensions
123134
run: |
124135
cd /home/runner
@@ -132,7 +143,7 @@ jobs:
132143
git -C src/ log -n 1 --format="%H"
133144
134145
- name: Cache dependencies (composer and npm)
135-
uses: actions/cache@v2
146+
uses: actions/cache@v3
136147
with:
137148
path: /home/runner/cache
138149
key: ${{ runner.os }}-${{ env.MEDIAWIKI_VERSION }}-${{ hashFiles('**/*.lock') }}
@@ -141,26 +152,43 @@ jobs:
141152
uses: shivammathur/setup-php@v2
142153
with:
143154
php-version: '7.4'
144-
tools: composer:v2
145155
- name: Composer install
146156
if: ${{ matrix.stage == 'phan' }}
147157
run: |
148158
composer install --prefer-dist --no-progress --no-interaction # $GITHUB_WORKSPACE
159+
- name: Setup Node.js environment
160+
uses: actions/setup-node@v2
161+
- name: Get yarn cache directory path
162+
id: yarn-cache-dir-path
163+
run: echo "::set-output name=dir::$(yarn cache dir)"
164+
- uses: actions/cache@v2
165+
id: yarn-cache
166+
with:
167+
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
168+
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
169+
restore-keys: ${{ runner.os }}-yarn-
170+
171+
- name: Run npm because Quibble is not compatible with yarn.
172+
run: |
173+
if [ -f yarn.lock ]; then
174+
npm install
175+
fi
149176
150177
- name: Main Test
151178
run: |
152179
cd /home/runner
153-
# Move our extension
154-
sudo cp -r "${GITHUB_WORKSPACE}" src/extensions/
155-
mkdir -p cache cover
180+
# Move our repository
181+
mkdir -p cache cover src/skins src/extensions
182+
sudo cp -r "${GITHUB_WORKSPACE}" "src/${{ env.TYPE }}s/${{ env.EXTENSION_NAME }}"
156183
chmod 777 src cache cover
157-
# chown cache/ https://github.com/femiwiki/.github/issues/3
184+
# https://github.com/femiwiki/.github/issues/3
158185
sudo chown -R nobody:nogroup src cache
159186
sudo chown $(id -u):$(id -g) src cache
160187
# Composer install
161188
if [ "${{ matrix.stage }}" == 'phan' ] || [ "${{ matrix.stage }}" == 'coverage' ]; then
162189
docker run \
163-
-e ZUUL_PROJECT=mediawiki/extensions/"${{ github.event.repository.name }}" \
190+
--entrypoint quibble-with-supervisord \
191+
-e "ZUUL_PROJECT=mediawiki/${{ env.TYPE }}s/${{ env.EXTENSION_NAME }}" \
164192
-v "$(pwd)"/cache:/cache \
165193
-v "$(pwd)"/src:/workspace/src \
166194
"${DOCKER_REGISTRY}/${DOCKER_ORG}/${QUIBBLE_DOCKER_IMAGE}:${QUIBBLE_DOCKER_LATEST_TAG}" \
@@ -173,26 +201,35 @@ jobs:
173201
174202
if [ "${{ matrix.stage }}" == 'phan' ]; then
175203
docker run \
176-
-e THING_SUBNAME=extensions/"${{ github.event.repository.name }}" \
204+
-e "THING_SUBNAME=${{ env.TYPE }}s/${{ env.EXTENSION_NAME }}" \
177205
-v "$(pwd)"/src:/mediawiki \
178206
"${DOCKER_REGISTRY}/${DOCKER_ORG}/${DOCKER_IMAGE}:${DOCKER_LATEST_TAG}" \
179207
--color
180208
elif [ "${{ matrix.stage }}" == 'coverage' ]; then
181-
# MW1.35 requires PHP7.3 but quibble-coverage is not.
182-
if [ "${MEDIAWIKI_VERSION}" == master ]; then
183-
docker run \
184-
-e ZUUL_PROJECT=mediawiki/extensions/"${{ github.event.repository.name }}" \
185-
-v "$(pwd)"/cache:/cache \
186-
-v "$(pwd)"/src:/workspace/src \
187-
-v "$(pwd)"/cover:/workspace/cover \
188-
"${DOCKER_REGISTRY}/${DOCKER_ORG}/${DOCKER_IMAGE}:${DOCKER_LATEST_TAG}" \
189-
--skip-zuul \
190-
--skip-deps \
191-
-c mwext-phpunit-coverage
209+
if [ -d tests/phpunit ]; then
210+
# MW1.35+ requires PHP7.3 but quibble-coverage is not.
211+
if [ "${MEDIAWIKI_VERSION}" == 'master' ]; then
212+
if [ "${TYPE}" == 'skin' ]; then
213+
COMMEND=mwskin-phpunit-coverage
214+
else
215+
COMMEND=mwext-phpunit-coverage
216+
fi
217+
docker run \
218+
--entrypoint quibble-with-supervisord \
219+
-e "ZUUL_PROJECT=mediawiki/${{ env.TYPE }}s/${{ env.EXTENSION_NAME }}" \
220+
-v "$(pwd)"/cache:/cache \
221+
-v "$(pwd)"/src:/workspace/src \
222+
-v "$(pwd)"/cover:/workspace/cover \
223+
"${DOCKER_REGISTRY}/${DOCKER_ORG}/${DOCKER_IMAGE}:${DOCKER_LATEST_TAG}" \
224+
--skip-zuul \
225+
--skip-deps \
226+
-c "${COMMEND}"
227+
fi
192228
fi
193229
else
194230
docker run \
195-
-e ZUUL_PROJECT=mediawiki/extensions/"${{ github.event.repository.name }}" \
231+
--entrypoint quibble-with-supervisord \
232+
-e "ZUUL_PROJECT=mediawiki/${{ env.TYPE }}s/${{ env.EXTENSION_NAME }}" \
196233
-v "$(pwd)"/cache:/cache \
197234
-v "$(pwd)"/src:/workspace/src \
198235
"${DOCKER_REGISTRY}/${DOCKER_ORG}/${DOCKER_IMAGE}:${DOCKER_LATEST_TAG}" \
@@ -211,7 +248,7 @@ jobs:
211248
- name: Tear down
212249
run: |
213250
cd /home/runner
214-
sudo rm -rf src/extensions/"${{ github.event.repository.name }}"
251+
sudo rm -rf "src/${{ env.TYPE }}s/${{ env.EXTENSION_NAME }}"
215252
# See https://doc.wikimedia.org/quibble/index.html#remove-localsettings-php-between-runs
216253
rm "$(pwd)"/src/LocalSettings.php || true
217254
mkdir -p docker-images

tests/phpunit/integration/AchieveTest.php

+29-24
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
* @group Database
1414
*
1515
* @covers \MediaWiki\Extension\AchievementBadges\Achievement
16-
* @covers \MediaWiki\Extension\AchievementBadges\Achievement
1716
*/
1817
class AchieveTest extends MediaWikiIntegrationTestCase {
1918

@@ -23,22 +22,25 @@ protected function setUp(): void {
2322
}
2423

2524
/**
26-
* @param int $num
25+
* @param bool $earned
2726
* @param User $user
28-
* @param string $type
27+
* @param string $key
2928
* @param string $msg
30-
* @return int
29+
* @return void
3130
*/
32-
private function assertNotificationNumber( $num, $user, $type, $msg ) {
31+
private function assertNotificationForAchievement( $earned, $user, $key, $msg ) {
3332
$notifMapper = new EchoNotificationMapper();
3433
$limit = 50;
35-
$notifs = $notifMapper->fetchUnreadByUser( $user, $limit, '', [ $type ] );
36-
$texts = [];
37-
foreach ( $notifs as $noti ) {
38-
$event = $noti->getEvent();
39-
$texts[] = $event . '(' . implode( ', ', array_values( $event->getExtra() ) ) . ')';
34+
$notifs = $notifMapper->fetchUnreadByUser( $user, $limit, null, [ Constants::EVENT_KEY_EARN ] );
35+
$eventKeys = array_map( static function ( $notif ) {
36+
return $notif->getEvent()->getExtra()['key'];
37+
}, $notifs );
38+
if ( $earned ) {
39+
$this->assertContains( $key, $eventKeys,
40+
"$msg: $key not found in " . implode( ', ', $eventKeys ) );
41+
} else {
42+
$this->assertNotContains( $key, $eventKeys, $msg );
4043
}
41-
$this->assertCount( $num, $notifs, "$msg (" . implode( ', ', $texts ) . ')' );
4244
}
4345

4446
private function assertEarnedAchievement( $num, $user, $key ) {
@@ -77,15 +79,15 @@ public function testAchieveEditPages() {
7779
// Edit a page
7880
$this->editPage( 'Edit Test', str_repeat( 'lorem', $ct++ ), '', NS_MAIN, $user );
7981
$this->assertSame( 1, $user->getEditCount() );
80-
$this->assertNotificationNumber( 1, $user, Constants::EVENT_KEY_EARN,
82+
$this->assertNotificationForAchievement( true, $user, Constants::ACHV_KEY_EDIT_PAGE . '-0',
8183
"edit-page-0 should be achieved (edit count: {$user->getEditCount()})" );
8284
$this->assertEarnedAchievement( 1, $user, Constants::ACHV_KEY_EDIT_PAGE );
8385

8486
// Edit another page
8587
$this->editPage( 'Edit Test', str_repeat( 'lorem', $ct++ ), '', NS_MAIN, $user );
8688
$this->assertSame( 2, $user->getEditCount() );
87-
$this->assertNotificationNumber( 2, $user, Constants::EVENT_KEY_EARN,
88-
"Only edit-page-0 should be achieved (edit count: {$user->getEditCount()})" );
89+
$this->assertNotificationForAchievement( true, $user, Constants::ACHV_KEY_EDIT_PAGE . '-1',
90+
"edit-page-0 should be achieved (edit count: {$user->getEditCount()})" );
8991
$this->assertEarnedAchievement( 2, $user, Constants::ACHV_KEY_EDIT_PAGE );
9092
}
9193

@@ -108,14 +110,14 @@ public function testAchieveCreatePages() {
108110
$ct = 1;
109111
// Create a page
110112
$this->editPage( 'Creation test' . $ct++, 'ipsum', '', NS_MAIN, $user );
111-
$this->assertNotificationNumber( 1, $user, Constants::EVENT_KEY_EARN,
113+
$this->assertNotificationForAchievement( true, $user, Constants::ACHV_KEY_CREATE_PAGE . '-0',
112114
"create-page-0 should be achieved" );
113115
$this->assertEarnedAchievement( 1, $user, Constants::ACHV_KEY_CREATE_PAGE );
114116

115117
// Create another page
116118
$this->editPage( 'Creation test' . $ct++, 'ipsum', '', NS_MAIN, $user );
117-
$this->assertNotificationNumber( 2, $user, Constants::EVENT_KEY_EARN,
118-
"Only create-page-0 should be achieved" );
119+
$this->assertNotificationForAchievement( true, $user, Constants::ACHV_KEY_CREATE_PAGE . '-1',
120+
"create-page-0 should be achieved" );
119121
$this->assertEarnedAchievement( 2, $user, Constants::ACHV_KEY_CREATE_PAGE );
120122
}
121123

@@ -132,13 +134,13 @@ public function testAchieveEditSize() {
132134
] );
133135

134136
$this->editPage( 'Size test', str_repeat( 'ipsum', 10 ), '', NS_MAIN, $user );
135-
$this->assertNotificationNumber( 1, $user, Constants::EVENT_KEY_EARN,
137+
$this->assertNotificationForAchievement( true, $user, Constants::ACHV_KEY_EDIT_SIZE . '-0',
136138
"edit-size-0 should be achieved" );
137139
$this->assertEarnedAchievement( 1, $user, Constants::ACHV_KEY_EDIT_SIZE );
138140

139141
$this->editPage( 'Size test', str_repeat( 'ipsum', 30 ), '', NS_MAIN, $user );
140-
$this->assertNotificationNumber( 2, $user, Constants::EVENT_KEY_EARN,
141-
"Only edit-size-0 should be achieved" );
142+
$this->assertNotificationForAchievement( true, $user, Constants::ACHV_KEY_EDIT_SIZE . '-1',
143+
"edit-size-0 should be achieved" );
142144
$this->assertEarnedAchievement( 2, $user, Constants::ACHV_KEY_EDIT_SIZE );
143145
}
144146

@@ -160,7 +162,7 @@ public function testAchieveEditSizeExist() {
160162
$user->addToDatabase();
161163

162164
$this->editPage( $titleText, $content . 'dolor', '', NS_MAIN, $user );
163-
$this->assertNotificationNumber( 0, $user, Constants::EVENT_KEY_EARN,
165+
$this->assertNotificationForAchievement( false, $user, Constants::ACHV_KEY_EDIT_SIZE . '-0',
164166
"edit-size-0 should not be achieved" );
165167
$this->assertEarnedAchievement( 0, $user, Constants::ACHV_KEY_EDIT_SIZE );
166168
}
@@ -182,8 +184,11 @@ public function testAchieveManyEditSize() {
182184
] );
183185

184186
$this->editPage( __METHOD__, str_repeat( 'ipsum', 30 ), '', NS_MAIN, $user );
185-
$this->assertNotificationNumber( 5, $user, Constants::EVENT_KEY_EARN,
186-
"All edit-size should be achieved" );
187+
188+
$this->assertNotificationForAchievement( true, $user, Constants::ACHV_KEY_EDIT_SIZE . '-0',
189+
"All edit-size-0 should be achieved" );
190+
$this->assertNotificationForAchievement( true, $user, Constants::ACHV_KEY_EDIT_SIZE . '-4',
191+
"All edit-size-4 should be achieved" );
187192
$this->assertEarnedAchievement( 5, $user, Constants::ACHV_KEY_EDIT_SIZE );
188193
}
189194

@@ -198,7 +203,7 @@ public function testLongUserPage() {
198203
$longText = str_repeat( 'lorem ipsum dolor amat', 40 );
199204

200205
$this->editPage( $user->getName(), $longText, '', NS_USER, $user );
201-
$this->assertNotificationNumber( 1, $user, Constants::EVENT_KEY_EARN,
206+
$this->assertNotificationForAchievement( true, $user, Constants::ACHV_KEY_LONG_USER_PAGE,
202207
'Should be achieved long-user-page' );
203208
$this->assertEarnedAchievement( 1, $user, Constants::ACHV_KEY_LONG_USER_PAGE );
204209
}

tests/selenium/wdio.conf.js

+1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ exports.config = {
99
//
1010
// Example:
1111
// logLevel: 'info',
12+
maxInstances: 4,
1213
};

0 commit comments

Comments
 (0)