forked from git-for-windows/build-extra
-
Notifications
You must be signed in to change notification settings - Fork 0
/
render-release-notes.sh
executable file
·148 lines (128 loc) · 4.51 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
#!/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:git@vger.kernel.org &&
links="$(printf "%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n" \
'<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>')" &&
printf '%s\n%s\n%s\n%s %s\n%s %s\n%s\n%s\n%s\n%s\n' \
'<!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">' \
"$links" \
'<div class="content">'
markdown "$SCRIPT_PATH"/ReleaseNotes.md ||
die "Could not generate ReleaseNotes.html"
printf '</div>\n</body>\n</html>\n') >"$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 ||
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"