From edbe8bd18a525e39b0705c895aa6b35363cbaa25 Mon Sep 17 00:00:00 2001 From: Thomas Vincent Date: Sun, 16 Aug 2026 15:58:17 -0700 Subject: [PATCH 01/10] ci: add the plugin integration workflow, CodeQL and Dependabot Matches the workflow the other Cacti plugins carry, plus a PHP 8.0 syntax job at the floor the INFO compat implies. Signed-off-by: Thomas Vincent --- .github/workflows/codeql.yml | 59 +++++ .github/workflows/plugin-ci-workflow.yml | 269 +++++++++++++++++++++++ 2 files changed, 328 insertions(+) create mode 100644 .github/workflows/codeql.yml create mode 100644 .github/workflows/plugin-ci-workflow.yml diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml new file mode 100644 index 0000000..d5e4120 --- /dev/null +++ b/.github/workflows/codeql.yml @@ -0,0 +1,59 @@ +# +-------------------------------------------------------------------------+ +# | Copyright (C) 2004-2026 The Cacti Group | +# +-------------------------------------------------------------------------+ +# | Cacti: The Complete RRDtool-based Graphing Solution | +# +-------------------------------------------------------------------------+ +# | http://www.cacti.net/ | +# +-------------------------------------------------------------------------+ +# +# CodeQL has no PHP analysis, so this covers js/GPSMaps.js only. The PHP is +# covered by the syntax and integration jobs in plugin-ci-workflow.yml. + +name: "CodeQL" + +on: + push: + branches: [main, develop] + paths-ignore: + - "**/*.md" + pull_request: + branches: [main, develop] + paths-ignore: + - "**/*.md" + schedule: + - cron: "30 1 * * 1" + workflow_dispatch: + +concurrency: + group: codeql-${{ github.ref }} + cancel-in-progress: true + +permissions: + contents: read + +jobs: + analyze: + name: Analyze + runs-on: ubuntu-latest + timeout-minutes: 15 + permissions: + actions: read + contents: read + security-events: write + strategy: + fail-fast: false + matrix: + language: ["javascript-typescript"] + steps: + - name: Checkout repository + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 + - name: Initialize CodeQL + uses: github/codeql-action/init@b56ba49b26e50535fa1e7f7db0f4f7b4bf65d80d # v3 + with: + languages: ${{ matrix.language }} + - name: Autobuild + uses: github/codeql-action/autobuild@b56ba49b26e50535fa1e7f7db0f4f7b4bf65d80d # v3 + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@b56ba49b26e50535fa1e7f7db0f4f7b4bf65d80d # v3 + with: + category: "/language:${{ matrix.language }}" diff --git a/.github/workflows/plugin-ci-workflow.yml b/.github/workflows/plugin-ci-workflow.yml new file mode 100644 index 0000000..7131b11 --- /dev/null +++ b/.github/workflows/plugin-ci-workflow.yml @@ -0,0 +1,269 @@ +# +-------------------------------------------------------------------------+ +# | Copyright (C) 2004-2026 The Cacti Group | +# +-------------------------------------------------------------------------+ +# | Cacti: The Complete RRDtool-based Graphing Solution | +# +-------------------------------------------------------------------------+ +# | http://www.cacti.net/ | +# +-------------------------------------------------------------------------+ + +name: Plugin Integration Tests + +on: + push: + branches: + - main + - develop + pull_request: + branches: + - main + - develop + +permissions: + contents: read + +jobs: + # The INFO compat value implies a Cacti 1.2.x install, which requires PHP + # 8.0. Linting at that floor catches syntax the declared minimum cannot run, + # which the integration matrix below would miss. + syntax-floor: + name: PHP 8.0 syntax floor + runs-on: ubuntu-latest + steps: + - name: Checkout gpsmap Plugin + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 + + - name: Install PHP 8.0 + uses: shivammathur/setup-php@cf4cade2721270509d5b1c766ab3549210a39a2a # v2 + with: + php-version: '8.0' + + - name: Lint every PHP file + run: | + if find . -path ./vendor -prune -o -name '*.php' -print \ + | xargs -n1 php -l 2>&1 | grep -iv 'no syntax errors detected'; then + echo "Syntax errors found at the declared PHP floor" + exit 1 + fi + + unit-test: + name: Standalone test suite + runs-on: ubuntu-latest + steps: + - name: Checkout gpsmap Plugin + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 + + - name: Install PHP + uses: shivammathur/setup-php@cf4cade2721270509d5b1c766ab3549210a39a2a # v2 + with: + php-version: '8.1' + coverage: xdebug + + # Guarded so this workflow can land ahead of the suite it runs. + - name: Run the suite + run: | + if [ -f tests/run.php ]; then + php tests/run.php + else + echo "tests/run.php not present on this branch, skipping" + fi + + - name: Enforce the coverage gate + env: + XDEBUG_MODE: coverage + run: | + if [ -f tests/coverage.php ]; then + php tests/coverage.php + else + echo "tests/coverage.php not present on this branch, skipping" + fi + + integration-test: + runs-on: ${{ matrix.os }} + + strategy: + fail-fast: false + matrix: + php: ['8.1', '8.2', '8.3'] + os: [ubuntu-latest] + + services: + mysql: + image: mysql:8.0 + env: + MYSQL_ROOT_PASSWORD: cactiroot + MYSQL_DATABASE: cacti + MYSQL_USER: cactiuser + MYSQL_PASSWORD: cactiuser + ports: + - 3306:3306 + options: >- + --health-cmd="mysqladmin ping" + --health-interval=10s + --health-timeout=5s + --health-retries=3 + + name: PHP ${{ matrix.php }} Integration Test on ${{ matrix.os }} + + steps: + - name: Checkout Cacti + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 + with: + repository: Cacti/cacti + path: cacti + + - name: Checkout gpsmap Plugin + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 + with: + path: cacti/plugins/gpsmap + + - name: Install PHP ${{ matrix.php }} + uses: shivammathur/setup-php@cf4cade2721270509d5b1c766ab3549210a39a2a # v2 + with: + php-version: ${{ matrix.php }} + extensions: intl, mysql, gd, ldap, gmp, xml, curl, json, mbstring + ini-values: "post_max_size=256M, max_execution_time=60, date.timezone=America/New_York" + + - name: Check PHP version + run: php -v + + - name: Run apt-get update + run: sudo apt-get update + + - name: Install System Dependencies + run: sudo apt-get install -y apache2 snmp snmpd rrdtool fping libapache2-mod-php${{ matrix.php }} + + - name: Start SNMPD Agent and Test + run: | + sudo systemctl start snmpd + sudo snmpwalk -c public -v2c -On localhost .1.3.6.1.2.1.1 + + - name: Setup Permissions + run: | + sudo chown -R www-data:runner ${{ github.workspace }}/cacti + sudo find ${{ github.workspace }}/cacti -type d -exec chmod 775 {} \; + sudo find ${{ github.workspace }}/cacti -type f -exec chmod 664 {} \; + sudo chmod +x ${{ github.workspace }}/cacti/cmd.php + sudo chmod +x ${{ github.workspace }}/cacti/poller.php + + - name: Create MySQL Config + run: | + echo -e "[client]\nuser = root\npassword = cactiroot\nhost = 127.0.0.1\n" > ~/.my.cnf + + - name: Initialize Cacti Database + env: + MYSQL_AUTH_USR: '--defaults-file=~/.my.cnf' + run: | + mysql $MYSQL_AUTH_USR -e 'CREATE DATABASE IF NOT EXISTS cacti;' + mysql $MYSQL_AUTH_USR -e "CREATE USER IF NOT EXISTS 'cactiuser'@'localhost' IDENTIFIED BY 'cactiuser';" + mysql $MYSQL_AUTH_USR -e "GRANT ALL PRIVILEGES ON cacti.* TO 'cactiuser'@'localhost';" + mysql $MYSQL_AUTH_USR -e "GRANT SELECT ON mysql.time_zone_name TO 'cactiuser'@'localhost';" + mysql $MYSQL_AUTH_USR -e "FLUSH PRIVILEGES;" + mysql $MYSQL_AUTH_USR cacti < ${{ github.workspace }}/cacti/cacti.sql + mysql $MYSQL_AUTH_USR -e "INSERT INTO settings (name, value) VALUES ('path_php_binary', '/usr/bin/php')" cacti + + - name: Install Composer Dependencies + run: | + cd ${{ github.workspace }}/cacti + if [ -f composer.json ]; then + sudo composer install --prefer-dist --no-progress + fi + + - name: Create Cacti config.php + run: | + cat ${{ github.workspace }}/cacti/include/config.php.dist | \ + sed -r "s/localhost/127.0.0.1/g" > ${{ github.workspace }}/cacti/include/config.php + sudo chmod 664 ${{ github.workspace }}/cacti/include/config.php + + - name: Configure Apache + run: | + cat << 'EOF' | sed 's#GITHUB_WORKSPACE#${{ github.workspace }}#g' > /tmp/cacti.conf + + ServerAdmin webmaster@localhost + DocumentRoot GITHUB_WORKSPACE/cacti + + + Options Indexes FollowSymLinks + AllowOverride All + Require all granted + + + ErrorLog ${APACHE_LOG_DIR}/error.log + CustomLog ${APACHE_LOG_DIR}/access.log combined + + EOF + sudo cp /tmp/cacti.conf /etc/apache2/sites-available/000-default.conf + sudo systemctl restart apache2 + + - name: Install Cacti via CLI + run: | + cd ${{ github.workspace }}/cacti + sudo php cli/install_cacti.php --accept-eula --install --force + + - name: Install gpsmap Plugin + run: | + cd ${{ github.workspace }}/cacti + sudo php cli/plugin_manage.php --plugin=gpsmap --install --enable + + - name: Check PHP Syntax for Plugin + run: | + cd ${{ github.workspace }}/cacti/plugins/gpsmap + if find . -name '*.php' -exec php -l {} 2>&1 \; | grep -iv 'no syntax errors detected'; then + echo "Syntax errors found!" + exit 1 + fi + + # gpsmap adds columns to the core host table, so a device with coordinates + # is what makes the poller hook produce anything at all. + - name: Add a mapped Device + run: | + cd ${{ github.workspace }}/cacti + # add_device.php exits 1 on an unknown template id, so take a real one + # rather than assuming what cacti.sql ships. + TPL=$(mysql -u cactiuser -p'cactiuser' -h 127.0.0.1 cacti -sN \ + -e "SELECT id FROM host_template ORDER BY id LIMIT 1;") + if [ -z "$TPL" ]; then + echo "No host_template rows found after install" + exit 1 + fi + echo "Using host_template id $TPL" + sudo php cli/add_device.php --description=mapped --ip=127.0.0.1 --template="$TPL" + mysql -u cactiuser -p'cactiuser' -h 127.0.0.1 cacti \ + -e "UPDATE host SET latitude='51.5074', longitude='-0.1278' WHERE description='mapped';" + mysql -u cactiuser -p'cactiuser' -h 127.0.0.1 cacti \ + -e "INSERT INTO gpsmap_templates (templateID, templateName, upimage, recoverimage, downimage, AP) + SELECT host_template_id, 'ci', 'Green.png', 'Orange.png', 'Red.png', 0 + FROM host WHERE description='mapped' LIMIT 1;" + + - name: Run Cacti Poller + run: | + cd ${{ github.workspace }}/cacti + sudo php poller.php --poller=1 --force --debug + if ! grep -q "SYSTEM STATS" log/cacti.log; then + echo "Cacti poller did not finish successfully" + cat log/cacti.log + exit 1 + fi + + - name: Verify the poller wrote its map artefacts + run: | + cd ${{ github.workspace }}/cacti/plugins/gpsmap/XML + ls -la + for f in all.xml all.kml all-top.html; do + if [ ! -s "$f" ]; then + echo "Expected $f to exist and be non-empty" + exit 1 + fi + done + if ! grep -q ' Date: Sun, 16 Aug 2026 17:26:42 -0700 Subject: [PATCH 02/10] ci: authenticate the MySQL service health check Without credentials the ping is denied and the container can stay unhealthy, so the job never starts. Signed-off-by: Thomas Vincent --- .github/workflows/plugin-ci-workflow.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/plugin-ci-workflow.yml b/.github/workflows/plugin-ci-workflow.yml index 7131b11..7ab53f0 100644 --- a/.github/workflows/plugin-ci-workflow.yml +++ b/.github/workflows/plugin-ci-workflow.yml @@ -97,7 +97,7 @@ jobs: ports: - 3306:3306 options: >- - --health-cmd="mysqladmin ping" + --health-cmd="mysqladmin ping -h 127.0.0.1 -u root -pcactiroot" --health-interval=10s --health-timeout=5s --health-retries=3 From 297d51e49b1cc335305fb5693f6be36ad873763c Mon Sep 17 00:00:00 2001 From: Thomas Vincent Date: Sun, 16 Aug 2026 22:34:00 -0700 Subject: [PATCH 03/10] ci: install the unversioned apache PHP module Ubuntu carries no libapache2-mod-php8.1 package, so every integration job failed at apt with exit 100 before reaching Cacti. The PHP the tests run under comes from setup-php, not apt, so the version does not need pinning here. Matches plugin_monitor, whose matrix passes. Signed-off-by: Thomas Vincent --- .github/workflows/plugin-ci-workflow.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/plugin-ci-workflow.yml b/.github/workflows/plugin-ci-workflow.yml index 7ab53f0..86c2f0f 100644 --- a/.github/workflows/plugin-ci-workflow.yml +++ b/.github/workflows/plugin-ci-workflow.yml @@ -130,7 +130,10 @@ jobs: run: sudo apt-get update - name: Install System Dependencies - run: sudo apt-get install -y apache2 snmp snmpd rrdtool fping libapache2-mod-php${{ matrix.php }} + run: | + # Unversioned: Ubuntu carries no libapache2-mod-php8.x package, and the + # PHP the tests run under comes from setup-php rather than from apt. + sudo apt-get install --yes --no-install-recommends apache2 snmp snmpd rrdtool fping libapache2-mod-php - name: Start SNMPD Agent and Test run: | From a5e0e414248f5e5cff47b0405c19999232096157 Mon Sep 17 00:00:00 2001 From: TheWitness Date: Mon, 17 Aug 2026 18:17:23 -0400 Subject: [PATCH 04/10] Update checkout reference for Cacti repository Use the 1.2.x branch for CI testing --- .github/workflows/plugin-ci-workflow.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/plugin-ci-workflow.yml b/.github/workflows/plugin-ci-workflow.yml index 86c2f0f..0ad3538 100644 --- a/.github/workflows/plugin-ci-workflow.yml +++ b/.github/workflows/plugin-ci-workflow.yml @@ -109,6 +109,7 @@ jobs: uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 with: repository: Cacti/cacti + ref: 1.2.x path: cacti - name: Checkout gpsmap Plugin From adcb98e54f5f6bbaeb6bc2d879dab98a7be2c0e3 Mon Sep 17 00:00:00 2001 From: TheWitness Date: Mon, 17 Aug 2026 18:29:42 -0400 Subject: [PATCH 05/10] Update CI workflow for PHP and database changes Updated PHP version matrix and changed MySQL to MariaDB. Added new steps for linting and checking coding standards. --- .github/workflows/plugin-ci-workflow.yml | 57 +++++++++++++++++++----- 1 file changed, 46 insertions(+), 11 deletions(-) diff --git a/.github/workflows/plugin-ci-workflow.yml b/.github/workflows/plugin-ci-workflow.yml index 0ad3538..0f7b9fb 100644 --- a/.github/workflows/plugin-ci-workflow.yml +++ b/.github/workflows/plugin-ci-workflow.yml @@ -83,12 +83,13 @@ jobs: strategy: fail-fast: false matrix: - php: ['8.1', '8.2', '8.3'] + php: ['8.1', '8.2', '8.3', '8.4'] os: [ubuntu-latest] + cacti: ['release/1.2.31'] services: mysql: - image: mysql:8.0 + image: mariadb:10.6 env: MYSQL_ROOT_PASSWORD: cactiroot MYSQL_DATABASE: cacti @@ -97,19 +98,19 @@ jobs: ports: - 3306:3306 options: >- - --health-cmd="mysqladmin ping -h 127.0.0.1 -u root -pcactiroot" + --health-cmd="mysqladmin ping" --health-interval=10s --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 ${{ matrix.cacti }} steps: - name: Checkout Cacti uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 with: repository: Cacti/cacti - ref: 1.2.x + ref: ${{ matrix.cacti }} path: cacti - name: Checkout gpsmap Plugin @@ -125,16 +126,16 @@ jobs: ini-values: "post_max_size=256M, max_execution_time=60, date.timezone=America/New_York" - name: Check PHP version - run: php -v + run: | + php -v + echo "PHP_BINARY=$(command -v php)" >> "$GITHUB_ENV" - name: Run apt-get update run: sudo apt-get update - name: Install System Dependencies run: | - # Unversioned: Ubuntu carries no libapache2-mod-php8.x package, and the - # PHP the tests run under comes from setup-php rather than from apt. - sudo apt-get install --yes --no-install-recommends apache2 snmp snmpd rrdtool fping libapache2-mod-php + sudo apt-get install --yes --no-install-recommends apache2 snmp snmpd rrdtool fping - name: Start SNMPD Agent and Test run: | @@ -175,9 +176,12 @@ jobs: - name: Create Cacti config.php run: | cat ${{ github.workspace }}/cacti/include/config.php.dist | \ - sed -r "s/localhost/127.0.0.1/g" > ${{ github.workspace }}/cacti/include/config.php + sed -r "s/localhost/127.0.0.1/g" | \ + sed -r "s/'cacti'/'cacti'/g" | \ + sed -r "s/'cactiuser'/'cactiuser'/g" | \ + sed -r "s/'cactiuser'/'cactiuser'/g" > ${{ github.workspace }}/cacti/include/config.php sudo chmod 664 ${{ github.workspace }}/cacti/include/config.php - + - name: Configure Apache run: | cat << 'EOF' | sed 's#GITHUB_WORKSPACE#${{ github.workspace }}#g' > /tmp/cacti.conf @@ -216,6 +220,37 @@ jobs: exit 1 fi + - name: Remove the plugins directory exclusion from the .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: | + 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: | + if composer --no-ansi run-script --list | grep -qE '^[[:space:]]+lint([[:space:]]|$)'; then + composer run-script lint ${{ github.workspace }}/cacti/plugins/gpsmaps + else + echo 'Composer lint script is not defined; skipping.' + fi + working-directory: ${{ github.workspace }}/cacti + + - name: Checking coding standards on base code + run: | + if composer --no-ansi run-script --list | grep -qE '^[[:space:]]+phpcsfixer([[:space:]]|$)'; then + composer run-script phpcsfixer ${{ github.workspace }}/cacti/plugins/gpsmaps + else + echo 'Composer phpcsfixer script is not defined; skipping.' + fi + working-directory: ${{ github.workspace }}/cacti + # gpsmap adds columns to the core host table, so a device with coordinates # is what makes the poller hook produce anything at all. - name: Add a mapped Device From 7678870ef5ddb4636f6ac92db20d94bfb4102a74 Mon Sep 17 00:00:00 2001 From: TheWitness Date: Mon, 17 Aug 2026 18:35:39 -0400 Subject: [PATCH 06/10] Update Cacti branch in CI workflow to 'develop' --- .github/workflows/plugin-ci-workflow.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/plugin-ci-workflow.yml b/.github/workflows/plugin-ci-workflow.yml index 0f7b9fb..0b5c14b 100644 --- a/.github/workflows/plugin-ci-workflow.yml +++ b/.github/workflows/plugin-ci-workflow.yml @@ -85,7 +85,7 @@ jobs: matrix: php: ['8.1', '8.2', '8.3', '8.4'] os: [ubuntu-latest] - cacti: ['release/1.2.31'] + cacti: ['develop'] services: mysql: From 26ce2348c742951e51353af6aa6ec40201202a40 Mon Sep 17 00:00:00 2001 From: Thomas Vincent Date: Tue, 18 Aug 2026 12:19:18 -0700 Subject: [PATCH 07/10] ci: lint the checked-out gpsmap directory Signed-off-by: Thomas Vincent --- .github/workflows/plugin-ci-workflow.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/plugin-ci-workflow.yml b/.github/workflows/plugin-ci-workflow.yml index 0b5c14b..d2700b2 100644 --- a/.github/workflows/plugin-ci-workflow.yml +++ b/.github/workflows/plugin-ci-workflow.yml @@ -126,7 +126,7 @@ jobs: ini-values: "post_max_size=256M, max_execution_time=60, date.timezone=America/New_York" - name: Check PHP version - run: | + run: | php -v echo "PHP_BINARY=$(command -v php)" >> "$GITHUB_ENV" @@ -181,7 +181,7 @@ jobs: sed -r "s/'cactiuser'/'cactiuser'/g" | \ sed -r "s/'cactiuser'/'cactiuser'/g" > ${{ github.workspace }}/cacti/include/config.php sudo chmod 664 ${{ github.workspace }}/cacti/include/config.php - + - name: Configure Apache run: | cat << 'EOF' | sed 's#GITHUB_WORKSPACE#${{ github.workspace }}#g' > /tmp/cacti.conf @@ -236,7 +236,7 @@ jobs: - name: Run Linter on base code run: | if composer --no-ansi run-script --list | grep -qE '^[[:space:]]+lint([[:space:]]|$)'; then - composer run-script lint ${{ github.workspace }}/cacti/plugins/gpsmaps + composer run-script lint ${{ github.workspace }}/cacti/plugins/gpsmap else echo 'Composer lint script is not defined; skipping.' fi @@ -245,7 +245,7 @@ jobs: - name: Checking coding standards on base code run: | if composer --no-ansi run-script --list | grep -qE '^[[:space:]]+phpcsfixer([[:space:]]|$)'; then - composer run-script phpcsfixer ${{ github.workspace }}/cacti/plugins/gpsmaps + composer run-script phpcsfixer ${{ github.workspace }}/cacti/plugins/gpsmap else echo 'Composer phpcsfixer script is not defined; skipping.' fi From 110dbc6acdda3a2d5848e0c88f0e20364626b008 Mon Sep 17 00:00:00 2001 From: Thomas Vincent Date: Tue, 18 Aug 2026 12:40:25 -0700 Subject: [PATCH 08/10] ci: scope style checks to changed PHP files Signed-off-by: Thomas Vincent --- .github/workflows/plugin-ci-workflow.yml | 29 +++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/.github/workflows/plugin-ci-workflow.yml b/.github/workflows/plugin-ci-workflow.yml index d2700b2..b38ba26 100644 --- a/.github/workflows/plugin-ci-workflow.yml +++ b/.github/workflows/plugin-ci-workflow.yml @@ -117,6 +117,7 @@ jobs: uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 with: path: cacti/plugins/gpsmap + fetch-depth: 0 - name: Install PHP ${{ matrix.php }} uses: shivammathur/setup-php@cf4cade2721270509d5b1c766ab3549210a39a2a # v2 @@ -243,12 +244,34 @@ jobs: working-directory: ${{ github.workspace }}/cacti - name: Checking coding standards on base code + env: + BASE_SHA: ${{ github.event.pull_request.base.sha || github.event.before }} run: | - if composer --no-ansi run-script --list | grep -qE '^[[:space:]]+phpcsfixer([[:space:]]|$)'; then - composer run-script phpcsfixer ${{ github.workspace }}/cacti/plugins/gpsmap - else + if ! composer --no-ansi run-script --list | grep -qE '^[[:space:]]+phpcsfixer([[:space:]]|$)'; then echo 'Composer phpcsfixer script is not defined; skipping.' + exit 0 + fi + + if ! git -C plugins/gpsmap cat-file -e "${BASE_SHA}^{commit}" 2>/dev/null; then + BASE_SHA=$(git -C plugins/gpsmap rev-parse HEAD^) + fi + + mapfile -d '' changed_php < <( + git -C plugins/gpsmap diff --name-only --diff-filter=ACMR -z \ + "$BASE_SHA" HEAD -- '*.php' + ) + + if [ "${#changed_php[@]}" -eq 0 ]; then + echo 'No PHP files changed; skipping coding standards.' + exit 0 fi + + php_files=() + for file in "${changed_php[@]}"; do + php_files+=("${{ github.workspace }}/cacti/plugins/gpsmap/$file") + done + + composer run-script phpcsfixer "${php_files[@]}" working-directory: ${{ github.workspace }}/cacti # gpsmap adds columns to the core host table, so a device with coordinates From 8bd158c3255dc46f8d5350bbf71936180d23aa54 Mon Sep 17 00:00:00 2001 From: Thomas Vincent Date: Tue, 18 Aug 2026 12:42:55 -0700 Subject: [PATCH 09/10] ci: diff style checks from the current PR base Signed-off-by: Thomas Vincent --- .github/workflows/plugin-ci-workflow.yml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/plugin-ci-workflow.yml b/.github/workflows/plugin-ci-workflow.yml index b38ba26..d75faa0 100644 --- a/.github/workflows/plugin-ci-workflow.yml +++ b/.github/workflows/plugin-ci-workflow.yml @@ -243,16 +243,18 @@ jobs: fi working-directory: ${{ github.workspace }}/cacti - - name: Checking coding standards on base code + - name: Check coding standards on changed plugin PHP env: - BASE_SHA: ${{ github.event.pull_request.base.sha || github.event.before }} + BASE_SHA: ${{ github.event.before }} run: | if ! composer --no-ansi run-script --list | grep -qE '^[[:space:]]+phpcsfixer([[:space:]]|$)'; then echo 'Composer phpcsfixer script is not defined; skipping.' exit 0 fi - if ! git -C plugins/gpsmap cat-file -e "${BASE_SHA}^{commit}" 2>/dev/null; then + if [ "$GITHUB_EVENT_NAME" = 'pull_request' ]; then + BASE_SHA=$(git -C plugins/gpsmap rev-parse HEAD^1) + elif ! git -C plugins/gpsmap cat-file -e "${BASE_SHA}^{commit}" 2>/dev/null; then BASE_SHA=$(git -C plugins/gpsmap rev-parse HEAD^) fi From 7fbe7d3e700513636102618f194e38713b1a28b9 Mon Sep 17 00:00:00 2001 From: Thomas Vincent Date: Tue, 18 Aug 2026 12:45:42 -0700 Subject: [PATCH 10/10] ci: seed a device template for integration tests Signed-off-by: Thomas Vincent --- .github/workflows/plugin-ci-workflow.yml | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/.github/workflows/plugin-ci-workflow.yml b/.github/workflows/plugin-ci-workflow.yml index d75faa0..845b778 100644 --- a/.github/workflows/plugin-ci-workflow.yml +++ b/.github/workflows/plugin-ci-workflow.yml @@ -281,13 +281,15 @@ jobs: - name: Add a mapped Device run: | cd ${{ github.workspace }}/cacti - # add_device.php exits 1 on an unknown template id, so take a real one - # rather than assuming what cacti.sql ships. + # A bare develop install may contain no templates. Seed the smallest + # valid template fixture so add_device.php can exercise the real API. TPL=$(mysql -u cactiuser -p'cactiuser' -h 127.0.0.1 cacti -sN \ -e "SELECT id FROM host_template ORDER BY id LIMIT 1;") if [ -z "$TPL" ]; then - echo "No host_template rows found after install" - exit 1 + mysql -u cactiuser -p'cactiuser' -h 127.0.0.1 cacti \ + -e "INSERT INTO host_template (name) VALUES ('CI Device');" + TPL=$(mysql -u cactiuser -p'cactiuser' -h 127.0.0.1 cacti -sN \ + -e "SELECT id FROM host_template WHERE name = 'CI Device' ORDER BY id DESC LIMIT 1;") fi echo "Using host_template id $TPL" sudo php cli/add_device.php --description=mapped --ip=127.0.0.1 --template="$TPL"