diff --git a/.github/workflows/image.yml b/.github/workflows/image.yml index fc8f7c1..112425e 100644 --- a/.github/workflows/image.yml +++ b/.github/workflows/image.yml @@ -7,38 +7,12 @@ on: pull_request: jobs: - docker-latest: - runs-on: ubuntu-latest - steps: - - - name: Checkout - uses: actions/checkout@v2 - - - name: Set up QEMU - uses: docker/setup-qemu-action@v1 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v1 - - - name: Login to DockerHub - uses: docker/login-action@v1 - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} - - - name: Build and push latest - uses: docker/build-push-action@v2 - with: - context: . - platforms: linux/amd64,linux/arm64 - push: ${{ github.ref == 'refs/heads/master' }} - tags: humanmade/plugin-tester:latest - docker-matrix: runs-on: ubuntu-latest strategy: matrix: - wp_version: ['5.4', '5.5', '5.6', '5.7', '5.8', '5.9', '6.0', '6.1', '6.2', '6.3', '6.4', '6.5', '6.6', '6.7', '6.8'] + wp_version: ['6.0', '6.1', '6.2', '6.3', '6.4', '6.5', '6.6', '6.7', '6.8'] + php_version: ['8.0', '8.1', '8.2', '8.3'] steps: - name: Checkout @@ -56,13 +30,17 @@ jobs: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - - name: Build and push ${{ matrix.wp_version }} + name: Build and push WP ${{ matrix.wp_version }} PHP ${{ matrix.php_version }} uses: docker/build-push-action@v2 with: context: . + file: Dockerfile.php${{ matrix.php_version }} build-args: | WP_VERSION=${{ matrix.wp_version }} platforms: linux/amd64,linux/arm64 push: ${{ github.ref == 'refs/heads/master' }} - tags: humanmade/plugin-tester:wp-${{ matrix.wp_version }} + tags: | + humanmade/plugin-tester:wp-${{ matrix.wp_version }}-php${{ matrix.php_version }} + ${{ matrix.php_version == '8.0' && format('humanmade/plugin-tester:wp-{0}', matrix.wp_version) || '' }} + ${{ matrix.php_version == '8.0' && matrix.wp_version == '6.8' && 'humanmade/plugin-tester:latest' || '' }} diff --git a/Dockerfile b/Dockerfile.php8.0 similarity index 65% rename from Dockerfile rename to Dockerfile.php8.0 index b2bf538..544e741 100644 --- a/Dockerfile +++ b/Dockerfile.php8.0 @@ -1,6 +1,6 @@ -FROM alpine:3.14 +FROM public.ecr.aws/docker/library/alpine:3.16 -ARG WP_VERSION=6.8 +ARG WP_VERSION RUN apk add -u --no-cache \ composer \ @@ -8,20 +8,23 @@ RUN apk add -u --no-cache \ imagemagick \ mysql \ mysql-client \ - php7 \ - php7-curl \ - php7-dom \ - php7-exif \ - php7-mysqli \ - php7-pecl-imagick \ - php7-simplexml \ - php7-tokenizer \ - php7-xml \ - php7-xmlwriter - -RUN apk add --no-cache php7-pear php7-dev gcc musl-dev make \ - && pecl install pcov && echo extension=pcov.so > /etc/php7/conf.d/pcov.ini \ - && apk del php7-pear php7-dev gcc musl-dev make + php8 \ + php8-curl \ + php8-dom \ + php8-exif \ + php8-mysqli \ + php8-pecl-imagick \ + php8-simplexml \ + php8-tokenizer \ + php8-xml \ + php8-xmlwriter + +RUN apk add --no-cache php8-pear php8-dev gcc musl-dev make \ + && pecl8 install pcov && echo extension=pcov.so > /etc/php8/conf.d/pcov.ini \ + && apk del php8-pear php8-dev gcc musl-dev make + +# Create php symlink to php8 +RUN ln -sf /usr/bin/php8 /usr/bin/php RUN wget -nv -O /tmp/wordpress.tar.gz https://wordpress.org/wordpress-${WP_VERSION}.tar.gz \ && mkdir /wordpress \ @@ -44,4 +47,4 @@ WORKDIR /code COPY ./docker-entrypoint.sh /entrypoint.sh COPY ./wp-tests-config.php /wp-tests-config.php RUN chmod 755 /entrypoint.sh -ENTRYPOINT ["/entrypoint.sh"] +ENTRYPOINT ["/entrypoint.sh"] \ No newline at end of file diff --git a/Dockerfile.php8.1 b/Dockerfile.php8.1 new file mode 100644 index 0000000..1472291 --- /dev/null +++ b/Dockerfile.php8.1 @@ -0,0 +1,50 @@ +FROM public.ecr.aws/docker/library/alpine:3.19 + +ARG WP_VERSION + +RUN apk add -u --no-cache \ + composer \ + git \ + imagemagick \ + mysql \ + mysql-client \ + php81 \ + php81-curl \ + php81-dom \ + php81-exif \ + php81-mysqli \ + php81-pecl-imagick \ + php81-simplexml \ + php81-tokenizer \ + php81-xml \ + php81-xmlwriter + +RUN apk add --no-cache php81-pear php81-dev gcc musl-dev make \ + && pecl81 install pcov && echo extension=pcov.so > /etc/php81/conf.d/pcov.ini \ + && apk del php81-pear php81-dev gcc musl-dev make + +# Create php symlink to php81 +RUN ln -sf /usr/bin/php81 /usr/bin/php + +RUN wget -nv -O /tmp/wordpress.tar.gz https://wordpress.org/wordpress-${WP_VERSION}.tar.gz \ + && mkdir /wordpress \ + && tar --strip-components=1 -zxmf /tmp/wordpress.tar.gz -C /wordpress \ + && rm /tmp/wordpress.tar.gz + +RUN wget -nv -O /tmp/wp-phpunit.tar.gz https://github.com/wp-phpunit/wp-phpunit/archive/${WP_VERSION}.0.tar.gz \ + && mkdir /wp-phpunit \ + && tar --strip-components=1 -zxmf /tmp/wp-phpunit.tar.gz -C /wp-phpunit \ + && rm /tmp/wp-phpunit.tar.gz + +RUN mysql_install_db --user=mysql --ldata=/var/lib/mysql +RUN sh -c 'mysqld_safe --datadir=/var/lib/mysql &' && sleep 4 && mysql -u root -e "CREATE DATABASE wordpress" + +ENV WP_DEVELOP_DIR=/wp-phpunit +ENV WP_PHPUNIT__TESTS_CONFIG=/wp-tests-config.php + +VOLUME ["/code"] +WORKDIR /code +COPY ./docker-entrypoint.sh /entrypoint.sh +COPY ./wp-tests-config.php /wp-tests-config.php +RUN chmod 755 /entrypoint.sh +ENTRYPOINT ["/entrypoint.sh"] \ No newline at end of file diff --git a/Dockerfile.php8.2 b/Dockerfile.php8.2 new file mode 100644 index 0000000..3d23a9d --- /dev/null +++ b/Dockerfile.php8.2 @@ -0,0 +1,50 @@ +FROM public.ecr.aws/docker/library/alpine:3.19 + +ARG WP_VERSION + +RUN apk add -u --no-cache \ + composer \ + git \ + imagemagick \ + mysql \ + mysql-client \ + php82 \ + php82-curl \ + php82-dom \ + php82-exif \ + php82-mysqli \ + php82-pecl-imagick \ + php82-simplexml \ + php82-tokenizer \ + php82-xml \ + php82-xmlwriter + +RUN apk add --no-cache php82-pear php82-dev gcc musl-dev make \ + && pecl82 install pcov && echo extension=pcov.so > /etc/php82/conf.d/pcov.ini \ + && apk del php82-pear php82-dev gcc musl-dev make + +# Create php symlink to php82 +RUN ln -sf /usr/bin/php82 /usr/bin/php + +RUN wget -nv -O /tmp/wordpress.tar.gz https://wordpress.org/wordpress-${WP_VERSION}.tar.gz \ + && mkdir /wordpress \ + && tar --strip-components=1 -zxmf /tmp/wordpress.tar.gz -C /wordpress \ + && rm /tmp/wordpress.tar.gz + +RUN wget -nv -O /tmp/wp-phpunit.tar.gz https://github.com/wp-phpunit/wp-phpunit/archive/${WP_VERSION}.0.tar.gz \ + && mkdir /wp-phpunit \ + && tar --strip-components=1 -zxmf /tmp/wp-phpunit.tar.gz -C /wp-phpunit \ + && rm /tmp/wp-phpunit.tar.gz + +RUN mysql_install_db --user=mysql --ldata=/var/lib/mysql +RUN sh -c 'mysqld_safe --datadir=/var/lib/mysql &' && sleep 4 && mysql -u root -e "CREATE DATABASE wordpress" + +ENV WP_DEVELOP_DIR=/wp-phpunit +ENV WP_PHPUNIT__TESTS_CONFIG=/wp-tests-config.php + +VOLUME ["/code"] +WORKDIR /code +COPY ./docker-entrypoint.sh /entrypoint.sh +COPY ./wp-tests-config.php /wp-tests-config.php +RUN chmod 755 /entrypoint.sh +ENTRYPOINT ["/entrypoint.sh"] \ No newline at end of file diff --git a/Dockerfile.php8.3 b/Dockerfile.php8.3 new file mode 100644 index 0000000..6ac6a1a --- /dev/null +++ b/Dockerfile.php8.3 @@ -0,0 +1,50 @@ +FROM public.ecr.aws/docker/library/alpine:3.19 + +ARG WP_VERSION + +RUN apk add -u --no-cache \ + composer \ + git \ + imagemagick \ + mysql \ + mysql-client \ + php83 \ + php83-curl \ + php83-dom \ + php83-exif \ + php83-mysqli \ + php83-pecl-imagick \ + php83-simplexml \ + php83-tokenizer \ + php83-xml \ + php83-xmlwriter + +RUN apk add --no-cache php83-pear php83-dev gcc musl-dev make \ + && pecl83 install pcov && echo extension=pcov.so > /etc/php83/conf.d/pcov.ini \ + && apk del php83-pear php83-dev gcc musl-dev make + +# Create php symlink to php83 +RUN ln -sf /usr/bin/php83 /usr/bin/php + +RUN wget -nv -O /tmp/wordpress.tar.gz https://wordpress.org/wordpress-${WP_VERSION}.tar.gz \ + && mkdir /wordpress \ + && tar --strip-components=1 -zxmf /tmp/wordpress.tar.gz -C /wordpress \ + && rm /tmp/wordpress.tar.gz + +RUN wget -nv -O /tmp/wp-phpunit.tar.gz https://github.com/wp-phpunit/wp-phpunit/archive/${WP_VERSION}.0.tar.gz \ + && mkdir /wp-phpunit \ + && tar --strip-components=1 -zxmf /tmp/wp-phpunit.tar.gz -C /wp-phpunit \ + && rm /tmp/wp-phpunit.tar.gz + +RUN mysql_install_db --user=mysql --ldata=/var/lib/mysql +RUN sh -c 'mysqld_safe --datadir=/var/lib/mysql &' && sleep 4 && mysql -u root -e "CREATE DATABASE wordpress" + +ENV WP_DEVELOP_DIR=/wp-phpunit +ENV WP_PHPUNIT__TESTS_CONFIG=/wp-tests-config.php + +VOLUME ["/code"] +WORKDIR /code +COPY ./docker-entrypoint.sh /entrypoint.sh +COPY ./wp-tests-config.php /wp-tests-config.php +RUN chmod 755 /entrypoint.sh +ENTRYPOINT ["/entrypoint.sh"] \ No newline at end of file diff --git a/README.md b/README.md index de01f6e..daa4269 100644 --- a/README.md +++ b/README.md @@ -4,12 +4,28 @@ Simple Docker image for running unit tests for WordPress plugins. +**Supports multiple PHP versions:** 8.0, 8.1, 8.2, 8.3 + To run the tests for your plugin, run this in your plugin directory: ```sh docker run --rm -v "$PWD:/code" humanmade/plugin-tester ``` +You can also specify a specific WordPress and PHP version combination: + +```sh +docker run --rm -v "$PWD:/code" humanmade/plugin-tester:wp-6.8-php8.3 +``` + +Available tags follow the pattern `wp-{version}-php{version}`, e.g.: +- `humanmade/plugin-tester:wp-6.8-php8.3` +- `humanmade/plugin-tester:wp-6.7-php8.2` +- `humanmade/plugin-tester:wp-6.6-php8.1` +- etc. + +The `latest` tag uses the newest WordPress version with PHP 8.3. + You will need `phpunit/phpunit` specified as a Composer dependency of your plugin. Additional arguments can be passed to PHPUnit on the CLI directly, e.g.: ```sh