From d5c043e8467881c00b2cd836f2f37b8479cf0b96 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sun, 31 Jul 2022 11:13:17 +0300 Subject: [PATCH] rework phpstan task to use inotifywait --- .vscode/tasks.json | 21 +++------------------ utils/phpstan-watcher.sh | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 18 deletions(-) create mode 100644 utils/phpstan-watcher.sh diff --git a/.vscode/tasks.json b/.vscode/tasks.json index a5aa65f30..0039fef88 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -3,11 +3,11 @@ "tasks": [ { "type": "shell", - "label": "phpstan-8.1 (background)", + "label": "phpstan 8.1 (watcher)", "isBackground": true, "problemMatcher": { "fileLocation": ["relative", "${workspaceRoot}"], - "owner": "phpstan-8.1", + "owner": "phpstan-watcher-8.1", "pattern": { "regexp": "^/app/(.*?):([0-9\\?]*):(.*)$", "file": 1, @@ -21,22 +21,7 @@ } }, - "command": "while true; do docker run --rm -v $(pwd):/app -v /tmp/phpstan-8.1:/tmp/phpstan --workdir /app php:8.1-cli php -d memory_limit=-1 ./vendor/bin/phpstan --memory-limit=2G --error-format=raw || true; echo 'All done'; sleep 30; done", - }, - { - "type": "shell", - "label": "phpstan-8.0 (run once)", - "problemMatcher": { - "fileLocation": ["relative", "${workspaceRoot}"], - "owner": "phpstan-8.0", - "pattern": { - "regexp": "^/app/(.*?):([0-9\\?]*):(.*)$", - "file": 1, - "line": 2, - "message": 3 - } - }, - "command": "docker run --rm -v $(pwd):/app -v /tmp/phpstan-8.0:/tmp/phpstan --workdir /app php:8.0-cli php -d memory_limit=-1 ./vendor/bin/phpstan --memory-limit=2G --error-format=raw || true", + "command": "${workspaceRoot}/utils/phpstan-watcher.sh", }, { "type": "gulp", diff --git a/utils/phpstan-watcher.sh b/utils/phpstan-watcher.sh new file mode 100644 index 000000000..d1acc906f --- /dev/null +++ b/utils/phpstan-watcher.sh @@ -0,0 +1,18 @@ +#!/bin/sh + +PHP_VERSION="$1" + +[ -z "$PHP_VERSION" ] && PHP_VERSION=8.1 + +echo PHP_VERSION: ${PHP_VERSION} +echo PWD: $(pwd) + +while true; do + inotifywait . -e close_write -r -t 300 | grep -q .php && \ + ( + docker run --rm -v $(pwd):/app -v /tmp/phpstan-8.1:/tmp/phpstan \ + --workdir /app php:${PHP_VERSION}-cli php -d memory_limit=-1 ./vendor/bin/phpstan --memory-limit=2G --error-format=raw + echo All done, RC=$?. + ) + sleep 1 +done