-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
make-or-update-release.sh
executable file
·121 lines (110 loc) · 3.14 KB
/
make-or-update-release.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
#!/bin/bash
### Script setup
set -e
W=$(dirname $(readlink -f $0))
### Tools
resolve-lesson() {
if [[ ${1:0:3} == 'dc:' ]] ; then
printf %s "https://github.com/datacarpentry/${1:3}.git"
else
printf %s "https://github.com/swcarpentry/$1"
fi
}
is-tag() {
if test "$2" = v5.3 ; then
true
return
fi
# might need auth... to avoid rate limits
curl -s "${1/github.com/api.github.com\/repos}/git/refs/tags/$2" | grep -q '"ref"'
}
is-branch() {
if test "$2" = v5.3 ; then
false
return
fi
curl -s "${1/github.com/api.github.com\/repos}/git/refs/heads/$2" | grep -q '"ref"'
}
fail() {
echo "... fail"
exit
}
progress() {
echo " #### $@"
}
ensure-git-version-is-at-least() {
local v
v=$(git version | awk '{print $NF}' | tr -d '.')
if test "$v" -lt "$1" ; then
echo "Expected git version at least $1, found $v"
false
fi
}
#if [ "$(pwd)" = "$W" ] ; then
# echo "This script should probably not be run run from the $W folder, but rather from its parent."
# exit
#fi
if [ $# -lt 2 ] ; then
echo "Requires a release name and a list of lessons (can be empty for updates)"
exit
fi
TARGET=$1
shift
TAG=${TAG-$TARGET}
progress "- Working on release '${TAG}' in folder '${TARGET}'."
if [ "${ONLYHTML}" != "" ] ; then
progress "- ONLYHTML is set, skipping generation/update"
cd "${TARGET}"
elif [ -d ${TARGET} ] ; then
progress "- Folder '${TARGET} is present, making an update"
progress "- TODO"
cd "${TARGET}"
else
progress "- Folder '${TARGET}' is absent, making it and starting a new release"
mkdir "${TARGET}"
cd "${TARGET}"
progress "- Trying to add submodules for each lesson"
for L in "$@"; do
progress " - Adding submodule for lesson '$L'"
l=$(resolve-lesson "$L")
if is-branch "$l" "$TAG" ; then
ensure-git-version-is-at-least 182 # for submodule with branch
progress " - it is a branch, adding a tracking submodule"
git submodule add --force -b "$TAG" "$l"
elif is-tag "$l" "$TAG" ; then
progress " - it is a tag, adding a simple submodule"
# the "--force" avoids recloning every time we try the script
git submodule add --force "$l"
(cd "$L" && git checkout "$TAG")
else
progress "$TAG is neither a branch nor a tag"
fail
fi
done
fi
progress "- Now (re)generating the index"
progress " - making the dummy HTML index"
cat <<EOF > index.html
<!doctype html>
<html class="no-js" lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
</head>
<body>
<ul>
EOF
for L in "$@"; do
echo "<li><a href='$L/index.html'>$L (${TAG})</a></li>" >> index.html
done
echo " </ul>" >> index.html
echo "</body>" >> index.html
progress " - adding index.html to git"
git add index.html
progress "- FINISHED WITH NO ERRORS"
progress " you may review it and commit/push, e.g., with"
progress ""
progress " git status"
progress " git commit -m 'Release ${TAG}'"
progress " git push"
progress ""