From 4afecd19909d3ab506372e9728b7e139deedf70f Mon Sep 17 00:00:00 2001 From: Thomas Vincent Date: Mon, 16 Nov 2026 20:28:44 -0800 Subject: [PATCH 1/2] test: enforce release archive contents Signed-off-by: Thomas Vincent --- .gitattributes | 12 ++++++ .github/workflows/plugin-ci-workflow.yml | 3 ++ tests/bin/archive-check.sh | 51 ++++++++++++++++++++++++ 3 files changed, 66 insertions(+) create mode 100644 tests/bin/archive-check.sh diff --git a/.gitattributes b/.gitattributes index 385524c..d5067ce 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,2 +1,14 @@ * text=auto eol=lf *.rrd binary + +# Keep repository and test tooling out of the installable plugin archive. +.editorconfig export-ignore +.gitattributes export-ignore +.github export-ignore +CODE_OF_CONDUCT.md export-ignore +CONTRIBUTING.md export-ignore +REUSE.toml export-ignore +phpstan.neon export-ignore +phpunit.xml export-ignore +phpunit-integration.xml export-ignore +tests export-ignore diff --git a/.github/workflows/plugin-ci-workflow.yml b/.github/workflows/plugin-ci-workflow.yml index e58c666..9aaf808 100644 --- a/.github/workflows/plugin-ci-workflow.yml +++ b/.github/workflows/plugin-ci-workflow.yml @@ -53,6 +53,9 @@ jobs: 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: diff --git a/tests/bin/archive-check.sh b/tests/bin/archive-check.sh new file mode 100644 index 0000000..82ca520 --- /dev/null +++ b/tests/bin/archive-check.sh @@ -0,0 +1,51 @@ +#!/usr/bin/env bash +# SPDX-FileCopyrightText: 2026 Thomas Vincent +# 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. + +set -euo pipefail + +repo=$(cd "$(dirname "$0")/../.." && pwd) +archive=$(mktemp) +trap 'rm -f "$archive"' EXIT + +git -C "$repo" archive --worktree-attributes --format=tar --output="$archive" HEAD +listing=$(tar -tf "$archive") + +while IFS= read -r path; do + case "$path" in + cloud_accounts.php|cloud_health.php|index.php|poller_cloud.php|setup.php|ss_cloud.php|INFO|README.md|LICENSE|SECURITY.md) ;; + LICENSES/|LICENSES/*|docs/|docs/*|include/|include/*|lib/|lib/*|locales/|locales/*|templates/|templates/*) ;; + *) + printf 'Unexpected file in release archive: %s\n' "$path" >&2 + exit 1 + ;; + esac +done <<< "$listing" + +for required in INFO README.md LICENSE setup.php cloud_accounts.php cloud_health.php poller_cloud.php ss_cloud.php index.php; do + if ! grep -Fxq "$required" <<< "$listing"; then + printf 'Required release file is missing: %s\n' "$required" >&2 + exit 1 + fi +done + +version=$(sed -n 's/^version[[:space:]]*=[[:space:]]*//p' "$repo/INFO" | head -n 1) +if [[ ! $version =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[A-Za-z0-9.-]+)?$ ]]; then + printf 'INFO version is not semantic: %s\n' "$version" >&2 + exit 1 +fi + +printf 'Release archive policy passed for plugin_cloud %s (%s files).\n' "$version" "$(wc -l <<< "$listing" | tr -d ' ')" From 8324af7cce3bc1eb7577feffd57fdec89e10436e Mon Sep 17 00:00:00 2001 From: Thomas Vincent Date: Mon, 16 Nov 2026 20:39:07 -0800 Subject: [PATCH 2/2] test: validate release archive SemVer Signed-off-by: Thomas Vincent --- tests/bin/archive-check.sh | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/tests/bin/archive-check.sh b/tests/bin/archive-check.sh index 82ca520..089a179 100644 --- a/tests/bin/archive-check.sh +++ b/tests/bin/archive-check.sh @@ -42,8 +42,33 @@ for required in INFO README.md LICENSE setup.php cloud_accounts.php cloud_health fi done -version=$(sed -n 's/^version[[:space:]]*=[[:space:]]*//p' "$repo/INFO" | head -n 1) -if [[ ! $version =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[A-Za-z0-9.-]+)?$ ]]; then +version=$(tar -xOf "$archive" INFO | sed -n 's/^version[[:space:]]*=[[:space:]]*//p' | head -n 1) + +is_semver() { + local version=$1 + local numeric='(0|[1-9][0-9]*)' + local prerelease_id='(0|[1-9][0-9]*|[0-9A-Za-z-]*[A-Za-z-][0-9A-Za-z-]*)' + local prerelease="(-${prerelease_id}(\\.${prerelease_id})*)?" + local build='(\+[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?' + + [[ $version =~ ^${numeric}\.${numeric}\.${numeric}${prerelease}${build}$ ]] +} + +for valid in 0.0.0 1.2.3-alpha.1 1.2.3+build.7 1.2.3-rc.1+build.7; do + if ! is_semver "$valid"; then + printf 'Valid semantic version rejected: %s\n' "$valid" >&2 + exit 1 + fi +done + +for invalid in 01.2.3 1.02.3 1.2.03 1.2.3-alpha..1 1.2.3+build..7; do + if is_semver "$invalid"; then + printf 'Invalid semantic version accepted: %s\n' "$invalid" >&2 + exit 1 + fi +done + +if ! is_semver "$version"; then printf 'INFO version is not semantic: %s\n' "$version" >&2 exit 1 fi