|
| 1 | +#!/usr/bin/php |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Helper script to increase Source Integration versions |
| 5 | + * |
| 6 | + * Will retrieve all plugin versions numbers, generate a message and create a |
| 7 | + * tag for the new version (based on Source framework version number), listing |
| 8 | + * individual, VCS-specific plugins names and versions. |
| 9 | + */ |
| 10 | + |
| 11 | +// Path to MantisBT root, relative to the Source Integration Plugin's git root |
| 12 | +// Change this based on your dev environment's setting |
| 13 | +$g_mantis_root = '../../mantisbt'; |
| 14 | + |
| 15 | + |
| 16 | +// --------------------------------------------------------------------------- |
| 17 | +// Main program |
| 18 | +// |
| 19 | + |
| 20 | +// Change to framework's root dir |
| 21 | +chdir( dirname( __DIR__ ) ); |
| 22 | + |
| 23 | +// Load plugins and get their version numbers |
| 24 | +foreach( new DirectoryIterator( getcwd() ) as $t_file ) { |
| 25 | + $t_name = $t_file->getFilename(); |
| 26 | + if( $t_file->isDir() && strpos( $t_name, 'Source' ) === 0 ) { |
| 27 | + if( plugin_load_class( $t_name ) ) { |
| 28 | + $t_plugins[$t_name] = plugin_get_version( $t_name ); |
| 29 | + } else { |
| 30 | + echo "ERROR: plugin '$t_name' could not be loaded"; |
| 31 | + } |
| 32 | + } |
| 33 | +} |
| 34 | +ksort( $t_plugins ); |
| 35 | + |
| 36 | +// Generate message |
| 37 | +$t_framework_version = array_shift( $t_plugins ); |
| 38 | +$t_tag = 'v' . $t_framework_version; |
| 39 | +$t_message = "Release $t_framework_version\n\n"; |
| 40 | +$t_message .= "Includes the following VCS-specific plugins:\n"; |
| 41 | +foreach( $t_plugins as $t_plugin => $t_version ) { |
| 42 | + $t_message .= "- $t_plugin $t_version\n"; |
| 43 | +} |
| 44 | + |
| 45 | +// Create Tag |
| 46 | +exec( "git tag -s $t_tag -m '$t_message' 2>&1", $t_output, $t_result ); |
| 47 | +if( $t_result ) { |
| 48 | + echo "ERROR: Tag creation failed\n"; |
| 49 | + foreach( $t_output as $t_line ) { |
| 50 | + echo $t_line . "\n"; |
| 51 | + } |
| 52 | + exit( 1 ); |
| 53 | +} |
| 54 | +echo "Tag $t_tag created\n"; |
| 55 | + |
| 56 | + |
| 57 | +// --------------------------------------------------------------------------- |
| 58 | +// Helper functions |
| 59 | +// |
| 60 | + |
| 61 | +/** |
| 62 | + * Load VCS plugin base |
| 63 | + * @param string $p_basename |
| 64 | + * @return bool |
| 65 | + */ |
| 66 | +function plugin_load_class( $p_basename ) { |
| 67 | + $t_path = $p_basename . '/' . $p_basename . '.php'; |
| 68 | + |
| 69 | + // Suppressing errors since we don't need to actually run the classes |
| 70 | + $t_result = @include_once $t_path; |
| 71 | + |
| 72 | + if( !$t_result ) { |
| 73 | + echo "Failed to load $p_basename\n"; |
| 74 | + return false; |
| 75 | + } |
| 76 | + return $t_result; |
| 77 | +} |
| 78 | + |
| 79 | +/** |
| 80 | + * Returns the given plugin's version number |
| 81 | + * @param string $p_basename |
| 82 | + * @return string |
| 83 | + */ |
| 84 | +function plugin_get_version( $p_basename ) { |
| 85 | + $t_class = $p_basename . 'Plugin'; |
| 86 | + return $t_class::PLUGIN_VERSION; |
| 87 | +} |
| 88 | + |
| 89 | +/** |
| 90 | + * Return MantisBT root dir |
| 91 | + * @return string |
| 92 | + */ |
| 93 | +function get_mantis_root() { |
| 94 | + global $g_mantis_root; |
| 95 | + $g_mantis_root = rtrim( $g_mantis_root, '/' ) . '/'; |
| 96 | + |
| 97 | + if( file_exists( $g_mantis_root . 'core.php' ) ) { |
| 98 | + return $g_mantis_root; |
| 99 | + } |
| 100 | + |
| 101 | + die( "ERROR: MantisBT not found in '$g_mantis_root'\n" ); |
| 102 | +} |
| 103 | + |
| 104 | +/** |
| 105 | + * Fake Mantis core functions. |
| 106 | + * - config_get() |
| 107 | + * - config_get_global() |
| 108 | + * - require_api() |
| 109 | + * - require_lib |
| 110 | + * These are required so that the Source Integration classes can be initialized |
| 111 | + * without actually loading the Mantis core. |
| 112 | + */ |
| 113 | +function config_get( $p_string ) { |
| 114 | + if( $p_string == 'plugin_path' ) { |
| 115 | + return getcwd() . '/'; |
| 116 | + } else { |
| 117 | + return config_get_global( $p_string ); |
| 118 | + } |
| 119 | +} |
| 120 | + |
| 121 | +function config_get_global( $p_string ) { |
| 122 | + $t_root = get_mantis_root() . 'core/'; |
| 123 | + |
| 124 | + switch( $p_string ) { |
| 125 | + case 'core_path': |
| 126 | + return $t_root; |
| 127 | + case 'class_path': |
| 128 | + return $t_root . 'classes/'; |
| 129 | + } |
| 130 | + return null; |
| 131 | +} |
| 132 | + |
| 133 | +function require_api( $p_path ) { |
| 134 | + return; |
| 135 | +} |
| 136 | + |
| 137 | +function require_lib( $p_path ) { |
| 138 | + return; |
| 139 | +} |
0 commit comments