From a62b055cfeaef79742fbad9e50ad24f622ac2c51 Mon Sep 17 00:00:00 2001 From: Universal Omega <54654040+Universal-Omega@users.noreply.github.com> Date: Sat, 11 Sep 2021 12:55:27 -0600 Subject: [PATCH] Better CI tests (#6) --- .github/workflows/download-mediawiki.sh | 12 +++ .github/workflows/mediawiki-REL1_36.yml | 57 ----------- .github/workflows/mediawiki-master.yml | 60 ------------ .github/workflows/mediawiki-tests.yml | 95 +++++++++++++++++++ .gitignore | 1 + .phan/config.php | 2 - composer.json | 4 +- .../Parser/MediaWikiParserService.php | 2 +- includes/services/Parser/Nodes/Node.php | 5 +- .../Parser/Nodes/NodeUnimplemented.php | 2 + 10 files changed, 116 insertions(+), 124 deletions(-) create mode 100644 .github/workflows/download-mediawiki.sh delete mode 100644 .github/workflows/mediawiki-REL1_36.yml delete mode 100644 .github/workflows/mediawiki-master.yml create mode 100644 .github/workflows/mediawiki-tests.yml diff --git a/.github/workflows/download-mediawiki.sh b/.github/workflows/download-mediawiki.sh new file mode 100644 index 0000000..6919472 --- /dev/null +++ b/.github/workflows/download-mediawiki.sh @@ -0,0 +1,12 @@ +#! /bin/bash +set -ex + +MW_BRANCH=$1 + +wget https://github.com/wikimedia/mediawiki/archive/"$MW_BRANCH".tar.gz -nv + +tar -zxf "$MW_BRANCH".tar.gz +mv mediawiki-"$MW_BRANCH" mediawiki + +cd mediawiki +composer update --prefer-dist --no-progress diff --git a/.github/workflows/mediawiki-REL1_36.yml b/.github/workflows/mediawiki-REL1_36.yml deleted file mode 100644 index 4a82743..0000000 --- a/.github/workflows/mediawiki-REL1_36.yml +++ /dev/null @@ -1,57 +0,0 @@ -name: Continuous integration (REL1_36) - -on: - create: - push: - pull_request: - types: [opened, synchronize] - -jobs: - test: - name: Test and lint - runs-on: ubuntu-latest - strategy: - matrix: - php-versions: ['7.3'] - steps: - - uses: actions/checkout@v2 - - - name: Install dependencies - run: | - composer validate - composer install --prefer-dist --no-progress - sudo pecl install ast - echo "extension=ast" | sudo tee -a /etc/php/8.0/cli/php.ini - - # Bypass the phpcbf non-standard exit code - - name: Check PHP - run: | - sh phpcbf.sh - composer fix - composer test - - - name: Clone MediaWiki - run: | - git clone https://github.com/wikimedia/mediawiki.git --branch=REL1_36 --depth=1 - cd mediawiki - git submodule update --init extensions/PageImages - composer install --no-dev - cd .. - - - name: Run phan - run: | - composer phan - - # Only patch code when it is a push event - - name: Push the changes - if: github.event_name == 'push' - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: | - git config --global user.name "github-actions" - git config --global user.email "github-actions@users.noreply.github.com" - git remote set-url origin "https://x-access-token:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git" - git add . - git commit -am "CI: lint code to MediaWiki standards" -m "Check commit and GitHub actions for more details" || echo "No changes to commit" - git pull --rebase - git push diff --git a/.github/workflows/mediawiki-master.yml b/.github/workflows/mediawiki-master.yml deleted file mode 100644 index 47bbdd0..0000000 --- a/.github/workflows/mediawiki-master.yml +++ /dev/null @@ -1,60 +0,0 @@ -name: Continuous integration (master) - -on: - create: - push: - pull_request: - types: [opened, synchronize] - -jobs: - test: - name: Test and lint - runs-on: ubuntu-latest - strategy: - matrix: - php-versions: ['7.3'] - steps: - - uses: actions/checkout@v2 - - - name: Install dependencies - run: | - composer validate - composer install --prefer-dist --no-progress - sudo pecl install ast - echo "extension=ast" | sudo tee -a /etc/php/8.0/cli/php.ini - - # Bypass the phpcbf non-standard exit code - - name: Check PHP - run: | - sh phpcbf.sh - composer fix - composer test - - - name: Clone MediaWiki - run: | - git clone https://github.com/wikimedia/mediawiki.git --depth=1 - cd mediawiki - git clone https://github.com/wikimedia/mediawiki-extensions-PageImages.git --depth=1 extensions/PageImages - composer install --no-dev - cd .. - - - name: Run phan - run: | - composer phan - - # - name: PHPUnit tests - # uses: php-actions/phpunit@v3 - - # Only patch code when it is a push event - - name: Push the changes - if: github.event_name == 'push' - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: | - git config --global user.name "github-actions" - git config --global user.email "github-actions@users.noreply.github.com" - git remote set-url origin "https://x-access-token:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git" - git add . - git commit -am "CI: lint code to MediaWiki standards" -m "Check commit and GitHub actions for more details" || echo "No changes to commit" - git pull --rebase - git push diff --git a/.github/workflows/mediawiki-tests.yml b/.github/workflows/mediawiki-tests.yml new file mode 100644 index 0000000..c3f1818 --- /dev/null +++ b/.github/workflows/mediawiki-tests.yml @@ -0,0 +1,95 @@ +name: MediaWiki tests + +on: + push: + pull_request: + branches: [ master ] + +jobs: + test: + name: "MediaWiki ${{ matrix.mw }} | PHP ${{ matrix.php }}" + continue-on-error: true + strategy: + matrix: + include: + # Latest stable MediaWiki - PHP 7.3 + - mw: 'REL1_36' + php: 7.3 + composer: v2 + continue-on-error: false + + # Latest stable MediaWiki - PHP 7.4 + - mw: 'REL1_36' + php: 7.4 + composer: v2 + continue-on-error: true + + # Latest MediaWiki master + - mw: 'master' + php: 7.3 + composer: v2 + continue-on-error: true + + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + extensions: intl,ast + tools: composer:${{ matrix.composer }} + + - name: Install dependencies + run: | + composer validate + composer update + + - name: Check PHP + if: ${{ matrix.mw == 'master' }} + run: | + sh phpcbf.sh + composer fix + composer test + + - name: Cache MediaWiki + id: cache-mediawiki + uses: actions/cache@v2 + with: + path: | + mediawiki + !mediawiki/extensions/ + !mediawiki/vendor/ + key: mw-${{ matrix.mw }}-php${{ matrix.php }}-v2 + + - name: Cache Composer cache + uses: actions/cache@v2 + with: + path: ~/.composer/cache + key: composer-php${{ matrix.php }} + + - name: Download MediaWiki + if: steps.cache-mediawiki.outputs.cache-hit != 'true' + run: | + bash .github/workflows/download-mediawiki.sh ${{ matrix.mw }} + git clone https://github.com/wikimedia/mediawiki-extensions-PageImages.git --depth=1 --branch=${{ matrix.mw }} mediawiki/extensions/PageImages + + - name: Run phan + continue-on-error: ${{ matrix.continue-on-error }} + run: | + composer phan + + # Only patch code when it is a push event + - name: Push the changes + if: github.event_name == 'push' && matrix.mw == 'master' + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + git config --global user.name "github-actions" + git config --global user.email "github-actions@users.noreply.github.com" + git remote set-url origin "https://x-access-token:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git" + git add . + git commit -am "CI: lint code to MediaWiki standards" -m "Check commit and GitHub actions for more details" || echo "No changes to commit" + git pull --rebase + git push diff --git a/.gitignore b/.gitignore index 70ff386..e592624 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ /vendor /node_modules /mediawiki +/*.tar.gz diff --git a/.phan/config.php b/.phan/config.php index 6fb1229..14df363 100644 --- a/.phan/config.php +++ b/.phan/config.php @@ -2,8 +2,6 @@ $cfg = require __DIR__ . '/../vendor/mediawiki/mediawiki-phan-config/src/config.php'; -$cfg['target_php_version'] = '7.3'; - $cfg['directory_list'] = array_merge( $cfg['directory_list'], [ 'mediawiki', diff --git a/composer.json b/composer.json index 4a1c6c1..95edcbf 100644 --- a/composer.json +++ b/composer.json @@ -4,10 +4,10 @@ "license": "GPL-3.0-or-later", "require-dev": { "mediawiki/mediawiki-codesniffer": "37.0.0", - "mediawiki/mediawiki-phan-config": "0.10.6", + "mediawiki/mediawiki-phan-config": "0.11.0", "mediawiki/minus-x": "1.1.1", "php-parallel-lint/php-console-highlighter": "0.5.0", - "php-parallel-lint/php-parallel-lint": "1.3.0" + "php-parallel-lint/php-parallel-lint": "1.3.1" }, "scripts": { "fix": [ diff --git a/includes/services/Parser/MediaWikiParserService.php b/includes/services/Parser/MediaWikiParserService.php index f94512a..ccbde68 100644 --- a/includes/services/Parser/MediaWikiParserService.php +++ b/includes/services/Parser/MediaWikiParserService.php @@ -35,7 +35,7 @@ class MediaWikiParserService implements ExternalParser { return $this->cache[$wikitext]; } - $parsed = $wikitext ? $this->parser->internalParse( $wikitext, false, $this->frame ) : null; + $parsed = $this->parser->internalParse( $wikitext, false, $this->frame ); if ( in_array( substr( $parsed, 0, 1 ), [ '*', '#' ] ) ) { // fix for first item list elements $parsed = "\n" . $parsed; diff --git a/includes/services/Parser/Nodes/Node.php b/includes/services/Parser/Nodes/Node.php index ad71010..66e584f 100644 --- a/includes/services/Parser/Nodes/Node.php +++ b/includes/services/Parser/Nodes/Node.php @@ -6,13 +6,14 @@ use PortableInfobox\Parser\SimpleParser; class Node { - private const DATA_SRC_ATTR_NAME = 'source'; private const NAME_ATTR_NAME = 'name'; private const DEFAULT_TAG_NAME = 'default'; private const FORMAT_TAG_NAME = 'format'; - private const LABEL_TAG_NAME = 'label'; private const EXTRACT_SOURCE_REGEX = '/{{{([^\|}]*?)\|?.*}}}/sU'; + protected const DATA_SRC_ATTR_NAME = 'source'; + protected const LABEL_TAG_NAME = 'label'; + protected $xmlNode; protected $infoboxData; protected $children; diff --git a/includes/services/Parser/Nodes/NodeUnimplemented.php b/includes/services/Parser/Nodes/NodeUnimplemented.php index 12c73d1..0c8328c 100644 --- a/includes/services/Parser/Nodes/NodeUnimplemented.php +++ b/includes/services/Parser/Nodes/NodeUnimplemented.php @@ -4,6 +4,8 @@ namespace PortableInfobox\Parser\Nodes; class NodeUnimplemented extends Node { public function getData() { + // @phan-suppress-previous-line PhanPluginNeverReturnMethod LSP violation. + throw new UnimplementedNodeException( $this->getType() ); } }