summaryrefslogtreecommitdiff
path: root/scripts/mk-release.sh
blob: 16a66c02d22d8576d8eb9f74a97080b9d84d14de (plain)
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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
#!/bin/bash
#set -x

export LC_ALL=C

my_name="$( basename "${0}" )"

usage() {
    cat <<-_EOF_
		Usage:
		    ${my_name} <repos_dir> <M.m.p>
	_EOF_
}

repos="${1}"
version="${2}"

[ -n "${repos}"   ] || { usage; exit 1; }
[ -d "${repos}"   ] || { printf "${my_name}: ${repos}: no such file or directory\n"; exit 1; }
[ -n "${version}" ] || { usage; exit 1; }

_hg() {
    HGPLAIN=1 hg --config progress.disabled=true "$@"
}

gen_bound_revs() {
    r1=$( _hg log   \
          |awk 'BEGIN {
                  found=0;
                }
                $1=="'"${label}"':" {
                  split($2,a,":"); rev=a[1];
                }
                $0~/^summary:[[:space:]]*[[:digit:]]+\.[[:digit:]]+: '"${msg}"'/ \
                && found==0 {
                  printf( "%d\n", rev ); found=1;
                }'
        )

    r2=$( _hg log -b "${branch}" \
          |awk '$1=="changeset:" {
                  split($2,a,":");
                  printf( "%d\n", a[1] );
                  nextfile;
                }'
        )

    r1_log=$((r1+log_offset))
    if [ ${#r1_log} -gt ${#r2} ]; then
        rev_w=${#r1_log}
    else
        rev_w=${#r2}
    fi
}

print_intro_mail() {
    cat <<-_EOF_
		Hello all!
		
		I'm pleased to announce the release of crosstool-NG ${version}!
		
		As usual, there has been quite a number of improvements, new features,
		and bug fixes all around. The most notable changes are listed below:
		
		YEM:
		YEM: PUT YOUR MESSAGE HERE
		YEM:
		
		This marks the beginning of the ${ver_M}.${ver_m} maintenance branch, and the end of
		the previous maintenance branch. As always, comments and suggestions
		are most welcome!
		
		The release can be found at the following URLs:
		Changelog: http://crosstool-ng.org/download/crosstool-ng/crosstool-ng-${version}.changelog
		Tarball:   http://crosstool-ng.org/download/crosstool-ng/crosstool-ng-${version}.tar.bz2
		Patches:   http://crosstool-ng.org/download/crosstool-ng/01-fixes/${version}/
		
		As a reminder, the home for crosstool-NG is:
		http://crosstool-ng.org/
		
		Crosstool-NG also has a Freshmeat page:
		http://freshmeat.net/projects/crosstool-ng
	_EOF_
}

print_intro_changelog_full_release() {
    cat <<-_EOF_
		crosstool-NG ${version} -- ${date}
		
		This is a feature-release. Significant changes are:
		
		YEM:
		YEM: PUT YOUR MESSAGE HERE
		YEM:
	_EOF_
}

print_intro_changelog_bug_fix() {
    cat <<-_EOF_
		crosstool-NG ${version} -- ${date}
		
		This is a bug-fix-only release.
	_EOF_
}

print_author_stats() {
    printf "\nMany thanks to the people who contributed to this release:\n\n"
    prev_author=""
    template='{author|person}\n'
    _hg log -b "${branch}" -r "${r1_log}:${r2}"                 \
           --template "${template}"                             \
    |sed -r -e 's/"//g;'                                        \
    |awk -F '' '{
                  nb[$0]++;
                }
                END {
                  for( author in nb ) {
                    printf( "   %4d  %s\n", nb[author], author );
                  }
                }'                                              \
    |sort -s -k1nr -k2
}

print_author_shortlog() {
    printf "\nHere is the per-author shortlog:\n"
    prev_author=""
    template='{author|person}|{rev}|{branches}|{desc|firstline}\n'
    _hg log -b "${branch}" -r "${r1_log}:${r2}"             \
           --template "${template}"                         \
    |awk -F '' '{
                  n=split( $0,a,"|" );
                  printf( "%s", gensub("\"","","g",a[1]) );
                  printf( "|%0*d", '${rev_w}', a[2] );
                  for(i=3;i<=n;i++) {
                    printf( "|%s", a[i] );
                  }
                  printf( "\n" );
                }'                                          \
    |sort                                                   \
    |while read line; do
        author="$( echo "${line}" |cut -d \| -f 1 )"
        rev="$( echo "${line}" |cut -d \| -f 2 )"
        br="$( echo "${line}" |cut -d \| -f 3 )"
        desc="$( echo "${line}" |cut -d \| -f 4- )"

        case "${br}" in
            ${branch})  ;;
            [0-9]*.*)    continue;;
            *) ;;
        esac

        case "${desc}" in
            Merge.)                 continue;;
            *": close "*" branch"*) continue;;
#           *\(merged\))            continue;;
        esac

        author="$( echo "${author}" |sed -r -e 's/"//g;' )"

        if [ ! "${prev_author}" = "${author}" ]; then
            printf "\n"
            printf "    ${author}:\n"
            prev_author="${author}"
        fi
        rev="$( echo "${rev}" |sed -r -e 's/^0*//;' )"

        printf "%s\n" "${desc}"     \
        |fmt -w 65                  \
        |(first=1; while read l; do
            if [ -n "${first}" ]; then
                printf "        [%*d] %s\n" ${rev_w} ${rev} "${l}"
                first=
            else
                printf "         %*.*s  %s\n" ${rev_w} ${rev_w} '' "${l}"
            fi
        done)
    done
}

print_diffstat() {
    printf "\nThe diffstat follows:\n\n"
    _hg diff -r "${r1}:${r2}" --color=never \
    |diffstat -r 2 -p 1 -w 10               \
    |tail -n 1                              \
    |sed -r -e 's/^ */    /;'

    _hg diff -r "${r1}:${r2}" --color=never \
    |diffstat -f 1 -r 2 -p 1 -w 10          \
    |head -n -1                             \
    |while read file line; do
        if [ ${#file} -gt 57 ]; then
            file="$( echo "${file}" |sed -r -e 's/^(.{,24}).*(.{28})$/\1.....\2/;' )"
        fi
        printf "    %-57s %s\n" "${file}" "${line}"
    done
}

print_short_diffstat() {
    printf "\nThe short diffstat follows:\n\n"

    eval total=$(( $(
        _hg diff -r "${r1}:${r2}" --color=never "${i}"                              \
        |diffstat -r 2 -p 1 -w 10                                                   \
        |tail -n 1                                                                  \
        |sed -r -e 's/^[[:space:]]*[[:digit:]]+ files? changed(,[[:space:]]+|$)//;' \
                -e 's/([[:digit:]]+)[^-\+]+\((-|\+)\)/\1/g;'                        \
                -e 's/,//g; s/ /+/; s/^$/0/;'
    ) ))
    printf "    %-24.24s %5d(+/-)\n" "Total" ${total}
    others=${total}

    { for i in              \
        kconfig/            \
        patches/            \
        config/*/           \
        scripts/build/*/    \
        samples/            \
        ; do
        eval val=$(( $(
            _hg diff -r "${r1}:${r2}" --color=never "${i}"                              \
            |diffstat -r 2 -p 1 -w 10                                                   \
            |tail -n 1                                                                  \
            |sed -r -e 's/^[[:space:]]*[[:digit:]]+ files? changed(,[[:space:]]+|$)//;' \
                    -e 's/([[:digit:]]+)[^-\+]+\((-|\+)\)/\1/g;'                        \
                    -e 's/,//g; s/ /+/; s/^$/0/;'
        ) ))
        if [ ${val} -gt $((total/100)) ]; then
            printf "%d %s\n" $(((1000*val)/total)) "${i}"
            others=$((others-val))
        fi
    done; printf "%d Others\n" $(((1000*others)/total)); }  \
    |sort -nr                                               \
    |{ while read v i; do
        if [ "${i}" = "Others" ]; then
            others=${v}
        else
            printf "    %-24.24s %3d.%d%%\n" "${i}" $((v/10)) $((v%10))
        fi
       done; printf "    %-24.24s %3d.%d%%\n" "Others" $((others/10)) $((others%10)); }
}

ver_M="$( printf "${version}" |cut -d . -f 1 )"
ver_m="$( printf "${version}" |cut -d . -f 2 )"
ver_p="$( printf "${version}" |cut -d . -f 3 )"

sob_line="$( printf "Signed-off-by: "; _hg debugconfig ui.username )"
prefix="$(pwd)/crosstool-ng-${version}"
pushd "${repos}" >/dev/null 2>&1

printf "Checking for existing tag: "
if _hg tags |grep -E '^'"crosstool-ng-${version}"'\>' >/dev/null; then
    printf "already tagged\n"
    exit 1
fi
printf "no\n"

if [ ${ver_p} -eq 0 ]; then
    print_mail="yes"
    print_intro_changelog="print_intro_changelog_full_release"
    label="parent"
    msg="create maintenance branch, (update|bump) version to [[:digit:]]+"'\'".[[:digit:]]+"'\'".0"'$'
    branch="default"
    log_offset=0
else
    print_mail="no"
    print_intro_changelog="print_intro_changelog_bug_fix"
    label="changeset"
    msg="(update|bump) version to ${ver_M}"'\'".${ver_m}"'\'".$((ver_p-1))"'\+hg$'
    branch="${ver_M}.${ver_m}"
    log_offset=1
fi

printf "Computing boundary revisions:"
gen_bound_revs
printf " %d:%d\n" ${r1} ${r2}

printf "Tagging release:"
_hg up "${branch}" >/dev/null
if [ ${ver_p} -eq 0 ]; then
    printf " update version"
    _hg branch "${ver_M}.${ver_m}" >/dev/null
    echo "${version}" >".version"
    _msg="$( printf "%s.%s: create maintenance branch, update version to %s\n\n%s" \
                    "${ver_M}" "${ver_m}" "${version}" "${sob_line}"
           )"
    _hg ci -m "${_msg}"
else
    printf " update version"
    echo "${version}" >".version"
    _msg="$( printf "%s.%s: update version to %s\n\n%s" \
                    "${ver_M}" "${ver_m}" "${version}" "${sob_line}"
           )"
    _hg ci -m "${_msg}"
fi

printf ", tag"
_msg="$( printf "Tagging release %s\n\n%s" "${version}" "${sob_line}" )"
_hg tag -m "${_msg}" crosstool-ng-${version}

printf ", update version"
echo "${version}+hg" >".version"
_msg="$( printf "%s.%s: update version to %s+hg\n\n%s" \
                "${ver_M}" "${ver_m}" "${version}" "${sob_line}"
       )"
_hg ci -m "${_msg}"

printf ", date"
date="$( _hg log -r crosstool-ng-${version} --template '{date|isodate}\n'    \
         |sed -r -e 's/-|://g; s/ /./; s/ //;'                              \
       )"
printf ", done.\n"

if [ ${ver_p} -eq 0 ]; then
    printf "Generating release mail:"
    printf " intro"
    print_intro_mail        > "${prefix}.mail"
    printf ", stats"
    print_author_stats      >>"${prefix}.mail"
    printf ", shortlog"
    print_author_shortlog   >>"${prefix}.mail"
    printf ", diffstat"
    print_short_diffstat    >>"${prefix}.mail"
    printf ", done.\n"
fi

printf "Generating release changelog:"
printf " intro"
${print_intro_changelog}    > "${prefix}.changelog"
printf ", stats"
print_author_stats          >>"${prefix}.changelog"
printf ", shortlog"
print_author_shortlog       >>"${prefix}.changelog"
printf ", diffstat"
print_diffstat              >>"${prefix}.changelog"
printf ", done.\n"

popd >/dev/null 2>&1

printf "Creating tarball:"
prefix="crosstool-ng-${version}"
printf " extract"
date="$( _hg log -R "${repos}" -r "${prefix}" --template '{date|rfc822date}\n' )"
tmpdir="$( mktemp -d --tmpdir XXXXXX )"
_hg archive --cwd "${repos}" -r "${prefix}" -X '.hg*' --type files "${tmpdir}/${prefix}"
printf ", bootstrap"
pushd "${tmpdir}/${prefix}" >/dev/null 2>&1
./bootstrap >/dev/null
rm -rf autom4te.cache
popd >/dev/null 2>&1
printf ", tarball"
tar cjf "$(pwd)/${prefix}.tar.bz2" -C "${tmpdir}" "${prefix}"
rm -rf "${tmpdir}"
printf ", sum"
for s in md5 sha1 sha512; do
    ${s}sum "${prefix}.tar.bz2" >"${prefix}.tar.bz2.${s}"
done
printf ", touch"
touch -d "${date}" "${prefix}"*
printf ", done.\n"

if [ ${ver_p} -eq 0 ]; then
    printf "\nAn editor will be launched for you to edit the mail.\n"
    read -p "Press enter when ready..." foo
    cp "${prefix}.mail"{,.orig}
    vi "${prefix}.mail"
    diff -du -U 1 "${prefix}.mail"{.orig,} |patch -p0 "${prefix}.changelog" >/dev/null
    rm -f "${prefix}".{mail,changelog}.orig
fi

printf "\nAn editor will be launched for you to review the changelog.\n"
read -p "Press enter when ready..." foo
vi "${prefix}.changelog"

printf "\nNow, you can push the changes with:   hg push -R '${repos}'\n"