| 1 | #!/bin/bash |
| 2 | ############################################################################### |
| 3 | # Copyright (c) 2016 Ericsson |
| 4 | # |
| 5 | # All rights reserved. This program and the accompanying materials |
| 6 | # are made available under the terms of the Eclipse Public License v1.0 |
| 7 | # which accompanies this distribution, and is available at |
| 8 | # http://www.eclipse.org/legal/epl-v10.html |
| 9 | ############################################################################### |
| 10 | |
| 11 | # A script that checks every plugin for modifications since last release |
| 12 | # and prompt to bump the micro version if necessary. |
| 13 | # |
| 14 | # Usage ./check_plugins_changes.sh [ignoredCommit1,ignoredCommit2,...] |
| 15 | # |
| 16 | # Where ignoredcommit is a 7 characters commit hash which will not be |
| 17 | # considered in the diffs (useful for big commits that didn't affect code) |
| 18 | # |
| 19 | # For example ./check_plugins_changes.sh 1325468,1325469 |
| 20 | |
| 21 | IFS=', ' read -r -a IGNORED_COMMITS <<< "$1" |
| 22 | |
| 23 | PREV_RELEASE_VERSION=$(git tag -l | tail -1 | cut -c 2-) |
| 24 | echo "Baseline version detected: $PREV_RELEASE_VERSION. If this is wrong, stop the script (Ctrl-C)" |
| 25 | read -rsp $'Press any key to continue...\n' -n1 key |
| 26 | |
| 27 | # Stats for the summary |
| 28 | num_new_plugins=0 |
| 29 | num_bumped_already=0 |
| 30 | num_bumped=0 |
| 31 | num_not_bumped=0 |
| 32 | num_no_bump_needed=0 |
| 33 | |
| 34 | ALL_PLUGIN_PATHS=($(dirname $(dirname $(find ../.. -name "MANIFEST.MF")))) |
| 35 | |
| 36 | #For each plugin |
| 37 | for plugin_path in "${ALL_PLUGIN_PATHS[@]}"; do |
| 38 | |
| 39 | commit_summary=$(git log --oneline --max-count=1 -- $plugin_path) |
| 40 | commit_id=$(echo $commit_summary | awk '{print $1}') |
| 41 | |
| 42 | # Check if the commit we are about to consider should be ignored |
| 43 | # and choose a better one if that's the case. |
| 44 | check_ignored_commit=1 |
| 45 | while [ $check_ignored_commit -eq 1 ]; do |
| 46 | check_ignored_commit=0 |
| 47 | for ignored_commit in "${IGNORED_COMMITS[@]}"; do |
| 48 | if [ "$ignored_commit" = "$commit_id" ] |
| 49 | then |
| 50 | echo Ignoring commit $commit_id |
| 51 | commit_summary=$(git log $commit_id~1 --oneline --max-count=1 -- "$plugin_path") |
| 52 | commit_id=$(echo $commit_summary | awk '{print $1}') |
| 53 | echo New commit: $commit_id |
| 54 | check_ignored_commit=1 |
| 55 | fi |
| 56 | done |
| 57 | done |
| 58 | |
| 59 | manifest_diff=$(git diff v$PREV_RELEASE_VERSION -- $plugin_path/META-INF/MANIFEST.MF) |
| 60 | is_new_file=$(echo "$manifest_diff" | grep "\-\-\- /dev/null") |
| 61 | |
| 62 | # We don't need to do anything for a new pluging that wasn't there |
| 63 | # before, the initial version is always good |
| 64 | if [[ -n "$is_new_file" ]] |
| 65 | then |
| 66 | echo "new plugin $plugin_path" |
| 67 | num_new_plugins=$((num_new_plugins+1)) |
| 68 | continue |
| 69 | fi |
| 70 | |
| 71 | old_version=$(echo "$manifest_diff" | grep "\-Bundle-Version" | cut -c 2-) |
| 72 | cur_version=$(grep Bundle-Version "$plugin_path/META-INF/MANIFEST.MF") |
| 73 | |
| 74 | plugin_diff=$(git diff v$PREV_RELEASE_VERSION $commit_id -- "$plugin_path") |
| 75 | # Is the plugin bump needed? Check if the last commit of the plugin matches the previous release tag |
| 76 | # or if there was no difference (aside from the ignored commits) |
| 77 | tags_containing=$(git tag --contains $commit_id) |
| 78 | if [[ -z "$plugin_diff" || ($tags_containing == *"$PREV_RELEASE_VERSION"*) ]] |
| 79 | then |
| 80 | echo "no update needed $plugin_path ($cur_version)" |
| 81 | num_no_bump_needed=$((num_no_bump_needed+1)) |
| 82 | continue |
| 83 | fi |
| 84 | |
| 85 | # Is the plugin already bumped? Check if versions are different |
| 86 | if [[ -n "$old_version" && ("$cur_version" != "$old_version") ]] |
| 87 | then |
| 88 | echo "bumped already $plugin_path ($old_version -> $cur_version)" |
| 89 | num_bumped_already=$((num_bumped_already+1)) |
| 90 | continue |
| 91 | fi |
| 92 | |
| 93 | # At this point, we have a potential version bump necessary. We will ask the user to decide what to do. |
| 94 | |
| 95 | cur_major_minor=$(echo $cur_version | sed -rn 's/Bundle-Version:\s([0-9][0-9]*\.[0-9][0-9]*).*/\1/p') |
| 96 | cur_micro=$(echo $cur_version | sed -rn 's/Bundle-Version:\s[0-9][0-9]*\.[0-9][0-9]*\.([0-9][0-9]*).*/\1/p') |
| 97 | next_micro=$cur_micro |
| 98 | let next_micro+=1 |
| 99 | git diff v$PREV_RELEASE_VERSION $commit_id -- "$plugin_path" |
| 100 | echo "Might need bump: $plugin_path ($cur_version) ($commit_summary)" |
| 101 | while true; do |
| 102 | read -p "Bump version from $cur_major_minor.$cur_micro to $cur_major_minor.$next_micro? (y/n) " answer |
| 103 | case $answer in |
| 104 | [Yy]* ) break;; |
| 105 | [Nn]* ) break;; |
| 106 | * ) echo "yes (y) or no (n).";; |
| 107 | esac |
| 108 | done |
| 109 | |
| 110 | if [[ $answer == "Y" || $answer == "y" ]] |
| 111 | then |
| 112 | num_bumped=$((num_bumped+1)) |
| 113 | sed -i -E 's/(Bundle-Version:\s)[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*(.*)/\1'$cur_major_minor.$next_micro'\2/g' "$plugin_path/META-INF/MANIFEST.MF" |
| 114 | else |
| 115 | num_not_bumped=$((num_not_bumped+1)) |
| 116 | fi |
| 117 | done |
| 118 | |
| 119 | # Print a little summary of how the plugins were processed |
| 120 | |
| 121 | echo Total plugins: ${#ALL_PLUGIN_PATHS[@]} |
| 122 | echo New: $num_new_plugins |
| 123 | echo Already bumped: $num_bumped_already |
| 124 | echo Bumped: $num_bumped |
| 125 | echo Not bumped by choice: $num_not_bumped |
| 126 | echo No bump needed: $num_no_bump_needed |
| 127 | |
| 128 | num_processed=$(($num_new_plugins + $num_bumped_already + $num_bumped + $num_not_bumped + $num_no_bump_needed)) |
| 129 | if [[ $num_processed -ne ${#ALL_PLUGIN_PATHS[@]} ]] |
| 130 | then |
| 131 | echo "Number of plugins processed mismatch! ($num_processed vs ${#ALL_PLUGIN_PATHS[@]})" |
| 132 | else |
| 133 | echo "All plugins processed." |
| 134 | fi |