1#!/usr/bin/env php 2<?php 3/** 4 * Version Update Script for Delete Page Guard Plugin 5 * 6 * Updates version information across all plugin files. 7 * Usage: php build/update-version.php [new-version] [new-date] 8 * 9 * @license GPL 2 (https://www.gnu.org/licenses/gpl-2.0.html) - see LICENSE.md 10 * @author Johann Duscher <jonny.dee@posteo.net> 11 * @copyright 2025 Johann Duscher 12 */ 13 14$baseDir = dirname(__DIR__); 15$versionFile = $baseDir . '/version.php'; 16 17// Load current version info 18if (!file_exists($versionFile)) { 19 die("Error: version.php not found\n"); 20} 21 22$versionInfo = include $versionFile; 23$currentVersion = $versionInfo['version']; 24$currentDate = $versionInfo['date']; 25 26// Parse command line arguments 27$newVersion = $argv[1] ?? null; 28$newDate = $argv[2] ?? date('Y-m-d'); 29 30if (!$newVersion) { 31 echo "Delete Page Guard Plugin - Version Update Script\n"; 32 echo "Current version: {$currentVersion} ({$currentDate})\n\n"; 33 echo "Usage: php build/update-version.php <new-version> [new-date]\n"; 34 echo "Example: php build/update-version.php 1.1.0 2025-02-01\n"; 35 exit(1); 36} 37 38// Validate version format (semantic versioning) 39if (!preg_match('/^\d+\.\d+\.\d+(-[a-zA-Z0-9\-\.]+)?$/', $newVersion)) { 40 die("Error: Invalid version format. Use semantic versioning (e.g., 1.0.0)\n"); 41} 42 43// Validate date format 44if (!preg_match('/^\d{4}-\d{2}-\d{2}$/', $newDate)) { 45 die("Error: Invalid date format. Use YYYY-MM-DD\n"); 46} 47 48echo "Updating version from {$currentVersion} to {$newVersion}\n"; 49echo "Updating date from {$currentDate} to {$newDate}\n\n"; 50 51// Update version.php 52$newVersionInfo = $versionInfo; 53$newVersionInfo['version'] = $newVersion; 54$newVersionInfo['date'] = $newDate; 55 56$versionContent = "<?php\n/**\n * Delete Page Guard Plugin - Version Information\n *\n * Centralized version management for the plugin.\n * This file is used by build scripts to maintain consistent versioning.\n *\n * @license GPL 2 (https://www.gnu.org/licenses/gpl-2.0.html) - see LICENSE.md\n * @author Johann Duscher <jonny.dee@posteo.net>\n * @copyright 2025 Johann Duscher\n */\n\n// Protect against direct call, but allow build scripts\nif (!defined('DOKU_INC') && php_sapi_name() !== 'cli') die();\n\nreturn " . var_export($newVersionInfo, true) . ";\n"; 57 58file_put_contents($versionFile, $versionContent); 59echo "✓ Updated version.php\n"; 60 61// Update plugin.info.txt 62$pluginInfoFile = $baseDir . '/plugin.info.txt'; 63if (file_exists($pluginInfoFile)) { 64 $content = file_get_contents($pluginInfoFile); 65 $content = preg_replace('/^version\s+.*$/m', "version {$newVersion}", $content); 66 $content = preg_replace('/^date\s+.*$/m', "date {$newDate}", $content); 67 file_put_contents($pluginInfoFile, $content); 68 echo "✓ Updated plugin.info.txt\n"; 69} 70 71// Update CHANGELOG.md header (if it exists and is unreleased) 72$changelogFile = $baseDir . '/CHANGELOG.md'; 73if (file_exists($changelogFile)) { 74 $content = file_get_contents($changelogFile); 75 // Replace [Unreleased] with actual version 76 if (strpos($content, '## [Unreleased]') !== false) { 77 $content = str_replace('## [Unreleased]', "## [{$newVersion}] - {$newDate}", $content); 78 file_put_contents($changelogFile, $content); 79 echo "✓ Updated CHANGELOG.md (marked release)\n"; 80 } else { 81 echo "ℹ CHANGELOG.md - no [Unreleased] section found\n"; 82 } 83} 84 85// Update dokuwiki-plugin-page.txt (plugin template) 86$pluginPageFile = $baseDir . '/dokuwiki-plugin-page.txt'; 87if (file_exists($pluginPageFile)) { 88 $content = file_get_contents($pluginPageFile); 89 90 // Update lastupdate date 91 $content = preg_replace('/^lastupdate\s*:\s*\d{4}-\d{2}-\d{2}\s*$/m', "lastupdate : {$newDate}", $content); 92 93 // Update downloadurl with new version (more robust pattern) 94 $content = preg_replace( 95 '#downloadurl:\s*https://github\.com/jonnydee/deletepageguard/releases/download/v\d+\.\d+\.\d+/deletepageguard-\d+\.\d+\.\d+\.zip#', 96 "downloadurl: https://github.com/jonnydee/deletepageguard/releases/download/v{$newVersion}/deletepageguard-{$newVersion}.zip", 97 $content 98 ); 99 100 // Update changelog section with new version entry (add at top of changelog) 101 $changelogEntry = " * **{$newDate}**\n * Release v{$newVersion}\n * "; 102 if (strpos($content, "Release v{$newVersion}") === false) { 103 // Find the changelog section and add new entry 104 $content = preg_replace( 105 '/(===== Changelog =====.*?)( \* \*\*\d{4}-\d{2}-\d{2}\*\*)/s', 106 "\$1{$changelogEntry}See CHANGELOG.md for details\n\n\$2", 107 $content 108 ); 109 } 110 111 file_put_contents($pluginPageFile, $content); 112 echo "✓ Updated dokuwiki-plugin-page.txt (download URL and date)\n"; 113} 114 115echo "\n✅ Version update completed successfully!\n"; 116echo "\nNext steps:\n"; 117echo "1. Review the changes\n"; 118echo "2. Update CHANGELOG.md if needed\n"; 119echo "3. Run 'make dist' to create distribution package\n"; 120echo "4. Commit and tag the release\n";