-
Notifications
You must be signed in to change notification settings - Fork 612
/
render-release-notes.sh
executable file
·229 lines (201 loc) · 6.66 KB
/
render-release-notes.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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
#!/bin/sh
usage () {
cat<<EOF
Usage: $0 [--output <dir>] [--css <dir>] [--copy-css | --preview]
If this script is executed without specifying any arguments, ReleaseNotes.html
will be generated in the present working directory and the corresponding
ReleaseNotes.css stylesheet will be copied to the present working directory as
well.
--output <dir>
Use this argument to specify the output directory for the generated
ReleaseNotes.html file. The default location is the present working
directory.
--css <dir>
Specifies the directory portion of the CSS stylesheet path to render
for the @href attribute of the <link /> element in the Release Notes
HTML file. The specified path will be taken relative to the path
specified for the --output argument. If a value is not provided for
this option, the CSS path will default to the path provided for
--output.
--copy-css
Instructs this script to also copy the CSS stylesheet to the directory
specified by the --css argument (or if not specified, the directory
specified by the --output argument).
When rendering the release notes as part of an installer package, it is
not necessary to copy the CSS stylesheet. The installer builders should
ensure that the CSS stylesheet is installed to the appropriate location
to allow for proper release notes styling when viewing them in a
browser.
--preview
This option implies the usage of --copy-css. After generating
ReleaseNotes.html, the script will open ReleaseNotes.html in your
default web browser.
EXAMPLE:
========
$0 --output ~/ --css styles --copy-css
In this example, the ReleaseNotes.html file will be rendered to the
current user's home directory. The HTML file will be rendered to look
for its CSS stylesheet at ~/styles. Due to --copy-css being specified,
ReleaseNotes.css will be copied to ~/styles so that when viewing the
release notes in a browser, the release notes are properly styled.
EOF
exit
}
die () {
echo "$*" >&2
exit 1
}
render_release_notes () {
(homepage=https://gitforwindows.org/ &&
contribute=$homepage#contribute &&
wiki=https://github.com/git-for-windows/git/wiki &&
faq=$wiki/FAQ &&
mailinglist=mailto:[email protected] &&
cat <<-EOF &&
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=UTF-8">
<link rel="stylesheet"
href="$CSSDIR${CSSDIR:+/}ReleaseNotes.css">
</head>
<body class="details">
<div class="links">
<ul>
<li><a href="$homepage">homepage</a></li>
<li><a href="$faq">faq</a></li>
<li><a href="$contribute">contribute</a></li>
<li><a href="$contribute">bugs</a></li>
<li><a href="$mailinglist">questions</a></li>
</ul>
<div id="git-for-windows-logo">
<div id="left-pane"></div>
<div id="top-pane"></div>
<div id="right-pane"></div>
<div id="bottom-pane"></div>
<div id="diagonal-pipe"></div>
<div id="vertical-pipe"></div>
<div id="top-ball"></div>
<div id="bottom-ball"></div>
<div id="right-ball"></div>
</div>
</div>
<div class="content">
EOF
body="$(markdown "$SCRIPT_PATH"/ReleaseNotes.md)" ||
die "Could not generate ReleaseNotes.html"
echo "$body" | perl -pe '
s/^(<h1)(>Known issues)/\1 id="known-issues" class="collapsible"\2/;
s/^(<h2)(>Licenses.*)/\1 id="licenses" class="collapsible"\2<div>/;
$v = $1 if (/<h1>Git for Windows (\S+)/);
if ((/^<h2>Changes since (Git for Windows ([^ <]*)|(Win)?Git-([^ <]*))/)) {
$previous_version = $2 ? $2 : "v$4";
if ($v eq $previous_version) {
# in-between version
$v = "snapshot"
}
s/^<h2>Changes since (?:Git(?: for Windows|-))(.*)/<h2>Changes in $v<br \/><small>since \1<\/small>/;
if (!$latest) {
s/>[^<]*/><a name="latest"$&<\/a>/;
$latest = 1;
}
$nr = 0 if (!$nr);
$nr++;
$id = $v;
s/^<h2>/<h2 id="$id" nr="$nr" class="collapsible"> /;
$v = $previous_version;
s/.*/<\/div>$&<div>/;
}'
cat <<-\EOF
</div>
</div>
<script>
(() => {
const hideEl = window.location.hash && window.location.hash != '#latest' ?
(el) => "#" + el.id !== window.location.hash :
(el) => el.getAttribute('nr') !== '1';
for (let el of document.getElementsByClassName('collapsible')) {
let arrow = document.createElement('div');
arrow.innerHTML = '▽';
arrow.style.float = 'left';
arrow.style.position = 'relative';
arrow.style.left = '-1em';
arrow.style.top = '+1.5em';
arrow.style.fontSize = 'larger';
arrow.style.cursor = 'pointer';
const toggle = () => {
// this.classList.toggle('active');
let details = el.nextElementSibling;
if (details.style.display === 'none') {
details.style.display = 'block';
arrow.innerHTML = '▽';
} else {
details.style.display = 'none';
arrow.innerHTML = '▷';
}
};
if (hideEl(el)) {
toggle();
}
el.addEventListener('click', toggle);
arrow.addEventListener('click', toggle);
el.parentElement.insertBefore(arrow, el);
}
})();
</script>
</body>
</html>
EOF
) >"$OUTPUTDIR${OUTPUTDIR:+/}ReleaseNotes.html"
}
COPYCSS=
PREVIEW=
test $# -eq 0 && COPYCSS=1 || {
while test $# -gt 0
do
case "$1" in
--copy-css)
COPYCSS=1
;;
--css)
shift
CSSDIR="${1%/}"
;;
--output)
shift
OUTPUTDIR="${1%/}"
;;
--preview|-p)
PREVIEW=1
COPYCSS=1
;;
--help|*)
usage
;;
esac
shift
done
}
SCRIPT_PATH="$(cd "$(dirname "$0")" && pwd)"
# Generate the ReleaseNotes.html file
test -x /usr/bin/markdown ||
export PATH="$PATH:$(readlink -f "$SCRIPT_PATH")/../../bin"
# Install markdown
type markdown ||
pacman -Sy --noconfirm markdown ||
pacman -S --noconfirm markdown ||
die "Could not install markdown"
test -f "$OUTPUTDIR${OUTPUTDIR:+/}Release.html" &&
test "$OUTPUTDIR${OUTPUTDIR:+/}Release.html" -nt "$SCRIPT_PATH"/ReleaseNotes.md &&
test "$OUTPUTDIR${OUTPUTDIR:+/}Release.html" -nt "$SCRIPT_PATH"/render-release-notes.sh || {
render_release_notes || die "Could not render $OUTPUTDIR${OUTPUTDIR:+/}ReleaseNotes.html"
test -z "$COPYCSS" || {
test -z "$CSSDIR" && CSSDIR="$OUTPUTDIR" || CSSDIR="$OUTPUTDIR${OUTPUTDIR:+/}$CSSDIR"
test -z "$CSSDIR" || test -d "$CSSDIR" || mkdir -p "$CSSDIR"
test -n "$CSSDIR" || CSSDIR="$PWD"
test "x$SCRIPT_PATH" = "x$CSSDIR" ||
cp -u "$SCRIPT_PATH"/ReleaseNotes.css "$CSSDIR${CSSDIR:+/}ReleaseNotes.css"
}
}
test -z "$PREVIEW" || start "$OUTPUTDIR${OUTPUTDIR:+/}ReleaseNotes.html"