diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index 7a12b45..d2b9be2 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -21,7 +21,7 @@ env: jobs: # Test the image Dockerfile syntax using https://github.com/replicatedhq/dockerfilelint - test: + lint: runs-on: ubuntu-latest if: github.event_name == 'push' || github.event_name == 'pull_request' steps: @@ -33,6 +33,79 @@ jobs: dockerfile: "Dockerfile" config: "hadolint.yaml" + test: + needs: [lint] + runs-on: ubuntu-latest + if: github.event_name == 'push' || github.event_name == 'pull_request' + steps: + - name: Checkout + uses: actions/checkout@v3 + + - + name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + with: + install: true + + - + name: Cache Docker layers + uses: actions/cache@v3 + with: + path: /tmp/.buildx-cache + key: ${{ runner.os }}-buildx-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-buildx- + + - + name: Build image + uses: docker/build-push-action@v3 + id: docker_build + with: + context: . + load: true + tags: canasta-base:test + push: false + cache-from: type=gha + cache-to: type=gha,mode=max + + - name: Start Redis + uses: supercharge/redis-github-action@1.6.0 + with: + redis-version: 7 + redis-port: 6379 + + - name: Shut down Ubuntu MySQL (SUDO) + run: sudo service mysql stop + + - name: Start MariaDB + uses: getong/mariadb-action@v1.1 + with: + host port: 3306 + container port: 3306 + character set server: 'utf8' + collation server: 'utf8_general_ci' + mariadb version: '10.4.10' + mysql database: 'mediawiki' + mysql root password: 'mediawiki' + mysql user: 'mediawiki' + mysql password: 'mediawiki' + + # Debug +# - name: Setup upterm session +# uses: lhotari/action-upterm@v1 + + - + name: Run PHPUnit + uses: addnab/docker-run-action@v3 + with: + image: ${{ steps.docker_build.outputs.imageid }} + shell: bash + options: > + --add-host=host.docker.internal:host-gateway + -v ${{ github.workspace }}/run-ci.sh:/var/www/mediawiki/w/run-ci.sh + -v ${{ github.workspace }}/images:/var/www/mediawiki/w/images + run: bash run-ci.sh + # Push image to GitHub Packages. # The image tag pattern is: # for pull-requests: --, eg: 1.35.2-20210125-25 @@ -40,7 +113,7 @@ jobs: # for `master` branch: latest + -latest + -- # being parsed from the Dockerfile push: - needs: [test] + needs: [lint, test] runs-on: ubuntu-latest if: github.event_name == 'push' || github.event_name == 'pull_request' steps: diff --git a/run-ci.sh b/run-ci.sh new file mode 100644 index 0000000..134102d --- /dev/null +++ b/run-ci.sh @@ -0,0 +1,83 @@ +#!/bin/bash + +# This script is run by GitHub Actions workflow +# It requires MariaDB and Redis to be installed via supercharge/redis-github-action and getong/mariadb-action +# priori to running the script and the `host.docker.internal` to be bind via `--add-host` docker param +# The script is executed within the container + +# Setup +echo "Installing system packages.." +apt update -qq > /dev/null 2>&1 +apt install -y nodejs npm -qq > /dev/null 2>&1 + +echo "Installing Composer dependencies..." +rm -rf vendor +composer -n --quiet update > /dev/null 2>&1 + +echo "Installing test database..." +php maintenance/install.php \ + --scriptpath '' \ + --dbtype mysql \ + --dbuser root \ + --dbname mediawiki \ + --dbpass mediawiki \ + --pass AdminPassword \ + --dbport 3306 \ + --dbserver host.docker.internal \ + --installdbuser root \ + --installdbpass mediawiki \ + --skins Vector \ + WikiName \ + AdminUser > /dev/null 2>&1 + +echo "Configuring test LocalSettings file..." +echo 'error_reporting(0);' >> LocalSettings.php +#echo 'wfLoadExtension("Bootstrap");' >> LocalSettings.php +echo '$wgShowExceptionDetails = false;' >> LocalSettings.php +echo '$wgShowDBErrorBacktrace = false;' >> LocalSettings.php +echo '$wgDevelopmentWarnings = false;' >> LocalSettings.php +echo '$wgObjectCaches["redis"] = [ "class" => "RedisBagOStuff", "servers" => [ "host.docker.internal:6379" ] ];' >> LocalSettings.php +echo '$wgMainCacheType = "redis";' >> LocalSettings.php +echo '$wgSessionCacheType = "redis";' >> LocalSettings.php +echo '$wgPhpCli = "/usr/bin/php";' >> LocalSettings.php + +echo "Running database updates..." +php maintenance/update.php --quick > /dev/null 2>&1 + +# Lint +# composer run-script test + +# PHPUnit +echo "Running tests..." + +# PHPUnit core unit tests only (no extensions/skins in base image) +# Temporarily replace getPHPUnitExtensionsAndSkins.php to return empty list +mv tests/phpunit/getPHPUnitExtensionsAndSkins.php tests/phpunit/getPHPUnitExtensionsAndSkins.php.bak 2>/dev/null || true +echo '#!/usr/bin/env php +' > tests/phpunit/getPHPUnitExtensionsAndSkins.php +chmod +x tests/phpunit/getPHPUnitExtensionsAndSkins.php + +# PHPUnit unit tests +# Exclude testConstruct_notReadable - fails in Docker/root environments where file permissions aren't enforced +composer phpunit:unit -- --exclude-group Broken,ParserFuzz,Stub --filter '/^(?!.*testConstruct_notReadable).*$/' +phpunit_exit=$? + +# PHPUnit default suite (without database or standalone) +composer run --timeout=0 phpunit:entrypoint -- --exclude-group Broken,ParserFuzz,Stub,Database,Standalone +phpunit_exit=$((phpunit_exit || $?)) + +# PHPUnit default suite (with database) +composer run --timeout=0 phpunit:entrypoint -- --group Database --exclude-group Broken,ParserFuzz,Stub,Standalone +phpunit_exit=$((phpunit_exit || $?)) + +# Restore original script +mv tests/phpunit/getPHPUnitExtensionsAndSkins.php.bak tests/phpunit/getPHPUnitExtensionsAndSkins.php 2>/dev/null || true + +# Exit with combined PHPUnit exit code +exit $phpunit_exit + +#composer run phpunit -- --exclude-group Broken,ParserFuzz,Stub --stop-on-failure --stop-on-error + +# Qunit