|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Copyright The containerd Authors. |
| 4 | + |
| 5 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | +# you may not use this file except in compliance with the License. |
| 7 | +# You may obtain a copy of the License at |
| 8 | + |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + |
| 11 | +# Unless required by applicable law or agreed to in writing, software |
| 12 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +# See the License for the specific language governing permissions and |
| 15 | +# limitations under the License. |
| 16 | + |
| 17 | + |
| 18 | +set -e |
| 19 | + |
| 20 | +COMMAND=$1 |
| 21 | + |
| 22 | +case "$COMMAND" in |
| 23 | + record) |
| 24 | + while read -r line; do |
| 25 | + hash=$(echo "$line" | grep -oE '[0-9a-f]{40}') |
| 26 | + path=$(echo "$line" | awk '{print $2}') |
| 27 | + if [ -n "$hash" ] && [ -n "$path" ]; then |
| 28 | + echo "$path $hash" |
| 29 | + fi |
| 30 | + done < <(git submodule status) |
| 31 | + ;; |
| 32 | + check) |
| 33 | + STATE_FILE=$2 |
| 34 | + REPORT_FILE=$3 |
| 35 | + if [ ! -f "$STATE_FILE" ]; then |
| 36 | + echo "Error: State file $STATE_FILE not found" >&2 |
| 37 | + exit 2 |
| 38 | + fi |
| 39 | + |
| 40 | + [ -n "$REPORT_FILE" ] && rm -f "$REPORT_FILE" |
| 41 | + |
| 42 | + declare -A old_hashes |
| 43 | + while read -r line; do |
| 44 | + path=$(echo "$line" | awk '{print $1}') |
| 45 | + hash=$(echo "$line" | awk '{print $2}') |
| 46 | + old_hashes["$path"]="$hash" |
| 47 | + done < "$STATE_FILE" |
| 48 | + |
| 49 | + has_relevant_changes=false |
| 50 | + |
| 51 | + while read -r line; do |
| 52 | + new_hash=$(echo "$line" | grep -oE '[0-9a-f]{40}') |
| 53 | + path=$(echo "$line" | awk '{print $2}') |
| 54 | + old_hash=${old_hashes["$path"]} |
| 55 | + |
| 56 | + if [ -n "$old_hash" ] && [ "$new_hash" != "$old_hash" ]; then |
| 57 | + echo "Submodule $path updated: $old_hash -> $new_hash" |
| 58 | + diff_output=$(git -C "$path" diff "$old_hash" "$new_hash" --name-only 2>/dev/null | grep -E "^(docs/|README\.md)" || true) |
| 59 | + if [ -n "$diff_output" ]; then |
| 60 | + echo "--> Relevant changes found in $path" |
| 61 | + has_relevant_changes=true |
| 62 | + if [ -n "$REPORT_FILE" ]; then |
| 63 | + echo "#### $path" >> "$REPORT_FILE" |
| 64 | + echo "$diff_output" | sed 's/^/- /' >> "$REPORT_FILE" |
| 65 | + echo "" >> "$REPORT_FILE" |
| 66 | + fi |
| 67 | + fi |
| 68 | + fi |
| 69 | + done < <(git submodule status) |
| 70 | + |
| 71 | + if [ "$has_relevant_changes" = true ]; then |
| 72 | + echo "Result: Relevant changes detected." |
| 73 | + exit 0 |
| 74 | + else |
| 75 | + echo "Result: No relevant changes." |
| 76 | + exit 1 |
| 77 | + fi |
| 78 | + ;; |
| 79 | + *) |
| 80 | + echo "Usage: $0 {record|check [state_file]}" >&2 |
| 81 | + exit 3 |
| 82 | + ;; |
| 83 | +esac |
0 commit comments