diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..7a62ba31 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,16 @@ +.git/ +.github/ +validation/ +vendor/ +docs/ +tools/ +**/.DS_Store +**/.idea +**/composer.lock +tests/output +.phpunit.result.cache +**/*.ast +**/.*.swp +**/.*.swo +**/Dockerfile +.dockerignore diff --git a/.gitattributes b/.gitattributes index b9ab85aa..b3326bf5 100644 --- a/.gitattributes +++ b/.gitattributes @@ -3,6 +3,7 @@ /tests/cases/**/*.php text eol=lf /.vscode export-ignore +/ci export-ignore /docs export-ignore /experiments export-ignore /php-langspec export-ignore @@ -17,3 +18,4 @@ /Contributing.md export-ignore /README.md export-ignore /phpunit.xml export-ignore +/.dockerignore export-ignore diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 00000000..edc2dd59 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,43 @@ +# Runs tolerant-php-parser's tests +name: CI + +# Controls when the action will run. +on: + # Triggers the workflow on push or pull request events but only for the main branch + push: + branches: [ main ] + pull_request: + branches: [ main ] + + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +# A workflow run is made up of one or more jobs that can run sequentially or in parallel +jobs: + # This workflow contains a single job called "build" + build: + # The type of runner that the job will run on + runs-on: ubuntu-latest + + # See https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#using-environment-variables-in-a-matrix + strategy: + fail-fast: false + matrix: + include: + # NOTE: If this is not quoted, the yaml parser will convert numbers such as 8.0 to the number 8, + # and the docker image `php:8` is the latest minor version of php 8.x (8.1). + - PHP_VERSION: '7.2' + - PHP_VERSION: '7.3' + - PHP_VERSION: '7.4' + - PHP_VERSION: '8.0' + - PHP_VERSION: '8.1' + - PHP_VERSION: '8.2.0beta2' + + # Steps represent a sequence of tasks that will be executed as part of the job + steps: + # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it + - uses: actions/checkout@v2 + + # Runs a single command using the runners shell + - name: Build and test in docker + run: bash ci/run_tests_dockerized.sh ${{ matrix.PHP_VERSION }} diff --git a/.gitignore b/.gitignore index b38b0286..f40bc934 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ tests/output *.ast .*.swp .*.swo +.phpunit.result.cache diff --git a/ci/Dockerfile b/ci/Dockerfile new file mode 100644 index 00000000..2949d56e --- /dev/null +++ b/ci/Dockerfile @@ -0,0 +1,12 @@ +ARG PHP_VERSION +FROM php:$PHP_VERSION +RUN curl https://getcomposer.org/download/latest-2.x/composer.phar -o /usr/bin/composer.phar && chmod a+x /usr/bin/composer.phar +WORKDIR /tolerant-php-parser +RUN apt-get update && apt-get install -y unzip && apt-get clean +ARG COMPOSER_OPTIONS +ENV COMPOSER_OPTIONS=$COMPOSER_OPTIONS + +ADD composer.json ./ +RUN composer.phar install $COMPOSER_OPTIONS && composer.phar clear-cache + +ADD . . diff --git a/ci/run_tests.sh b/ci/run_tests.sh new file mode 100755 index 00000000..fdda534c --- /dev/null +++ b/ci/run_tests.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env bash +# This runs the tests that have been set up in GitHub Workflows so far + +# -x Exit immediately if any command fails +# -e Echo all commands being executed. +set -xe +php -d short_open_tag=0 ./vendor/bin/phpunit --testsuite invariants +php -d short_open_tag=0 ./vendor/bin/phpunit --testsuite grammar +php -d short_open_tag=0 ./vendor/bin/phpunit --testsuite api diff --git a/ci/run_tests_dockerized.sh b/ci/run_tests_dockerized.sh new file mode 100755 index 00000000..e1ceee0f --- /dev/null +++ b/ci/run_tests_dockerized.sh @@ -0,0 +1,22 @@ +#!/usr/bin/env bash +if [ $# != 1 ]; then + echo "Usage: $0 PHP_VERSION" 1>&2 + echo "e.g. $0 8.0" 1>&2 + echo "The PHP_VERSION is the version of the php docker image to use" 1>&2 + echo "This runs the tests that have been set up in GitHub Workflows so far" 1>&2 + exit 1 +fi +# -x Exit immediately if any command fails +# -e Echo all commands being executed. +# -u fail for undefined variables +set -xeu +PHP_VERSION=$1 +COMPOSER_OPTIONS="" +# lexicographic comparison +if [ "$PHP_VERSION" > "8.1" ]; then + COMPOSER_OPTIONS="--ignore-platform-reqs" +fi + +DOCKER_IMAGE="tolerant-php-parser-test-runner:$PHP_VERSION" +docker build --build-arg="PHP_VERSION=$PHP_VERSION" --build-arg="COMPOSER_OPTIONS=$COMPOSER_OPTIONS" --tag="$DOCKER_IMAGE" -f ci/Dockerfile . +docker run --rm $DOCKER_IMAGE ci/run_tests.sh