Repository navigation
devops: move dresscode's config beside vendor, at the root its type rules found nothing and passed #238
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
devops: move dresscode's config beside vendor, at the root its type rules found nothing and passed #238
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
5c5dc8c
devops: move dresscode's config beside vendor, at the root its type r…
landsman 98eb1d3
devops: fail make dresscode when its type rules go silent, a clean ru…
landsman 6f80853
devops: check php in cli subfolders too, one would have been skipped …
landsman 00b74d3
devops: run the dresscode hook with the worktree's own install, it sk…
landsman 7cf86b5
devops: keep the deliberately bad dresscode file in tests, it had no …
landsman cab164c
devops: give dresscode's type rules phpstan.neon and check cli too, t…
landsman 54035b4
devops: say when the dresscode hook could not check a file, it looked…
landsman 933a030
devops: count dresscode's findings in a fixed format, github's own pr…
landsman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| # What dresscode's type rules read: it looks for this file only in its own root, app/. | ||
| includes: | ||
| - ../phpstan.neon |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| #!/bin/sh | ||
| # Runs dresscode over app/ and each PHP file in cli/, then again with a file that breaks a type rule | ||
| # in both. A clean run cannot tell a checked file from one dropped without a word, and the type rules | ||
| # go silent with exit 0 when dresscode.neon leaves app/. | ||
| # Usage: cli/dresscode.sh <frankenphp> | ||
| set -eu | ||
|
|
||
| frankenphp=$1 | ||
|
|
||
| run() { | ||
| find cli -name '*.php' -exec "$frankenphp" php-cli app/vendor/bin/dresscode check --jobs 1 -c app/dresscode.neon --no-color "$@" app {} + | ||
| } | ||
|
|
||
| if [ ! -f app/phpstan.neon ]; then | ||
| echo "app/phpstan.neon is missing: dresscode's type rules would run without phpstan.neon, and not say so" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| run | ||
|
|
||
| trap 'rm -f app/override-missing.php cli/override-missing.php' EXIT | ||
| # dash skips the EXIT trap on a signal unless the signal itself exits | ||
| trap 'exit 130' INT TERM | ||
| for file in app/override-missing.php cli/override-missing.php; do | ||
| cp tests/dresscode/override-missing.php "$file" | ||
| done | ||
|
|
||
| # A fixed format: under GitHub Actions the default one prints each finding twice. | ||
| output=$(run --format agent || true) | ||
| case $output in | ||
| *"the types go without it"*) | ||
| printf '%s\n' "$output" | ||
| echo "dresscode's type rules run without phpstan.neon" >&2 | ||
| exit 1 | ||
| ;; | ||
| esac | ||
| found=$(printf '%s\n' "$output" | grep -c upgrading.classes.Override || true) | ||
| if [ "$found" != 2 ]; then | ||
| printf '%s\n' "$output" | ||
| echo "dresscode's type rules went silent: reported tests/dresscode/override-missing.php $found times of 2, once from app/ and once from cli/" >&2 | ||
| exit 1 | ||
| fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| #!/bin/sh | ||
| # cli/dresscode-hook.php given a file in cli/ spelled through a symlink, as /tmp is on macOS: a plain | ||
| # comparison takes it for a file outside cli/ and skips it with exit 0. Run by `make qa`. | ||
| set -eu | ||
|
|
||
| root=$(cd "$(dirname "$0")/../.." && pwd) | ||
| dir=$(mktemp -d) | ||
| probe=$root/cli/hook-probe-$$.php | ||
| trap 'rm -rf "$dir" "$probe"' EXIT | ||
| ln -s "$root" "$dir/link" | ||
| cat > "$probe" <<'PHP' | ||
| <?php | ||
| declare(strict_types=1); | ||
| $a = array(); | ||
| PHP | ||
|
|
||
| printf '{"tool_input":{"file_path":"%s"}}' "$dir/link/cli/$(basename "$probe")" \ | ||
| | "$root/bin/frankenphp" php-cli "$root/cli/dresscode-hook.php" >/dev/null 2>&1 || true | ||
| if grep -q 'array()' "$probe"; then | ||
| echo "dresscode-hook skipped a file in cli/ reached through a symlink" >&2 | ||
| exit 1 | ||
| fi | ||
| echo "dresscode-hook ok" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| #!/bin/sh | ||
| # What cli/dresscode.sh would get wrong silently: passing when a type rule went quiet in app/ or cli/, | ||
| # or when phpstan.neon was not read, and leaving its bad files behind. Stubs dresscode. Run by `make qa`. | ||
| set -eu | ||
|
|
||
| script=$(cd "$(dirname "$0")/../.." && pwd)/cli/dresscode.sh | ||
| dir=$(mktemp -d) | ||
| trap 'rm -rf "$dir"' EXIT | ||
| cd "$dir" | ||
| mkdir -p app cli tests/dresscode | ||
| touch app/phpstan.neon cli/a.php tests/dresscode/override-missing.php | ||
| cat > stub <<'STUB' | ||
| #!/bin/sh | ||
| [ -e app/override-missing.php ] || exit "${CLEAN_EXIT:-0}" | ||
| printf '%b\n' "$REPORT" | ||
| exit 1 | ||
| STUB | ||
| chmod +x stub | ||
| rule=upgrading.classes.Override | ||
| failed=0 | ||
|
|
||
| check() { # <behaviour> <wanted exit> <report> [clean run's exit] | ||
| got=0 | ||
| REPORT=$3 CLEAN_EXIT=${4:-0} "$script" ./stub >/dev/null 2>&1 || got=$? | ||
| if [ "$got" = "$2" ] && [ ! -e app/override-missing.php ] && [ ! -e cli/override-missing.php ]; then | ||
| echo "ok $1" | ||
| else | ||
| echo "FAIL $1 (exit $got)" | ||
| failed=1 | ||
| fi | ||
| } | ||
|
|
||
| check "passes when both bad files are reported" 0 "$rule\n$rule" | ||
| check "fails when only one is reported" 1 "$rule" | ||
| check "fails when neither is" 1 "OK" | ||
| check "fails when phpstan.neon was not read" 1 "$rule\n$rule\nthe types go without it" | ||
| check "fails on a finding in the real code" 1 "" 3 | ||
|
|
||
| rm app/phpstan.neon | ||
| check "fails when app/phpstan.neon is gone" 1 "$rule\n$rule" | ||
| touch app/phpstan.neon | ||
|
|
||
| cat > stub <<'STUB' | ||
| #!/bin/sh | ||
| [ -e app/override-missing.php ] || exit 0 | ||
| touch started | ||
| sleep 1 | ||
| STUB | ||
| "$script" ./stub >/dev/null 2>&1 & | ||
| pid=$! | ||
| while [ ! -e started ]; do sleep 0.1; done | ||
| kill -TERM "$pid" | ||
| wait "$pid" || true | ||
| if [ -e app/override-missing.php ] || [ -e cli/override-missing.php ]; then | ||
| echo "FAIL an interrupted run removes its bad files" | ||
| failed=1 | ||
| else | ||
| echo "ok an interrupted run removes its bad files" | ||
| fi | ||
| exit "$failed" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| <?php | ||
| declare(strict_types=1); | ||
|
|
||
| // Breaks upgrading.classes.Override on purpose: `make dresscode` fails unless it is reported, because | ||
| // a rule that needs types can go silent and still exit 0. | ||
|
|
||
| class OverrideMissingParent { | ||
| function method(): void { | ||
| } | ||
| } | ||
|
|
||
| class OverrideMissingChild extends OverrideMissingParent { | ||
| function method(): void { | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.