Repository navigation
452 lines (400 loc) · 16.2 KB
/
Copy pathplugin-ci-workflow.yml
File metadata and controls
452 lines (400 loc) · 16.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
# SPDX-FileCopyrightText: 2026 Thomas Vincent <thomasvincent@gmail.com>
# SPDX-License-Identifier: GPL-2.0-or-later
#
# This file is part of plugin_cloud, a plugin for Cacti.
# https://github.com/somethingwithproof/plugin_cloud
#
# 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.
# Follows plugin_smokeping and the maintained plugins (servcheck, webseer,
# monitor): Cacti checked out with this plugin under plugins/, a MariaDB
# service, Cacti installed from its CLI, the plugin installed with
# plugin_manage.php, and Pest from the locked shared plugin harness. The test
# harness choice is pending maintainers in #12; this matches what maintained
# plugins use today.
#
# `ci-ok` is the one check branch protection needs to name.
name: CI
on:
push:
branches:
- main
pull_request:
workflow_dispatch:
permissions:
contents: read
concurrency:
group: ci-${{ github.event_name }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
jobs:
# Cacti includes setup.php on whatever PHP a 1.2.31 site runs, so the entry
# points must parse on PHP 8.0 even though the plugin refuses to run below
# 8.2.
entry-point-lint:
name: PHP 8.0 entry point lint
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Checkout plugin
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: Check release archive contents and version
run: bash tests/bin/archive-check.sh
- name: Install PHP 8.0
uses: shivammathur/setup-php@eb7c497e18156a6bbabfef1d3a82760b9eda3962 # 2.40.0
with:
php-version: '8.0'
coverage: none
- name: Lint entry points
run: |
set -euo pipefail
php -v
for f in *.php include/*.php locales/*.php tests/bin/*.php; do
php -l "$f"
done
integration-test:
name: PHP ${{ matrix.php }} on Cacti ${{ matrix.cacti }}
runs-on: ubuntu-latest
# The real pages and collector run below; no provider may be reached.
env:
CLOUD_OFFLINE: '1'
timeout-minutes: 30
strategy:
fail-fast: false
matrix:
php: ['8.2', '8.3', '8.4', '8.5']
cacti: ['release/1.2.31', '1.2.x']
services:
mariadb:
image: mariadb:11.8@sha256:6422478cb8e159f080fb1d8ccf65101e26fe51385787fde7d16c3b165a331f15
env:
MYSQL_ROOT_PASSWORD: cactiroot
MYSQL_DATABASE: cacti
MYSQL_USER: cactiuser
MYSQL_PASSWORD: cactiuser
ports:
- 3306:3306
options: >-
--health-cmd="mariadb-admin ping"
--health-interval=10s
--health-timeout=5s
--health-retries=3
steps:
- name: Checkout Cacti
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
repository: Cacti/cacti
ref: ${{ matrix.cacti }}
path: cacti
- name: Checkout cloud plugin
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
path: cacti/plugins/cloud
- name: Install PHP ${{ matrix.php }}
uses: shivammathur/setup-php@eb7c497e18156a6bbabfef1d3a82760b9eda3962 # 2.40.0
with:
php-version: ${{ matrix.php }}
tools: composer:2.10.3, phpstan:2.3.5
extensions: intl, mysql, gd, ldap, gmp, xml, json, mbstring, openssl, snmp
ini-values: "post_max_size=256M, max_execution_time=60, date.timezone=America/New_York"
coverage: none
- name: Install system dependencies
run: |
sudo apt-get update
# Ubuntu 26.04's mysql client rejects the DELIMITER line at the top of
# Cacti's cacti.sql; MariaDB's client loads it.
sudo apt-get install -y rrdtool gettext mariadb-client
# Core's release archives exclude tests/, so fetch the shared harness lock
# at the same immutable revision the maintained plugins pin.
- name: Checkout shared CI tooling
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
repository: Cacti/cacti
ref: f3ff777992875740e4665fedfe2eff8335f5b894
persist-credentials: false
path: ci-tools
sparse-checkout: |
tests/tools/plugin-harness
- name: Install the locked Pest harness
run: |
set -euo pipefail
harness="$RUNNER_TEMP/cacti-plugin-harness"
mkdir -p "$harness"
cp ci-tools/tests/tools/plugin-harness/composer.json ci-tools/tests/tools/plugin-harness/composer.lock "$harness/"
composer --working-dir="$harness" validate --strict
composer --working-dir="$harness" install --no-interaction --no-progress --prefer-dist
echo "CACTI_PEST_BIN=$harness/vendor/bin/pest" >> "$GITHUB_ENV"
- name: Initialize Cacti database
run: |
echo -e "[client]\nuser = root\npassword = cactiroot\nhost = 127.0.0.1\n" > ~/.my.cnf
chmod 600 ~/.my.cnf
mariadb -e "CREATE USER IF NOT EXISTS 'cactiuser'@'127.0.0.1' IDENTIFIED BY 'cactiuser';"
mariadb -e "GRANT ALL PRIVILEGES ON cacti.* TO 'cactiuser'@'127.0.0.1';"
mariadb -e "GRANT SELECT ON mysql.time_zone_name TO 'cactiuser'@'127.0.0.1';"
mariadb -e "FLUSH PRIVILEGES;"
mariadb cacti < cacti/cacti.sql
mariadb -e "INSERT INTO settings (name, value) VALUES ('path_php_binary', '$(command -v php)')" cacti
- name: Create Cacti config.php
run: |
sed -r "s/localhost/127.0.0.1/g" cacti/include/config.php.dist > cacti/include/config.php
- name: Install Cacti via CLI
working-directory: cacti
run: php cli/install_cacti.php --accept-eula --install --force
- name: Run unit tests
working-directory: cacti/plugins/cloud
run: '"$CACTI_PEST_BIN" --configuration=phpunit.xml'
# Installs, upgrades, and uninstalls the plugin through Cacti's own
# plugin API, so it runs before the plugin is installed for the poller.
- name: Run lifecycle integration tests
working-directory: cacti/plugins/cloud
env:
CACTI_PATH: ${{ github.workspace }}/cacti
CLOUD_TEST_DATABASE: disposable
run: '"$CACTI_PEST_BIN" --configuration=phpunit-integration.xml'
# The integration tests provoke refusals that the plugin logs as errors,
# such as a schema downgrade. Keep their log apart so the error check
# below covers the install and the poller run.
- name: Set the integration tests' log aside
if: always()
run: |
if [ -f cacti/log/cacti.log ]; then
mv cacti/log/cacti.log cacti/log/integration.log
fi
- name: Install and enable the plugin
working-directory: cacti
run: php plugins/cloud/tests/bin/php-guard-check.php
# Against the minimum supported release only: the 1.2.x branch's
# docblocks give PDO connections as resources and mistype some
# parameters, which PHPStan reports at every call site.
- name: Run PHPStan
if: matrix.cacti == 'release/1.2.31'
working-directory: cacti/plugins/cloud
env:
CACTI_PATH: ${{ github.workspace }}/cacti
run: phpstan analyse -c phpstan.neon --no-progress
- name: Verify translation template and catalogs
working-directory: cacti/plugins/cloud
run: sh locales/build_gettext.sh --check
- name: Run Cacti poller
working-directory: cacti
run: |
php poller.php --poller=1 --force --debug
grep -q "SYSTEM STATS" log/cacti.log
# poller_bottom starts the collector in the background; run it once in
# the foreground too, so its exit status and log lines are checked.
- name: Run the cloud collector
working-directory: cacti
run: php plugins/cloud/poller_cloud.php --poller=1
- name: Check page permissions and POST-only actions
working-directory: cacti
env:
CLOUD_TEST_DATABASE: disposable
run: |
php -S 127.0.0.1:8080 -t "$GITHUB_WORKSPACE" > "$RUNNER_TEMP/php-server.log" 2>&1 &
for _ in 1 2 3 4 5 6 7 8 9 10; do
curl -fsS -o /dev/null http://127.0.0.1:8080/cacti/index.php && break
sleep 1
done
php plugins/cloud/tests/bin/page-permissions.php http://127.0.0.1:8080/cacti/
if grep -E "Fatal error|Warning:|Uncaught" "$RUNNER_TEMP/php-server.log"; then
exit 1
fi
- name: Check Cacti log for errors
if: always()
run: |
if [ -f cacti/log/integration.log ]; then
echo "== integration tests (not checked)"
cat cacti/log/integration.log
fi
if [ -f cacti/log/cacti.log ]; then
echo "== install and poller run"
cat cacti/log/cacti.log
if grep -E "FATAL:|ERROR:|WARNING:" cacti/log/cacti.log; then
exit 1
fi
fi
# Fails only when 1,000 series do not finish within one poller interval
# (REQ-PERF-001). The timings are printed, not compared: runners vary.
# It runs after the log check, since its budget case logs a warning on
# purpose; its own exit status and the web server log are checked here.
- name: Measure collection and the health page
working-directory: cacti
env:
CLOUD_TEST_DATABASE: disposable
run: |
php -S 127.0.0.1:8081 -t "$GITHUB_WORKSPACE" > "$RUNNER_TEMP/php-perf.log" 2>&1 &
for _ in 1 2 3 4 5 6 7 8 9 10; do
curl -fsS -o /dev/null http://127.0.0.1:8081/cacti/index.php && break
sleep 1
done
php plugins/cloud/tests/bin/perf.php http://127.0.0.1:8081/cacti/
if grep -E "Fatal error|Warning:|Uncaught" "$RUNNER_TEMP/php-perf.log"; then
exit 1
fi
# A 1.2.31 site may still run PHP 8.1. Enabling the plugin there must be
# refused with a message and leave Cacti working, both on a fresh install
# and after an upgrade-in-place left the plugin's hooks registered.
php-guard:
name: Refusal on PHP 8.1 with Cacti 1.2.31
runs-on: ubuntu-latest
# The real pages and collector run below; no provider may be reached.
env:
CLOUD_OFFLINE: '1'
timeout-minutes: 20
services:
mariadb:
image: mariadb:11.8@sha256:6422478cb8e159f080fb1d8ccf65101e26fe51385787fde7d16c3b165a331f15
env:
MYSQL_ROOT_PASSWORD: cactiroot
MYSQL_DATABASE: cacti
MYSQL_USER: cactiuser
MYSQL_PASSWORD: cactiuser
ports:
- 3306:3306
options: >-
--health-cmd="mariadb-admin ping"
--health-interval=10s
--health-timeout=5s
--health-retries=3
steps:
- name: Checkout Cacti
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
repository: Cacti/cacti
ref: release/1.2.31
path: cacti
- name: Checkout cloud plugin
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
path: cacti/plugins/cloud
- name: Install system dependencies
run: |
sudo apt-get update
sudo apt-get install -y rrdtool mariadb-client
- name: Install PHP 8.1
uses: shivammathur/setup-php@eb7c497e18156a6bbabfef1d3a82760b9eda3962 # 2.40.0
with:
php-version: '8.1'
extensions: intl, mysql, gd, ldap, gmp, xml, json, mbstring, openssl, snmp
ini-values: "date.timezone=America/New_York"
coverage: none
- name: Initialize Cacti database
run: |
echo -e "[client]\nuser = root\npassword = cactiroot\nhost = 127.0.0.1\n" > ~/.my.cnf
chmod 600 ~/.my.cnf
mariadb -e "CREATE USER IF NOT EXISTS 'cactiuser'@'127.0.0.1' IDENTIFIED BY 'cactiuser';"
mariadb -e "GRANT ALL PRIVILEGES ON cacti.* TO 'cactiuser'@'127.0.0.1';"
mariadb -e "GRANT SELECT ON mysql.time_zone_name TO 'cactiuser'@'127.0.0.1';"
mariadb -e "FLUSH PRIVILEGES;"
mariadb cacti < cacti/cacti.sql
sed -r "s/localhost/127.0.0.1/g" cacti/include/config.php.dist > cacti/include/config.php
- name: Install Cacti via CLI
working-directory: cacti
run: php cli/install_cacti.php --accept-eula --install --force
- name: Install is refused on PHP 8.1
working-directory: cacti
run: php plugins/cloud/tests/bin/php-guard-check.php
- name: Install PHP 8.2
uses: shivammathur/setup-php@eb7c497e18156a6bbabfef1d3a82760b9eda3962 # 2.40.0
with:
php-version: '8.2'
extensions: intl, mysql, gd, ldap, gmp, xml, json, mbstring, openssl, snmp
ini-values: "date.timezone=America/New_York"
coverage: none
- name: Install succeeds on PHP 8.2
working-directory: cacti
run: php plugins/cloud/tests/bin/php-guard-check.php
- name: Install PHP 8.1 again
uses: shivammathur/setup-php@eb7c497e18156a6bbabfef1d3a82760b9eda3962 # 2.40.0
with:
php-version: '8.1'
extensions: intl, mysql, gd, ldap, gmp, xml, json, mbstring, openssl, snmp
ini-values: "date.timezone=America/New_York"
coverage: none
- name: Registered hooks stay quiet on PHP 8.1
working-directory: cacti
run: php plugins/cloud/tests/bin/php-guard-check.php
# The poller dispatches poller_bottom and loads every enabled plugin's
# setup.php, as each page does through include/global.php.
- name: Cacti's poller still runs on PHP 8.1
working-directory: cacti
run: |
php poller.php --poller=1 --force --debug
grep -q "SYSTEM STATS" log/cacti.log
# Every page includes each enabled plugin's setup.php and runs its
# hooks, so the core pages must keep loading, and the plugin's own pages
# must show the refusal instead of failing.
- name: Core pages still load on PHP 8.1
working-directory: cacti
env:
CLOUD_TEST_DATABASE: disposable
CLOUD_EXPECT_REFUSAL: '1'
run: |
php -S 127.0.0.1:8080 -t "$GITHUB_WORKSPACE" > "$RUNNER_TEMP/php-server.log" 2>&1 &
for _ in 1 2 3 4 5 6 7 8 9 10; do
curl -fsS -o /dev/null http://127.0.0.1:8080/cacti/index.php && break
sleep 1
done
php plugins/cloud/tests/bin/page-check.php http://127.0.0.1:8080/cacti/ \
index.php host.php graph_view.php graphs.php data_sources.php plugins.php \
settings.php utilities.php user_admin.php \
plugins/cloud/cloud_health.php plugins/cloud/cloud_accounts.php
if grep -E "Fatal error|Parse error|Uncaught" "$RUNNER_TEMP/php-server.log"; then
exit 1
fi
workflow-lint:
name: Workflow lint
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Checkout plugin
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: Lint the workflows with actionlint and zizmor
env:
GH_TOKEN: ${{ github.token }}
run: sh tests/lint-workflows.sh
reuse:
name: REUSE compliance
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Checkout plugin
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: Lint licensing metadata
run: pipx run --spec 'reuse[charset-normalizer]==6.3.0' reuse lint
ci-ok:
name: ci-ok
if: ${{ always() }}
needs:
- entry-point-lint
- integration-test
- php-guard
- workflow-lint
- reuse
runs-on: ubuntu-latest
timeout-minutes: 5
permissions: {}
steps:
- name: Require every job to have succeeded
env:
NEEDS: ${{ toJSON(needs) }}
run: |
set -euo pipefail
echo "$NEEDS" | jq -r 'to_entries[] | "\(.key): \(.value.result)"'
echo "$NEEDS" | jq -e 'all(.[]; .result == "success")' >/dev/null