From 5bbe0538ab8ffb65c7c4616daabcee37a366249a Mon Sep 17 00:00:00 2001 From: Tyson Andre Date: Sun, 25 Sep 2022 08:23:59 -0400 Subject: [PATCH 1/2] Move validation test suite, phpstan to GitHub Workflows - Perform a shallow clone of submodules analyzed in validation test suite in GitHub workflows (should take around 30 seconds) - Switch badge in README.md to GitHub Workflows and update default branch for badge. - Remove travis config - After #385 is merged run_phpstan.sh can remove the separate install step (as a followup PR) - Require a newer phpunit patch version in devDependencies Make it harder for contributors to have any inconsistencies with CI when running tests (e.g. php version support, fixed phpunit bugs, etc) --- .dockerignore | 1 + .github/workflows/main.yml | 8 +++++++ .travis.yml | 44 ------------------------------------ README.md | 2 +- ci/run_phpstan.sh | 11 +++++++++ ci/run_phpstan_dockerized.sh | 17 ++++++++++++++ ci/run_tests.sh | 1 + ci/run_tests_dockerized.sh | 12 ++++------ 8 files changed, 44 insertions(+), 52 deletions(-) delete mode 100644 .travis.yml create mode 100755 ci/run_phpstan.sh create mode 100755 ci/run_phpstan_dockerized.sh diff --git a/.dockerignore b/.dockerignore index 7a62ba31..f536dcc9 100644 --- a/.dockerignore +++ b/.dockerignore @@ -13,4 +13,5 @@ tests/output **/.*.swp **/.*.swo **/Dockerfile +ci/*_dockerized.sh .dockerignore diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index edc2dd59..8453fe6a 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -27,6 +27,7 @@ jobs: # 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' + STATIC_ANALYSIS: true - PHP_VERSION: '7.3' - PHP_VERSION: '7.4' - PHP_VERSION: '8.0' @@ -38,6 +39,13 @@ jobs: # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - uses: actions/checkout@v2 + # Clone submodules + - name: Checkout submodules for validation tests + run: git submodule update --init --recursive --depth 1 + # Runs a single command using the runners shell - name: Build and test in docker run: bash ci/run_tests_dockerized.sh ${{ matrix.PHP_VERSION }} + + - name: Run static analysis (PHP 7.2 only) + run: if [[ "${{ matrix.STATIC_ANALYSIS }}" == true ]]; then bash ci/run_phpstan_dockerized.sh ${{ matrix.PHP_VERSION }}; fi diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 805aae5b..00000000 --- a/.travis.yml +++ /dev/null @@ -1,44 +0,0 @@ -language: php - -php: - - '7.2' - - '7.3' - - '7.4' - - '8.0' - - '8.1' - -env: - - VALIDATION=false - - VALIDATION=true - -os: - - linux - -matrix: - include: - - php: 7.2 - env: STATIC_ANALYSIS=true - fast_finish: true - -cache: - directories: - - validation/frameworks - -before_script: - - composer install - - set -e # Stop on first error. - - phpenv config-rm xdebug.ini || true - - if find . -name "*.php" -path "./src/*" -path "./experiments/*" -path "./tools/*" -path "./syntax-visualizer/server/src/*" -exec php -l {} 2>&1 \; | grep "syntax error, unexpected"; then exit 1; fi - - if find . -name "*.php" -path "./tests/*" -path "./validation/*" -maxdepth 0 --exec php -l {} 2>&1 \; | grep "syntax error, unexpected"; then exit 1; fi - -script: - - composer validate - - if [[ $STATIC_ANALYSIS = true ]]; then ./vendor/bin/phpstan analyse; fi - - | - if [[ $VALIDATION = true ]]; then - ./vendor/bin/phpunit --testsuite validation - else - ./vendor/bin/phpunit --testsuite invariants - ./vendor/bin/phpunit --testsuite grammar - ./vendor/bin/phpunit --testsuite api - fi diff --git a/README.md b/README.md index 60a18364..99940e52 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # Tolerant PHP Parser -[![Build Status](https://travis-ci.org/Microsoft/tolerant-php-parser.svg?branch=master)](https://travis-ci.org/Microsoft/tolerant-php-parser) +[![Build Status](https://github.com/microsoft/tolerant-php-parser/actions/workflows/main.yml/badge.svg?branch=main)](https://github.com/microsoft/tolerant-php-parser/actions/workflows/main.yml?query=branch%3Amain) This is an early-stage PHP parser designed, from the beginning, for IDE usage scenarios (see [Design Goals](#design-goals) for more details). There is still a ton of work to be done, so at this point, this repo mostly serves as diff --git a/ci/run_phpstan.sh b/ci/run_phpstan.sh new file mode 100755 index 00000000..9c92eb53 --- /dev/null +++ b/ci/run_phpstan.sh @@ -0,0 +1,11 @@ +#!/usr/bin/env bash +# -x Exit immediately if any command fails +# -e Echo all commands being executed. +# -u Fail for undefined variables +set -xeu +# This installs and runs phpstan +# TODO: Remove separate phpstan install step after https://github.com/microsoft/tolerant-php-parser/pull/385 is merged +if [ ! -d vendor/phpstan/phpstan ]; then + composer.phar require --dev phpstan/phpstan=^1.8 +fi +./vendor/bin/phpstan analyze diff --git a/ci/run_phpstan_dockerized.sh b/ci/run_phpstan_dockerized.sh new file mode 100755 index 00000000..747cb33a --- /dev/null +++ b/ci/run_phpstan_dockerized.sh @@ -0,0 +1,17 @@ +#!/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 to run phpstan (static analysis)" 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 + +# This is the same image name, Dockerfile and build arguments as ci/run_tests_dockerized.sh +DOCKER_IMAGE="tolerant-php-parser-test-runner:$PHP_VERSION" +docker build --build-arg="PHP_VERSION=$PHP_VERSION" --tag="$DOCKER_IMAGE" -f ci/Dockerfile . +docker run --rm $DOCKER_IMAGE ci/run_phpstan.sh diff --git a/ci/run_tests.sh b/ci/run_tests.sh index fdda534c..e4bcd15d 100755 --- a/ci/run_tests.sh +++ b/ci/run_tests.sh @@ -7,3 +7,4 @@ 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 +php -d short_open_tag=0 ./vendor/bin/phpunit --testsuite validation diff --git a/ci/run_tests_dockerized.sh b/ci/run_tests_dockerized.sh index e1ceee0f..23e3d162 100755 --- a/ci/run_tests_dockerized.sh +++ b/ci/run_tests_dockerized.sh @@ -11,12 +11,10 @@ fi # -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 +docker build --build-arg="PHP_VERSION=$PHP_VERSION" --tag="$DOCKER_IMAGE" -f ci/Dockerfile . +# Run all of the phpunit test suites in CI. +# - Add the validation folder as a read-only volume for running "phpunit --testsuite validation" +# (This is around 180MB, so it is not added to the docker image) +docker run --volume="$PWD/validation:/tolerant-php-parser/validation:ro" --rm $DOCKER_IMAGE ci/run_tests.sh From edc83529876fa9bed480ddbde2b5b700a7a5f17a Mon Sep 17 00:00:00 2001 From: Tyson Andre Date: Wed, 3 Jan 2024 10:39:32 -0500 Subject: [PATCH 2/2] Require a newer phpunit patch version in devDependencies --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 6f5e3e8c..3c67d39c 100644 --- a/composer.json +++ b/composer.json @@ -6,7 +6,7 @@ "php": ">=7.2" }, "require-dev": { - "phpunit/phpunit": "^8.5.15", + "phpunit/phpunit": "^8.5.36", "phpstan/phpstan": "^1.8" }, "license": "MIT",