|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# This script checks which plugins have changes since their last tagged release. |
| 4 | +# It is useful for determining which plugins need to be released. |
| 5 | + |
| 6 | +set -o errexit |
| 7 | +set -o nounset |
| 8 | +set -o pipefail |
| 9 | + |
| 10 | +SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" |
| 11 | +ROOT_DIR="$(dirname "$SCRIPT_DIR")" |
| 12 | + |
| 13 | +# Colors for output |
| 14 | +RED='\033[0;31m' |
| 15 | +GREEN='\033[0;32m' |
| 16 | +YELLOW='\033[0;33m' |
| 17 | +CYAN='\033[0;36m' |
| 18 | +NC='\033[0m' # No Color |
| 19 | + |
| 20 | +# Get all plugins from the plugins directory (exclude hidden dirs like .tox) |
| 21 | +all_plugins="$(cd "$ROOT_DIR/plugins" ; find . -mindepth 1 -maxdepth 1 -type d -not -name '.*' | sed 's|./||g' | sort)" |
| 22 | + |
| 23 | +verbose=false |
| 24 | +show_commits=false |
| 25 | + |
| 26 | +function usage() { |
| 27 | + echo "Check which plugins have changes since their last tagged release." |
| 28 | + echo "" |
| 29 | + echo "Usage: $0 [options] [plugin...]" |
| 30 | + echo "" |
| 31 | + echo "Options:" |
| 32 | + echo " -h, --help Show this help message" |
| 33 | + echo " -v, --verbose Show detailed information about changes" |
| 34 | + echo " -c, --commits Show commit messages for changed plugins" |
| 35 | + echo "" |
| 36 | + echo "If no plugins are specified, all plugins will be checked." |
| 37 | +} |
| 38 | + |
| 39 | +# Parse arguments |
| 40 | +plugins_to_check=() |
| 41 | +while (( $# > 0 )); do |
| 42 | + case "$1" in |
| 43 | + --help | -h) |
| 44 | + usage |
| 45 | + exit 0 |
| 46 | + ;; |
| 47 | + --verbose | -v) |
| 48 | + verbose=true |
| 49 | + ;; |
| 50 | + --commits | -c) |
| 51 | + show_commits=true |
| 52 | + ;; |
| 53 | + *) |
| 54 | + if grep -qE "^$1\$" <<< "$all_plugins"; then |
| 55 | + plugins_to_check+=("$1") |
| 56 | + else |
| 57 | + echo -e "${RED}Unknown plugin: $1${NC}" |
| 58 | + echo "Valid plugins are:" |
| 59 | + echo "$all_plugins" |
| 60 | + exit 1 |
| 61 | + fi |
| 62 | + ;; |
| 63 | + esac |
| 64 | + shift |
| 65 | +done |
| 66 | + |
| 67 | +# If no plugins specified, check all |
| 68 | +if [ ${#plugins_to_check[@]} -eq 0 ]; then |
| 69 | + while IFS= read -r line; do |
| 70 | + plugins_to_check+=("$line") |
| 71 | + done <<< "$all_plugins" |
| 72 | +fi |
| 73 | + |
| 74 | +cd "$ROOT_DIR" |
| 75 | + |
| 76 | +changed_plugins=() |
| 77 | +unchanged_plugins=() |
| 78 | +untagged_plugins=() |
| 79 | + |
| 80 | +for plugin in "${plugins_to_check[@]}"; do |
| 81 | + # Skip empty lines |
| 82 | + [ -z "$plugin" ] && continue |
| 83 | + |
| 84 | + plugin_path="plugins/$plugin" |
| 85 | + |
| 86 | + # Check if plugin directory exists |
| 87 | + if [ ! -d "$plugin_path" ]; then |
| 88 | + if $verbose; then |
| 89 | + echo -e "${YELLOW}Skipping $plugin: directory not found${NC}" |
| 90 | + fi |
| 91 | + continue |
| 92 | + fi |
| 93 | + |
| 94 | + # Find the latest tag for this plugin |
| 95 | + latest_tag=$(git tag --list "${plugin}-v*" --sort=-v:refname | head -1) |
| 96 | + |
| 97 | + if [ -z "$latest_tag" ]; then |
| 98 | + untagged_plugins+=("$plugin") |
| 99 | + if $verbose; then |
| 100 | + echo -e "${YELLOW}$plugin: No tags found${NC}" |
| 101 | + fi |
| 102 | + continue |
| 103 | + fi |
| 104 | + |
| 105 | + # Count commits to the plugin directory since the last tag |
| 106 | + # Exclude version bump commits (chore(version): update ... version to *.dev0) |
| 107 | + commit_count=$(git log --oneline "${latest_tag}..HEAD" -- "$plugin_path" | grep -cvE "^[a-f0-9]+ chore\(version\): update .* version to .*\.dev0$" || true) |
| 108 | + |
| 109 | + if [ "$commit_count" -gt 0 ]; then |
| 110 | + changed_plugins+=("$plugin") |
| 111 | + if $verbose; then |
| 112 | + echo -e "${GREEN}$plugin: $commit_count commit(s) since $latest_tag${NC}" |
| 113 | + fi |
| 114 | + if $show_commits; then |
| 115 | + echo -e "${CYAN} Commits since $latest_tag:${NC}" |
| 116 | + git log --oneline "${latest_tag}..HEAD" -- "$plugin_path" | grep -vE "^[a-f0-9]+ chore\(version\): update .* version to .*\.dev0$" | sed 's/^/ /' |
| 117 | + echo "" |
| 118 | + fi |
| 119 | + else |
| 120 | + unchanged_plugins+=("$plugin") |
| 121 | + if $verbose; then |
| 122 | + echo -e "${NC}$plugin: No changes since $latest_tag${NC}" |
| 123 | + fi |
| 124 | + fi |
| 125 | +done |
| 126 | + |
| 127 | +# Summary |
| 128 | +echo "" |
| 129 | +echo "========================================" |
| 130 | +echo " Summary" |
| 131 | +echo "========================================" |
| 132 | + |
| 133 | +if [ ${#changed_plugins[@]} -gt 0 ]; then |
| 134 | + echo -e "${GREEN}Plugins with changes (${#changed_plugins[@]}):${NC}" |
| 135 | + for plugin in "${changed_plugins[@]}"; do |
| 136 | + latest_tag=$(git tag --list "${plugin}-v*" --sort=-v:refname | head -1) |
| 137 | + commit_count=$(git log --oneline "${latest_tag}..HEAD" -- "plugins/$plugin" | grep -cvE "^[a-f0-9]+ chore\(version\): update .* version to .*\.dev0$" || true) |
| 138 | + echo -e " ${GREEN}✓${NC} $plugin ($commit_count commits since $latest_tag)" |
| 139 | + done |
| 140 | + echo "" |
| 141 | +fi |
| 142 | + |
| 143 | +if [ ${#untagged_plugins[@]} -gt 0 ]; then |
| 144 | + echo -e "${YELLOW}Plugins without any tags (${#untagged_plugins[@]}):${NC}" |
| 145 | + for plugin in "${untagged_plugins[@]}"; do |
| 146 | + echo -e " ${YELLOW}?${NC} $plugin" |
| 147 | + done |
| 148 | + echo "" |
| 149 | +fi |
| 150 | + |
| 151 | +if [ ${#unchanged_plugins[@]} -gt 0 ] && $verbose; then |
| 152 | + echo -e "Plugins with no changes (${#unchanged_plugins[@]}):" |
| 153 | + for plugin in "${unchanged_plugins[@]}"; do |
| 154 | + latest_tag=$(git tag --list "${plugin}-v*" --sort=-v:refname | head -1) |
| 155 | + echo " - $plugin (latest: $latest_tag)" |
| 156 | + done |
| 157 | + echo "" |
| 158 | +fi |
| 159 | + |
| 160 | +# Suggest release commands |
| 161 | +if [ ${#changed_plugins[@]} -gt 0 ]; then |
| 162 | + echo "========================================" |
| 163 | + echo " Suggested Release Commands" |
| 164 | + echo "========================================" |
| 165 | + for plugin in "${changed_plugins[@]}"; do |
| 166 | + echo " tools/release.sh $plugin" |
| 167 | + done |
| 168 | + echo "" |
| 169 | +fi |
0 commit comments