This repository has been archived by the owner on Jun 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 195
/
Copy pathcheckversions.sh
executable file
·139 lines (122 loc) · 4.5 KB
/
checkversions.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#!/usr/bin/env bash
#
# Copyright (c) 2019 Intel Corporation
#
# SPDX-License-Identifier: Apache-2.0
#
# Check if our local component versions are out of date with their
# upstream repositories.
#
# Use the Debian uscan (https://manpages.debian.org/stretch/devscripts/uscan.1.en.html)
# to do the compare. As such, uscan format annotations are stored in our version.yaml
# file for any components that should be checked.
# The script recognises the following keys from the versions.yaml file:
# - 'uscan-url' - the url regexp used to scan for versions of the component
# - 'uscan-opts' - any additional opts (in the uscan watchfile) required to complete
# version processing, such as 'filenamemangle'.
#
# This script:
# - locates any uscan-url keys in the versions.toml file
# - locates any corresponding 'version' keys (at the same level/entry)
# - extracts any related 'uscan-opts' if present
# - constructs a uscan watchfile with the information
# - executes 'uscan' to gather results
# - parses the uscan results to determine if an update is available
# - tabulates the results and prints a report
# - returns the number of components that could be updated (fails) as the return value
runtime_repo="github.com/kata-containers/kata-containers"
runtime_repo_dir="$GOPATH/src/${runtime_repo}"
versions_file="${runtime_repo_dir}/versions.yaml"
YQ=$(which yq)
uscan_phrase="uscan-url"
# Store up the paths to all the checks that passed
declare -a check_passed
check_passed=()
# Store up the paths to all the checks that failed
declare -a check_failed
check_failed=()
# Associative array between path names (keys) and the current version
declare -A current_version
current_version=()
declare -A newest_version
newest_version=()
# Record number of passes (up to date) and fails (could be updated)
declare passes
declare fails
# Look in the yaml file handed to us to find uscan URLs.
# return a list of paths to the URL items.
# $1 - path to versions.yaml file.
#
extract_uscan_items() {
# We convert the yaml to json, as jq can then be used to extract a list of
# keys that container our identifying search phrase.
paths=$(${YQ} r -j "$1" | jq -r 'paths | join(".")' | grep "${uscan_phrase}$")
echo "$paths"
}
main() {
passes=0
fails=0
local paths=$(extract_uscan_items "$versions_file")
for path in $paths; do
# Find the root key path for this component
local rootname="${path%.$uscan_phrase}"
echo "Processing [$rootname]"
local versionpath="$rootname.version"
longversion=$(yq r $versions_file $versionpath)
# Strip any leading non-digit values - uscan deals with digit style versions
# and copes better without any prefixes
version=$(sed -E 's/^[^0-9]+//' <<< $longversion)
# store away to use in the report table
current_version[$path]="$version"
uscanurl=$(yq r $versions_file $path)
local optspath="$rootname.uscan-opts"
uscanopts=$(yq r $versions_file $optspath)
# uscan needs a 'version' entry at the top of its file. uscan currently always
# expects that to be version 4.
echo "version=4" > watchfile
if [ -n "$uscanopts" ] && [ "$uscanopts" != "null" ]; then
echo "$uscanopts \\" >> watchfile
fi
echo "$uscanurl" >> watchfile
# And run the uscan
result="$(uscan --report --package ${rootname} --upstream-version ${version} --watchfile watchfile 2>/dev/null)"
# Extract the latest version found
newversion="$(egrep -o 'remote site is (.*)+,' <<< $result | sed 's/remote site is //' | sed 's/,//')"
newest_version[$path]="$newversion"
# And note if that was marked as being 'Newer' than our current version
failure=$(grep Newer <<< $result)
# Store the results for later
if [ -n "$failure" ]; then
((fails++))
check_failed[${#check_failed[@]}]="$path"
else
((passes++))
check_passed[${#check_passed[@]}]="$path"
fi
done
}
# Generate a nice tabulated summary of the results.
results() {
printf "\n %3s: %40s %20s %20s\n" "Num" "Item" "Current Ver" "Upstream Ver"
if [ $passes -gt 0 ]; then
echo "PASSES:"
for (( index=0; index<$passes; index++ )); do
path="${check_passed[$index]}"
printf " %3d: %40s %20s %20s\n" "$index" "${check_passed[$index]}" "${current_version[$path]}" "${newest_version[$path]}"
done
fi
echo ""
if [ $fails -gt 0 ]; then
echo "FAILURES:"
for (( index=0; index<$fails; index++ )); do
path="${check_failed[$index]}"
printf " %3d: %40s %20s %20s\n" "$index" "${check_failed[$index]}" "${current_version[$path]}" "${newest_version[$path]}"
done
fi
echo ""
echo "PASSES: $passes"
echo "FAILS: $fails"
}
main
results
exit $fails