From 58ec8af2c30fc82deb1afe3a785f9332cf97b600 Mon Sep 17 00:00:00 2001 From: Glomberg Date: Fri, 20 Sep 2024 11:00:56 +0300 Subject: [PATCH] New. Code. Auto tests implemented. --- .github/workflows/releaseNotice.yml | 23 +++++++++++++ .github/workflows/reviewNotice.yml | 27 +++++++++++++++ .github/workflows/tests.yml | 53 +++++++++++++++++++++++++++++ .gitignore | 9 ++++- composer.json | 22 ++++++++++++ tests/.phpcs.xml | 27 +++++++++++++++ tests/bootstrap.php | 1 + tests/phpunit.xml | 17 +++++++++ tests/psalm.xml | 22 ++++++++++++ 9 files changed, 200 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/releaseNotice.yml create mode 100644 .github/workflows/reviewNotice.yml create mode 100644 .github/workflows/tests.yml create mode 100644 composer.json create mode 100644 tests/.phpcs.xml create mode 100644 tests/bootstrap.php create mode 100644 tests/phpunit.xml create mode 100644 tests/psalm.xml diff --git a/.github/workflows/releaseNotice.yml b/.github/workflows/releaseNotice.yml new file mode 100644 index 0000000..46abd80 --- /dev/null +++ b/.github/workflows/releaseNotice.yml @@ -0,0 +1,23 @@ +name: Notice about releases via Telegram + +on: + release: + types: [published] + +jobs: + + build: + runs-on: ubuntu-latest + steps: + - name: send telegram message on release + uses: appleboy/telegram-action@master + with: + to: ${{ secrets.TELEGRAM_TO }} + token: ${{ secrets.TELEGRAM_TOKEN }} + message: | + ${{ github.event.repository.description }} v${{github.event.release.name}} released + ${{github.event.release.html_url}} + + ${{ github.event.release.body }} + format: html + disable_web_page_preview: true \ No newline at end of file diff --git a/.github/workflows/reviewNotice.yml b/.github/workflows/reviewNotice.yml new file mode 100644 index 0000000..d29c9ad --- /dev/null +++ b/.github/workflows/reviewNotice.yml @@ -0,0 +1,27 @@ +name: Notice about review approved via Telegram + +on: + pull_request_review: + types: [ submitted ] + +jobs: + + build: + if: github.event.review.state == 'approved' && toJSON(github.event.pull_request.requested_reviewers) == '[]' + runs-on: ubuntu-latest + steps: + - name: Convert date format + id: date + run: echo "::set-output name=date::$(date -d "${{ github.event.pull_request.created_at }}" +"%Y-%m-%d")" + - name: Send telegram message on review approved + uses: appleboy/telegram-action@master + with: + to: ${{ secrets.TELEGRAM_PLUGINS_TO }} + token: ${{ secrets.TELEGRAM_REVIEWER_TOKEN }} + message: | + 💥🎉🎉🎉💥 Pull-request ${{ github.event.pull_request.title }} + submitted by ${{ github.event.pull_request.user.login }} at ${{ steps.date.outputs.date }} + + was approved and is ready to merge ➡️ !!! + format: html + disable_web_page_preview: true \ No newline at end of file diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..44daf25 --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,53 @@ +name: PHPUnit, PHPCS, Psalm + +on: # event list + push: # on push to each of these branches + branches: + - dev + - fix + - master + pull_request: + branches: + - dev + - master + +env: # environment variables (available in any part of the action) + PHP_VERSION: 7.4 + +jobs: + build: + name: PHPUnit, PHPCS, Psalm + runs-on: ubuntu-latest + env: + DB_CONNECTION: mysql + DB_HOST: localhost + DB_PORT: 3306 + DB_DATABASE: wordpress_test + DB_USERNAME: root + DB_PASSWORD: root + + steps: + - name: Set up PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ env.PHP_VERSION }} + + - name: Run MySQL server + run: sudo systemctl start mysql + + - name: Code Checkout + uses: actions/checkout@v4 + + - name: Make the script files executable + run: chmod +x ./tests/wp-test-setup.sh + + - name: Install WP develop + run: ./tests/wp-test-setup.sh wordpress_test root root localhost latest + + - name: Install Dependencies + run: composer i + + - name: Running tests + env: + CLEANTALK_TEST_API_KEY: ${{ secrets.CLEANTALK_TEST_API_KEY }} + run: composer test \ No newline at end of file diff --git a/.gitignore b/.gitignore index 60ad722..3d39e56 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,11 @@ * !README.md !Antispam/ -!Antispam/* \ No newline at end of file +!Antispam/* +!.github/ +!.github/* +!.github/workflows/ +!.github/workflows/* +!composer.json +!tests/ +!tests/** \ No newline at end of file diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..343a8db --- /dev/null +++ b/composer.json @@ -0,0 +1,22 @@ +{ + "require-dev": { + "vimeo/psalm": "^4.8", + "phpunit/phpunit": "^7.5", + "squizlabs/php_codesniffer": "3.*", + "phpcompatibility/php-compatibility": "@dev" + }, + "scripts": { + "test": [ + "vendor/bin/phpunit --configuration tests/phpunit.xml", + "vendor/bin/phpcs --config-set installed_paths vendor/phpcompatibility/php-compatibility", + "vendor/bin/phpcs --standard=tests/.phpcs.xml", + "vendor/bin/psalm --no-cache --config=tests/psalm.xml", + "vendor/bin/psalm --no-cache --config=tests/psalm.xml --taint-analysis" + ] + }, + "config": { + "allow-plugins": { + "dealerdirect/phpcodesniffer-composer-installer": true + } + } +} diff --git a/tests/.phpcs.xml b/tests/.phpcs.xml new file mode 100644 index 0000000..58c25b8 --- /dev/null +++ b/tests/.phpcs.xml @@ -0,0 +1,27 @@ + + + Sniff code to check different PHP compatibility + + + ../Antispam + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tests/bootstrap.php b/tests/bootstrap.php new file mode 100644 index 0000000..b3d9bbc --- /dev/null +++ b/tests/bootstrap.php @@ -0,0 +1 @@ + + + + + ./ + ./bootstrap.php + + + diff --git a/tests/psalm.xml b/tests/psalm.xml new file mode 100644 index 0000000..60adba1 --- /dev/null +++ b/tests/psalm.xml @@ -0,0 +1,22 @@ + + + + + + \ No newline at end of file