Fix test for directory
[git-tools-moved-to-github.git] / id-release
1 #!/bin/sh
2 # Copyright (c) 2011-2015 IndexData ApS. http://indexdata.com
3 # Author: Wolfram Schneider
4 #
5 # id-release - a helper script to build a release & packaging for debian + redhat
6 #
7 # see http://twiki.indexdata.dk/cgi-bin/twiki/view/ID/IDSoftwareRelease
8 # https://twiki.indexdata.com/twiki/bin/view/ID/AdamsReleaseProcedure
9
10 # die early
11 set -e
12
13 usage () {
14     echo  >&2 "usage $0 version"
15     echo  >&2 "$@"
16     exit 1
17 }
18
19 branch_check () {
20     if ! git branch | egrep -q '^\* master$'; then
21         ( echo ">>> Warning: you are not running on the master branch <<<"
22           git branch; echo ) 1>&2
23     fi
24 }
25
26 ######################################################################
27 branch_check
28
29 case $1 in
30   [0-9]* ) version=$1 ;;
31        * ) usage ;;
32 esac
33
34
35
36 cat <<EOF
37 #!/bin/sh
38 #
39 # See also https://twiki.indexdata.com/twiki/bin/view/ID/AdamsReleaseProcedure
40 #
41
42 set -e
43
44 EOF
45
46 echo "# Did you updated the news log file?"
47 for file in Changes News NEWS
48 do
49   if [ -e $file ]; then
50     echo "# $(ls -l $file)"
51   fi
52 done
53 echo ""
54
55 if [ -e "pom.xml" ]; then
56     java=true
57 else
58     java=false
59 fi
60
61 if [ `find . -name '*.pm' | wc -l` -gt 0 ]; then
62     perl=true
63 else
64     perl=false
65 fi
66
67 if [ `ls | egrep '\.spec$' | wc -l` -eq 0 ]; then
68     usage "No *.spec file found"
69 else
70     spec=`ls |egrep '\.spec$' | head -1`
71     package=`perl -ne 's/\s*$//; print if s/^NAME=//' IDMETA`
72     if [ -z "$package" ]; then
73         package=`basename $spec .spec`
74     fi
75 fi
76
77 # configure new version
78 perl -i.bak -npe "s,VERSION=.*,VERSION=$version," IDMETA
79
80 if $java; then
81     echo "# set maven version to $version"
82     mvn versions:set -DnewVersion=$version > mvn-versions.log
83 fi
84
85 if $perl; then
86   echo "# check perl version numbers"
87   find . -name '*.pm' -print0 | xargs -0 egrep -H '\$VERSION.*=.*[0-9]' | 
88         egrep -v '^\./deb-src/' | perl -npe 's,^,# ,'
89 fi
90
91 # update debian version file
92 perl -i.bak -npe "\$. == 1 && s,\(.*?\),($version)," debian/changelog 
93
94 # update redhat version file
95 perl -i.bak -npe "s,^Version: \d+.*,Version: $version," $spec
96
97
98 ######################################################################
99 echo "# Please commit the version updates now"
100 echo "git commit -a -m'new release v$version'"
101 echo ""
102 echo "# Please tag now (we will push later to origin)"
103 echo "git tag v$version"
104
105 if $java; then
106     echo "mvn versions:set -DnewVersion=$version-SNAPSHOT" 
107 fi
108
109 ######################################################################
110 echo ""
111 echo "# On mochi, please run the commands"
112 echo "\$HOME/proj/git-tools/id-deb-build/mkdist.sh"
113 echo "\$HOME/proj/git-tools/id-deb-build/id-pbuild.sh"
114 echo "\$HOME/proj/git-tools/id-deb-build/id-pbuild.sh --upload"
115 echo ""
116
117 echo "# if successfully, don't forget to push to origin"
118 echo "git push origin master"
119 echo "git push origin tag v$version"
120
121 # EOF
122