-
Notifications
You must be signed in to change notification settings - Fork 6
/
repo-generate
executable file
·92 lines (76 loc) · 2.14 KB
/
repo-generate
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
#!/bin/sh
progname="$(basename "$0")"
export TZ=''
release_pattern='v[0-9]*'
warn() {
printf >&2 "%s: %s\n" "$progname" "$*"
}
die() { warn "$@"; exit 1; }
git_last_version() {
git describe --match="$release_pattern"
}
files_changed_in_last_version() {
git diff-tree --no-commit-id --name-only -r $(git_last_version)
}
partial_changelog() {
# the sed filter is against spammers
git log --decorate=short --date=iso "$@" | sed '/^Author:/s/ <.*//' | sed '/^Author:/s/ [A-Za-z0-9._-]\+@.*$//'
}
gen_changelog() {
if files_changed_in_last_version | fgrep -q sieve-connect.
then
partial_changelog -- sieve-connect.\*
else
latest="$(git_last_version)"
partial_changelog "${latest}^..${latest}"
echo
partial_changelog -- sieve-connect.\*
fi
}
missing_year() {
local complain
complain=die
[ -n "${RELEASE_IGNORE_COPYRIGHT_YEAR:-}" ] && complain=warn
$complain "Current year not in $* Copyright line"
}
check_copyright() {
if [ $# -eq 0 ]; then
die "Missing files to check for copyright year"
fi
local fn
for fn
do
grep -q "Copyright.*\\<`date +%Y`" "$fn" || missing_year "$fn"
done
}
gen_version() {
local dirty
dirty='--dirty=-XX'
[ -n "${RELEASE_PRETEND_CLEAN_REPO:-}" ] && dirty=''
git describe --match="$release_pattern" $dirty | sed -n 's/^v//p'
}
gen_date() {
git show -s --format=%ci HEAD | cut -d ' ' -f 1
}
filter_embed_version() {
[ $# -ne 2 ] && die "Usage: ${progname} versionfilter <infile> <outfile>"
[ -f versionfile ] || die "missing file: versionfile"
local repo_src="$1"
local distributed_src="$2"
perl -MFile::Slurp -p < "${repo_src:?}" > "${distributed_src:?}" -e '
BEGIN { $newver = read_file("versionfile"); chomp $newver; };
next unless /VERSION.*MAGIC LINE REPLACED IN DISTRIBUTION/;
$_ = qq{our \$VERSION = '"'"'$newver'"'"';\n};'
chmod +x "${distributed_src:?}"
}
cmd="$1"
shift
case "${cmd:-unknown}" in
copyright) check_copyright "$@" ;;
changelog) gen_changelog "$@" ;;
date) gen_date "$@" ;;
version) gen_version "$@" ;;
versionfilter) filter_embed_version "$@" ;;
help) echo "$0 changelog|date|version|{copyright <files>}|{versionfilter <in> <out>}" ;;
*) echo >&2 "$0: unknown action" ; exit 1 ;;
esac