-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathversion.sh
More file actions
executable file
·168 lines (132 loc) · 4.38 KB
/
version.sh
File metadata and controls
executable file
·168 lines (132 loc) · 4.38 KB
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
#! /bin/sh
### version.sh --- Generic versioning script for LaTeX packages
## Copyright (C) 2017 Didier Verna
## Author: Didier Verna <didier@didierverna.net>
## This file is part of LtxPkg.
## Permission to use, copy, modify, and distribute this software for any
## purpose with or without fee is hereby granted, provided that the above
## copyright notice and this permission notice appear in all copies.
## THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
## WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
## MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
## ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
## WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
## ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
## OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
### Commentary:
# LtxPkg is a generic infrastructure for maintaining LaTeX packages. This
# script automates the updating of the version number and release date in the
# dtx files.
# The relase date is computed from the current date. The version number is
# either given on the command line, or computed from the NEWS file (with lines
# of the form "* Version x.x" for each version), or left untouched. Once the
# release date and version number are known, this script looks for the
# following lines and updates them in the .dtx files:
# \ProvidesClass{foo}[<releasedate> v<version>
# \ProvidesPackage{foo}[<releasedate> v<version>
# This script also has the capability to commit to git and even tag as a
# release.
## Usage:
# You may call this script directly from the command-line (see the `usage'
# fonction below for command-line arguments). You can also use it as a Git
# post-commit hook (for instance, to bump the release date automatically).
### Code:
prog=`basename $0`
dry_run=no
version=
commit=no
tag=no
date=`date +%Y/%m/%d`
usage ()
{
cat <<EOF
Usage: $prog [OPTIONS]
-h, --help: display this help and exit
-n, --dry-run: just pretend to run (defaults to no)
-v --version[=VERSION]: set new version number to VERSION
or use the latest version from the NEWS file
-c, --commit: commit the change (defaults to no)
-t, --tag: tag the repository (defaults to no)
implies -c unless nothing to commit
EOF
}
while test $# != 0
do
# Standalone options:
found=yes
case $1 in
-h | --help) usage && exit 0;;
-n | --dry-run) dry_run=yes;;
-c | --commit) commit=yes;;
-t | --tag) commit=yes && tag=yes;;
*) found=no;;
esac
test $found = yes && shift && continue
# (Optionally) Valued options:
found=yes
case $1 in
--*=*) option=`expr "$1" : '\([^=]*\)='`
value=`expr "$1" : '[^=]*=\(.*\)'`
shift;;
-*) option="$1"
shift
case $option in
-*) value=__none__;;
*) value="$1" && shift;;
esac;;
esac
case "$option" in
-v | --version) version="$value";;
*) found=no;;
esac
test $found = yes && continue
echo "unknown option: $option" && exit 1
done
version_str=
version_tag=
news_version=`grep -m 1 "^*[ \t]*Version" NEWS \
| sed 's|\*[ \t]*Version[ \t]*\(.*\)|\1|'`
if test "x$version" = "x"
then
# not given
version_str="\3" # this depends on the regexp below
version_tag="`echo $news_version | tr '-' ' '`"
elif test "x$version" = "x__none__"
then
# use latest from the NEWS file
version_str="$news_version"
version_tag="`echo $news_version | tr '-' ' '`"
else
version_str="$version"
version_tag="`echo $version | tr '-' ' '`"
fi
# Hack the dtx file:
if test $dry_run = yes
then
echo "perl -pi -e \"s|(\\\Provides(Class\|Package)\{[a-z]+\})\[\d{4}/\d{2}/\d{2} v([^ ]+) (.*)|\1\[$date v$version_str \4|\" *.dtx"
else
perl -pi -e "s|(\\\Provides(Class\|Package)\{[a-z]+\})\[\d{4}/\d{2}/\d{2} v([^ ]+) (.*)|\1\[$date v$version_str \4|" *.dtx
fi
if test "x$commit" = "xyes"; then
test "x`git status | grep 'nothing to commit'`" = "x" || commit=no
fi
# Commit the change:
if test "x$commit" = "xyes"; then
if test $dry_run = yes
then
echo "git ci -a"
else
git ci -a
fi
fi
# Tag the repository:
if test "x$tag" = "xyes"; then
if test $dry_run = yes
then
echo "git tag -a -m \"Version ${version_tag}, release date $date\" \"version-${version_tag}\""
else
git tag -a -m "Version ${version_tag}, release date $date" \
"version-${version_tag}"
fi
fi
exit 0