forked from angular/angularjs.org
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget-cdn-version.sh
executable file
·97 lines (83 loc) · 2.16 KB
/
get-cdn-version.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
#! /bin/sh
set -e
# returns e.g. 1.2.8
function getAngularVersions {
VERSION_PATTERN=$1
# result of ls-remote
# e.g. 0f9a1c21e6d7c57dc02842efa9612a1a70993146 refs/tags/v1.2.8^{}
# e.g. a7a660b65bceb7c93579469047b332e040afdf5b refs/tags/v1.2.9
git ls-remote https://github.com/angular/angular.js.git | while read line
do
if [[ $line =~ v([0-9].*[0-9])$ ]]; then
# a line like ...v1.2.9
# remove 'v' at begin of tag
# e.g. v1.3.0 -> 1.3.0
VERSION=${BASH_REMATCH[1]}
if [[ $VERSION == $VERSION_PATTERN ]]; then
log "found tag for $VERSION_PATTERN: $VERSION"
echo $VERSION
fi
fi
done
}
function sortBySemVer {
function sortBySortId() {
# e.g. 1.3.0.beta.1
# e.g. 1.3.0.zzz.99
sort -t"." -k1,1nr -k2,2nr -k3,3nr -k4,4r -k5,5nr
}
function addSortId {
while read VERSION
do
SORT_ID=$VERSION
# add -zzz.99 to non pre release versions
# e.g. 1.3.0 -> 1.3.0-zzz.99
if [[ $SORT_ID != *-* ]]; then
SORT_ID="$SORT_ID-zzz.99"
fi
# replace "-"" with ".""
# e.g. 1.3.0-beta.2 -> 1.3.0.beta.2
SORT_ID=${SORT_ID//-/.}
# e.g. 1.3.0.zzz.99:1.3.0
# e.g. 1.3.0.beta.2:1.3.0-beta.2
echo "$SORT_ID:$VERSION"
done
}
function removeSortId {
while read line
do
# get the part after the first colon (i.e. remove sortId)
# e.g. 1.3.0.beta.99:1.3.0 -> 1.3.0
echo ${line#*:}
done
}
addSortId | sortBySortId | removeSortId
}
function checkCDN {
while read VERSION
do
STATUS_CODE=$(curl http://ajax.googleapis.com/ajax/libs/angularjs/$VERSION/angular.min.js \
--head --write-out '%{http_code}' -o /dev/null -silent)
log "Checking version $VERSION on CDN: $STATUS_CODE"
if [[ $STATUS_CODE == "200" ]]; then
echo $VERSION
return
fi
done
log "No CDN version found"
exit 1
}
function log() {
echo "$@" >&2
}
# replaceInFile(file, findText, replaceText)
function replaceInFile {
sed -i .tmp "s/$2/$3/" $1
rm $1.tmp
}
BRANCH=$1
if [[ ! BRANCH ]]; then
log "Usage: $0 <BRANCH>, e.g. $0 1.2"
exit 1
fi
getAngularVersions "${BRANCH}.*" | sortBySemVer| checkCDN