|
| 1 | +#!/bin/sh |
| 2 | + |
| 3 | +set -eu |
| 4 | + |
| 5 | +fail() { |
| 6 | + printf '%s\n' "$1" >&2 |
| 7 | + exit 1 |
| 8 | +} |
| 9 | + |
| 10 | +require_file() { |
| 11 | + if [ ! -f "$1" ]; then |
| 12 | + fail "Required version metadata file is missing: $1" |
| 13 | + fi |
| 14 | +} |
| 15 | + |
| 16 | +require_single_value() { |
| 17 | + label=$1 |
| 18 | + value=$2 |
| 19 | + |
| 20 | + if [ -z "$value" ]; then |
| 21 | + fail "Could not find $label." |
| 22 | + fi |
| 23 | + |
| 24 | + line_count=$( printf '%s\n' "$value" | awk 'END { print NR }' ) |
| 25 | + |
| 26 | + if [ "$line_count" -ne 1 ]; then |
| 27 | + fail "Expected exactly one $label, found $line_count." |
| 28 | + fi |
| 29 | + |
| 30 | + printf '%s\n' "$value" |
| 31 | +} |
| 32 | + |
| 33 | +repository_root=$( git rev-parse --show-toplevel 2>/dev/null ) || { |
| 34 | + fail 'Version consistency check must run inside a Git worktree.' |
| 35 | +} |
| 36 | + |
| 37 | +cd "$repository_root" |
| 38 | + |
| 39 | +plugin_file='plugins/basicrum/basicrum.php' |
| 40 | +readme_file='plugins/basicrum/readme.txt' |
| 41 | + |
| 42 | +require_file "$plugin_file" |
| 43 | +require_file "$readme_file" |
| 44 | + |
| 45 | +plugin_header_version=$( require_single_value 'plugin header Version value' "$( |
| 46 | + sed -n 's/^[[:space:]]*\*[[:space:]]*Version:[[:space:]]*\([^[:space:]]*\)[[:space:]]*$/\1/p' "$plugin_file" |
| 47 | +)" ) |
| 48 | + |
| 49 | +constant_version=$( require_single_value 'BASICRUM_VERSION value' "$( |
| 50 | + sed -n "s/^[[:space:]]*define( 'BASICRUM_VERSION', '\([^']*\)' );[[:space:]]*$/\1/p" "$plugin_file" |
| 51 | +)" ) |
| 52 | + |
| 53 | +stable_tag=$( require_single_value 'readme Stable tag value' "$( |
| 54 | + sed -n 's/^Stable tag:[[:space:]]*\([^[:space:]]*\)[[:space:]]*$/\1/p' "$readme_file" |
| 55 | +)" ) |
| 56 | + |
| 57 | +changelog_version=$( require_single_value 'top changelog version' "$( |
| 58 | + awk ' |
| 59 | + $0 == "== Changelog ==" { |
| 60 | + in_changelog = 1 |
| 61 | + next |
| 62 | + } |
| 63 | +
|
| 64 | + in_changelog && /^= .+ =$/ { |
| 65 | + version = $0 |
| 66 | + sub(/^= /, "", version) |
| 67 | + sub(/ =$/, "", version) |
| 68 | + print version |
| 69 | + exit |
| 70 | + } |
| 71 | + ' "$readme_file" |
| 72 | +)" ) |
| 73 | + |
| 74 | +if [ "$constant_version" != "$plugin_header_version" ]; then |
| 75 | + fail "BASICRUM_VERSION ($constant_version) does not match plugin header Version ($plugin_header_version)." |
| 76 | +fi |
| 77 | + |
| 78 | +if [ "$stable_tag" != "$plugin_header_version" ]; then |
| 79 | + fail "Stable tag ($stable_tag) does not match plugin header Version ($plugin_header_version)." |
| 80 | +fi |
| 81 | + |
| 82 | +if [ "$changelog_version" != "$plugin_header_version" ]; then |
| 83 | + fail "Top changelog version ($changelog_version) does not match plugin header Version ($plugin_header_version)." |
| 84 | +fi |
| 85 | + |
| 86 | +if ! printf '%s\n' "$plugin_header_version" | grep -Eq '^[0-9]+(\.[0-9]+){2}([.-][0-9A-Za-z]+)*$'; then |
| 87 | + fail "Plugin header Version ($plugin_header_version) must use an X.Y.Z version format." |
| 88 | +fi |
| 89 | + |
| 90 | +release_tag=${BASICRUM_RELEASE_TAG:-} |
| 91 | + |
| 92 | +if [ "$#" -gt 1 ]; then |
| 93 | + fail 'Usage: tools/verify-version-consistency.sh [release-tag]' |
| 94 | +fi |
| 95 | + |
| 96 | +if [ "$#" -eq 1 ]; then |
| 97 | + release_tag=$1 |
| 98 | +fi |
| 99 | + |
| 100 | +if [ -n "$release_tag" ]; then |
| 101 | + if [ "$release_tag" != "v$plugin_header_version" ]; then |
| 102 | + fail "Release tag ($release_tag) does not match plugin header Version ($plugin_header_version). Use v$plugin_header_version." |
| 103 | + fi |
| 104 | +fi |
| 105 | + |
| 106 | +printf '%s\n' "Version consistency check passed: $plugin_header_version" |
0 commit comments