File: OpenIGTLinkReleaseScript.sh

package info (click to toggle)
openigtlink 3.0.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,080 kB
  • sloc: cpp: 20,076; ansic: 6,704; sh: 227; perl: 74; makefile: 46
file content (177 lines) | stat: -rwxr-xr-x 4,680 bytes parent folder | download
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
#! /usr/bin/env bash

# Bash script to release a new revision of OpenIGTLink library.
# Run the command without arugment for the usage.

GITHUB_ORG="tokjun"
GITHUB_REPO="OpenIGTLink.git"
GITHUB_PAGES_REPO="openigtlink.github.com"

GIT_URL="https://github.com/$GITHUB_ORG/$GITHUB_REPO"
GIT_WEB_URL="https://github.com/$GITHUB_ORG/$GITHUB_PAGES_REPO"

#
# Major, minor, and patch version numbers
#
MAJ=0
MIN=0
PAT=0

printUsage() {
    echo ''
    echo 'Usage: Utilities/OpenIGTLinkReleaseScript.sh <RELEASE_TYPE>'
    echo ''
    echo '  RELEASE_TYPE: Type of release' 
    echo '      major : Major version release'
    echo '      minor : Minor version release'
    echo '      patch : Patch release'
}

#
# Extract OpenIGTLink protocol version numbers from the specified CMake file
#
getVersionNumbers() {

    local FILE=$1

    echo "Examining the existing version numbers in $FILE..."
    MAJ=`sed -rn 's/(\s*SET\(OpenIGTLink_VERSION_MAJOR\s+\")([0-9]+)(.*)/\2/p' $FILE`
    MIN=`sed -rn 's/(\s*SET\(OpenIGTLink_VERSION_MINOR\s+\")([0-9]+)(.*)/\2/p' $FILE`
    PAT=`sed -rn 's/(\s*SET\(OpenIGTLink_VERSION_PATCH\s+\")([0-9]+)(.*)/\2/p' $FILE`

    echo "Old version: $MAJ.$MIN.$PAT"

}

#
# Update OpenIGTLink protocol version numbers in the specified CMake file
#
updateVersionNumbers() {
    
    local FILE=$1

    echo "New version: $MAJ.$MIN.$PAT"

    cat $FILE \
	| sed -r 's/(\s*SET\(OpenIGTLink_VERSION_MAJOR\s+\")([0-9]+)(.*)/\1'"$MAJ"'\3/g' \
	| sed -r 's/(\s*SET\(OpenIGTLink_VERSION_MINOR\s+\")([0-9]+)(.*)/\1'"$MIN"'\3/g' \
	| sed -r 's/(\s*SET\(OpenIGTLink_VERSION_PATCH\s+\")([0-9]+)(.*)/\1'"$PAT"'\3/g' > $FILE.back
    mv $FILE.back $FILE

}


replacePageLine() {
    local FILE=$1
    local STRING1=$2
    local STRING2=$3
    cat $FILE \
	| sed -r 's/'"$STRING1"'.*)/'"$STRING2"'/g' > $FILE.back
    mv $FILE.back $FILE
}

updatePage() {
    local FILE=$1
    local VERSION=$2
    local STRING=$3
    cat $FILE \
	| sed -r 's/(\[AUTO_VER'"$VERSION"'\]\:\s+\<\>\s+\(.*\).*)/'"$STRING"'/g' > $FILE.back
    mv $FILE.back $FILE
}

# Validate the number of arguments
if [ "$#" -ne 1 ]; then
    printUsage
    exit 1
fi

RELEASE_TYPE=$1

getVersionNumbers CMakeLists.txt

if [ $RELEASE_TYPE == "major" ]; then
    MAJ=$(($MAJ+1))
    MIN=0
    PAT=0
elif [ $RELEASE_TYPE == "minor" ]; then
    MIN=$(($MIN+1))
    PAT=0
elif [ $RELEASE_TYPE == "patch" ]; then
    PAT=$(($PAT+1))
else
    echo "ERROR: Invaid release type: $TYPE"
    exit 1
fi

BRANCH_NAME="release-$MAJ.$MIN"
TAG_NAME="v$MAJ.$MIN.$PAT"
CURRENT_BRANCH=`git rev-parse --abbrev-ref HEAD`

# Major release must be performed under the master branch
if [ $RELEASE_TYPE == "major" ]]; then
    if [ $CURRENT_BRANCH != "master" ]]; then
	echo "ERROR: Cannot perform major release from non-master branch."
	exit 1
    fi
fi

updateVersionNumbers CMakeLists.txt

# If the current branch is not master, switch to the appropriate release branch
if [ $CURRENT_BRANCH != "master" ]]; then
    git checkout -B $BRANCH_NAME
    CURRENT_BRANCH=$BRANCH_NAME
fi

# Commit the updated CMakeFileLists.txt to the current branch
git commit -a -m "Update version number in CMakeLists.txt to $MAJ.$MIN.$PAT."
git push $GIT_URL $CURRENT_BRANCH

# Change to the release branch, if the current branch is master
git checkout -B $BRANCH_NAME

# Add release tag
git tag -a $TAG_NAME -m "Relase $MAJ.$MIN.$PAT"    
git push --tags $GIT_URL $CURRENT_BRANCH

# Generate Doxygen in a temporary directory
TEMP_DIR=`mktemp -d`
SOURCE_DIR=`pwd`

cd $TEMP_DIR
mkdir OpenIGTLink-build
cd OpenIGTLink-build
cmake -DBUILD_DOCUMENTATION:BOOL=ON $SOURCE_DIR
make Documentation

# Download the repository of OpenIGTLink website
cd $TEMP_DIR
git clone $GIT_WEB_URL
cd $GITHUB_PAGES_REPO

# Copy Doxygen-generated API document
mkdir api/v$MAJ.$MIN
cp -rp $TEMP_DIR/OpenIGTLink-build/Documents/Doxygen/html/* api/v$MAJ.$MIN
git add api/v$MAJ.$MIN/*
git commit -a -m "Add API document for release $MAJ.$MIN.$PAT."

DATE=`date +"%b %d, %G"`
updatePage releaselog.md 0 " - $DATE : Version $MAJ.$MIN.$PAT is released."

if [ $RELEASE_TYPE == "patch" ]]; then
    replacePageLine spec.md "- [Relase $MAJ.$MIN]" "- [Release $MAJ.$MIN]](https://github.com/openigtlink/OpenIGTLink/blob/release-v$MAJ.$MIN.$PAT/Documents/Protocol/index.md)"
    replacePageLine api/index.md "- [Relase $MAJ.$MIN]" "- [Release $MAJ.$MIN]](https://github.com/openigtlink/OpenIGTLink/blob/release-v$MAJ.$MIN.$PAT/Documents/Protocol/index.md)"
fi

if [ $RELEASE_TYPE == "minor" ]]; then
    updatePage spec.md $MAJ " - [Release $MAJ.$MIN](https://github.com/openigtlink/OpenIGTLink/blob/release-v$MAJ.$MIN.$PAT/Documents/Protocol/index.md)"
fi


rm -rf $TEMP_DIR