diff --git a/.github/workflows/php-unit-tests.yml b/.github/workflows/php-unit-tests.yml index 9ab561f2..89eb1ad4 100644 --- a/.github/workflows/php-unit-tests.yml +++ b/.github/workflows/php-unit-tests.yml @@ -20,7 +20,7 @@ # +-------------------------------------------------------------------------+ -name: PHP Unit Tests +name: Pest Tests on: push: @@ -41,7 +41,7 @@ concurrency: jobs: unit-test: - name: PHPUnit on PHP 8.1 (Docker) + name: Pest using Cacti Composer (Docker) runs-on: ubuntu-latest steps: @@ -51,25 +51,49 @@ jobs: # patch-coverage.php diffs against the base branch. fetch-depth: 0 - # The image is the same one developers run locally via - # `composer test:docker`, so a green run here is reproducible off-CI. - - name: Build test image - run: docker build --tag cacti-thold-test:php8.1 --file tests/docker/Dockerfile tests/docker + - name: Checkout Cacti 1.2.31 runtime + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + repository: Cacti/cacti + # Commit behind the annotated release/1.2.31 tag. + ref: 1e8eaca26b84b128c39ce8cc8ece42d7ff76aac1 + path: cacti-runtime - - name: Validate composer.json - run: docker run --rm --volume "$PWD":/cacti/plugins/thold cacti-thold-test:php8.1 composer validate --strict --no-check-lock + - name: Checkout Cacti test toolchain + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + repository: Cacti/cacti + # Pin Composer, Pest, the lock file, and Cacti's Docker test image. + ref: 298bd51eca843490fb90b27ada6b3fecc9b9a7d8 + path: cacti-toolchain - - name: Install dependencies - run: docker run --rm --volume "$PWD":/cacti/plugins/thold cacti-thold-test:php8.1 composer install --no-progress --no-ansi + # Build the same Linux image used by Cacti's tests/tools/docker_pest.sh. + # Composer installs and executes Cacti's locked Pest toolchain in /work; + # Thold contributes no parallel vendor directory or PHPUnit dependency. + - name: Build Cacti test image + run: | + docker build --tag cacti-web --file cacti-toolchain/docker/Dockerfile cacti-toolchain/docker + docker build --tag cacti-thold-test --file cacti-toolchain/docker/Dockerfile.test cacti-toolchain - # Same scripts a developer runs locally, and the same names Cacti core uses. - name: Lint every PHP source file - run: docker run --rm --volume "$PWD":/cacti/plugins/thold cacti-thold-test:php8.1 composer lint + run: | + docker run --rm --volume "$PWD":/work/plugins/thold \ + --env COMPOSER_ROOT_VERSION=1.3.0-dev \ + --entrypoint composer cacti-thold-test \ + run-script lint /work/plugins/thold - - name: Run unit tests with coverage + - name: Run Pest with coverage run: | - docker run --rm --volume "$PWD":/cacti/plugins/thold cacti-thold-test:php8.1 \ - composer test:coverage + docker run --rm \ + --volume "$PWD/cacti-runtime":/cacti \ + --volume "$PWD":/cacti/plugins/thold \ + --env COMPOSER_ROOT_VERSION=1.3.0-dev \ + --env XDEBUG_MODE=coverage \ + --user root \ + --entrypoint composer cacti-thold-test \ + test -- --configuration=/cacti/plugins/thold/phpunit.xml \ + --coverage-clover=/cacti/plugins/thold/coverage/clover.xml \ + /cacti/plugins/thold/tests/Unit # Whole-file coverage is meaningless here: most of the plugin only runs # inside a live Cacti. What is enforceable is that a change covers the @@ -77,11 +101,11 @@ jobs: - name: Enforce coverage of changed lines if: github.event_name == 'pull_request' env: - BASE_REF: origin/${{ github.base_ref }} + BASE_REF: ${{ github.event.pull_request.base.sha }} run: | - docker run --rm --volume "$PWD":/cacti/plugins/thold --env BASE_REF \ - cacti-thold-test:php8.1 \ - sh -c 'git config --global --add safe.directory /cacti/plugins/thold && php tests/bin/patch-coverage.php coverage/clover.xml "$BASE_REF" 100' + docker run --rm --volume "$PWD":/plugin --workdir /plugin \ + --env BASE_REF --user root --entrypoint sh cacti-thold-test \ + -c 'git config --global --add safe.directory /plugin && php tests/bin/patch-coverage.php coverage/clover.xml "$BASE_REF" 100' - name: Upload coverage report if: always() diff --git a/.github/workflows/plugin-ci-workflow.yml b/.github/workflows/plugin-ci-workflow.yml index aea428fe..5e4f3db6 100644 --- a/.github/workflows/plugin-ci-workflow.yml +++ b/.github/workflows/plugin-ci-workflow.yml @@ -35,11 +35,21 @@ jobs: integration-test: runs-on: ${{ matrix.os }} + # A failure against the pinned release is a real failure. The develop entry + # is advisory: it is how a core regression becomes visible here, but it must + # not turn the plugin's own pull requests red. + continue-on-error: ${{ matrix.cacti != 'release/1.2.31' }} + strategy: fail-fast: false matrix: php: ['8.1', '8.2', '8.3', '8.4'] os: [ubuntu-latest] + cacti: ['release/1.2.31'] + include: + - php: '8.4' + os: ubuntu-latest + cacti: 'develop' services: mariadb: @@ -57,13 +67,14 @@ jobs: --health-timeout=5s --health-retries=3 - name: PHP ${{ matrix.php }} Integration Test on ${{ matrix.os }} + name: PHP ${{ matrix.php }} Integration Test on ${{ matrix.os }} against Cacti ${{ matrix.cacti }} steps: - name: Checkout Cacti uses: actions/checkout@v7 with: repository: Cacti/cacti + ref: ${{ matrix.cacti }} path: cacti - name: Checkout Thold Plugin @@ -190,18 +201,34 @@ jobs: fi - name: Remove the plugins directory exclusion from the .phpstan.neon - run: sed '/plugins/d' -i .phpstan.neon + run: | + if [ -f .phpstan.neon ]; then + sed -i '/plugins/d' .phpstan.neon + fi working-directory: ${{ github.workspace }}/cacti - name: Mark composer scripts executable - run: sudo chmod +x ${{ github.workspace }}/cacti/include/vendor/bin/* + run: | + if [ -d "${{ github.workspace }}/cacti/include/vendor/bin" ]; then + sudo find "${{ github.workspace }}/cacti/include/vendor/bin" -maxdepth 1 -type f -exec chmod +x {} + + fi - name: Run Linter on base code - run: composer run-script lint ${{ github.workspace }}/cacti/plugins/thold + run: | + if composer --no-ansi run-script --list | grep -qE '^[[:space:]]+lint([[:space:]]|$)'; then + composer run-script lint ${{ github.workspace }}/cacti/plugins/thold + else + echo 'Composer lint script is not defined; skipping.' + fi working-directory: ${{ github.workspace }}/cacti - name: Checking coding standards on base code - run: composer run-script phpcsfixer ${{ github.workspace }}/cacti/plugins/thold + run: | + if composer --no-ansi run-script --list | grep -qE '^[[:space:]]+phpcsfixer([[:space:]]|$)'; then + composer run-script phpcsfixer ${{ github.workspace }}/cacti/plugins/thold + else + echo 'Composer phpcsfixer script is not defined; skipping.' + fi working-directory: ${{ github.workspace }}/cacti # - name: Run PHPStan at Level 6 on base code outside of Composer due to technical issues diff --git a/.gitignore b/.gitignore index 0806dc45..e2e016a6 100644 --- a/.gitignore +++ b/.gitignore @@ -21,9 +21,6 @@ locales/po/*.mo -/vendor/ -/composer.lock /.phpunit.cache/ /coverage/ -/coverage/ /.phpunit.result.cache diff --git a/composer.json b/composer.json deleted file mode 100644 index 94aead2f..00000000 --- a/composer.json +++ /dev/null @@ -1,49 +0,0 @@ -{ - "_comment": [ - "+-------------------------------------------------------------------------+", - "| Copyright (C) 2004-2026 The Cacti Group |", - "| |", - "| This program is free software; you can redistribute it and/or |", - "| modify it under the terms of the GNU General Public License |", - "| as published by the Free Software Foundation; either version 2 |", - "| of the License, or (at your option) any later version. |", - "| |", - "| This program is distributed in the hope that it will be useful, |", - "| but WITHOUT ANY WARRANTY; without even the implied warranty of |", - "| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |", - "| GNU General Public License for more details. |", - "+-------------------------------------------------------------------------+", - "| Cacti: The Complete RRDtool-based Graphing Solution |", - "+-------------------------------------------------------------------------+", - "| http://www.cacti.net/ |", - "+-------------------------------------------------------------------------+" - ], - "name": "cacti/plugin-thold", - "description": "Thold Plugin for Cacti", - "type": "project", - "license": "GPL-2.0-only", - "require-dev": { - "overtrue/phplint": "^9.6", - "phpunit/phpunit": "^10.5.64" - }, - "scripts": { - "lint": "phplint --no-cache --exclude=vendor ", - "test": "phpunit --display-warnings", - "test:coverage": "phpunit --display-warnings --coverage-clover=coverage/clover.xml", - "test:docker": "docker compose -f tests/docker/docker-compose.yml run --rm phpunit" - }, - "config": { - "sort-packages": true, - "vendor-dir": "vendor", - "platform": { - "php": "8.1.0" - }, - "platform-check": true - }, - "autoload-dev": { - "classmap": [ - "tests/Helpers/", - "tests/TestCase.php" - ] - } -} diff --git a/phpunit.xml b/phpunit.xml index 46a8d9a8..b68405ad 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,6 +1,6 @@