Skip to content
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

Fix/pre commit #325

Merged
merged 8 commits into from
Feb 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,7 @@ ij_json_wrap_long_lines = false

[{*.htm,*.html,*.sht,*.shtm,*.shtml}]
ij_html_add_new_line_before_tags = body,div,p,form,h1,h2,h3
ij_html_align_attributes = true
ij_html_align_attributes = false
ij_html_align_text = false
ij_html_attribute_wrap = normal
ij_html_block_comment_add_space = false
Expand Down
13 changes: 11 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,22 @@ repos:
- id: coding-standard-fixer
name: PHP and WordPress coding standards Fixer test
language: system
entry: ./bin/coding-standard-fixer.sh
pass_filenames: false
entry: task lint:fix
stages: [ pre-commit ]

- id: coding-standard
name: Check the PHP and WordPress coding standards
language: system
entry: ./bin/coding-standard.sh
pass_filenames: false
entry: task lint
stages: [ pre-commit ]

- id: php-compatibility
name: Check the PHP compatibility
language: system
pass_filenames: false
entry: task php-compatibility
stages: [ pre-commit ]

# - repo: https://github.com/returntocorp/semgrep
Expand Down
52 changes: 31 additions & 21 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,40 +18,50 @@ tasks:
cmds:
- docker compose build --build-arg UID="$(id -u)" php5-6

test:
desc: Run tests
deps:
- build:test
cmds:
- docker compose run --rm test
- docker compose down --remove-orphans

pre-commit:install:
desc: Install pre-commit hooks
lint:build:
desc: Build lint container (php-cs-fixer)
cmds:
- pre-commit install --hook-type commit-msg
- pre-commit install
- docker build -t lint:wc -f lint.Dockerfile .

lint:
desc: Run linter
desc: Run lint container
deps:
- build:php5-6
- lint:build
cmds:
- docker compose run --rm php5-6 php ./vendor/bin/phpcs --standard=phpcs.xml ./
- ./bin/lint.sh

lint:fix:
desc: Run linter with autofix
desc: Run lint container
deps:
- build:php5-6
- lint:build
cmds:
- ./bin/lint-fix.sh

php-compatibility:build:
desc: Build php-compatibility container (phpcs)
cmds:
- docker compose run --rm php5-6 php ./vendor/bin/phpcbf --standard=phpcs.xml ./
- docker build -t php-compatibility:wc -f lint.Dockerfile .

php-compatibility:
desc: Check compatibility code
desc: Check compatibility code in PHP-CS container
deps:
- build:php5-6
- php-compatibility:build
cmds:
- ./bin/php-compatibility.sh

test:
desc: Run tests
deps:
- build:test
cmds:
- docker compose run --rm php5-6 php ./vendor/bin/phpcs -d memory_limit=512M -p ./ --standard=PHPCompatibility -s --runtime-set testVersion 5.6-8.1 --ignore='*/vendor/*,build/*'
- docker compose run --rm test
- docker compose down --remove-orphans

pre-commit:install:
desc: Install pre-commit hooks
cmds:
- pre-commit install --hook-type commit-msg
- pre-commit install

dist:
desc: Build zip file
Expand Down
2 changes: 2 additions & 0 deletions alma-gateway-for-woocommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@
* @return Alma\Woocommerce\AlmaPlugin
* @noinspection PhpIncludeInspection
*/


function alma_plugin() {
static $plugin;

Expand Down
7 changes: 0 additions & 7 deletions bin/coding-standard-fixer.sh

This file was deleted.

7 changes: 0 additions & 7 deletions bin/coding-standard.sh

This file was deleted.

8 changes: 8 additions & 0 deletions bin/lint-fix.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash
docker run --rm -v "$(pwd):/app" -w /app lint:wc -v --standard=phpcs.xml ./
EXIT_CODE=$?

if [[ $EXIT_CODE -ne 0 ]]; then
echo "Fix the errors with PHPcbf automatic fixer before commit!"
exit 1
fi
8 changes: 8 additions & 0 deletions bin/lint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash
docker run --rm -v "$(pwd):/app" -w /app lint:wc -v --standard=phpcs.xml ./
EXIT_CODE=$?

if [[ $EXIT_CODE -ne 0 ]]; then
echo "Fix the errors before commit!"
exit 1
fi
9 changes: 9 additions & 0 deletions bin/php-compatibility.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash
docker run --rm -v "$(pwd):/app" -v "$(pwd)/.php_cs.cache:/app/.php_cs.cache" --entrypoint /composer/vendor/bin/phpcs \
php-compatibility:wc -p . --standard=PHPCompatibility -s --runtime-set testVersion 5.6-8.4 --ignore=\*/vendor/\*,build/*,node_modules/*,coverage/*
EXIT_CODE=$?

if [[ $EXIT_CODE -ne 0 ]]; then
echo "Check PHP code compatibility before commit!"
exit 1
fi
2 changes: 1 addition & 1 deletion compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ services:
php5-6:
build:
context: ./
dockerfile: Dockerfile.legacy
dockerfile: legacy.Dockerfile
volumes:
- ./:/home/phpuser
- /home/phpuser/src/vendor # do not mount vendor inside container
Expand Down
20 changes: 20 additions & 0 deletions dockerfile.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Dockerfiles

## Dockerfile

Used to run the tests with the command

```task test```

*Tests need MySQL to run. The MySQL container is started by the `docker-compose.yml` file.*

## Legacy Dockerfile

Used to build the ZIP file to release the plugin.

## PHPCS Dockerfile

Used to run the `lint` and `lint:fix` command by the pre-commit hook or manually with the command

```task lint```
```task lint:fix```
Loading