File: create-release-commit-and-tag.sh

package info (click to toggle)
snoopy 2.5.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,988 kB
  • sloc: ansic: 7,167; sh: 4,514; makefile: 1,095
file content (190 lines) | stat: -rwxr-xr-x 4,495 bytes parent folder | download | duplicates (2)
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
#!/bin/bash



### How does this script operate?
#
# Script's expectations:
# - `ChangeLog` file already updated, containing the version-to-be-released at the top
# - `README.md` file already updated, containing references to version-to-be-released in the
#     `News` and `Latest version` sections
# - The edits  to `ChangeLog` and `README.md` not yet committed, but can already be staged
# - The commit containing message `Release X.Y.Z` not existing in the git history
# - The tag `snoopy-x.y.z` not existing in the git repository
#
# Script's arguments:
# - (none)
#
# Steps that this script performs:
# - A check that we're on the `master` branch (can be avoided with the `-c` flag)
# - Gets the release tag from the ChangeLog (via `./dev-tools/libexec/get-release-tag.sh changelog`)
# - Verifies ChangeLog content
# - Verifies README.md content (`News` and `Latest version` sections)
# - Creates an appropriately formatted commit (including sign-off message)



### Shell configuration and script bootstrap
#
set -e
set -u
. `dirname $0`/_bootstrap.sh



### Define help method
#
_showHelp()
{
    cat <<EOF
Purpose:

    Create a git commit and tag for a release

Supported CLI arguments:

    -c          Use current branch for the commit, regardless of what it is.
                By default, the "master" branch needs to be checked out.

    -h/--help   Show this help.

EOF
}

_showHelpAndExit()
{
    _showHelp
    exit
}



### Parse the CLI arguments
#
if [[ $@ =~ [-][-]help ]]; then
    _showHelpAndExit
fi

SKIP_CURRENT_BRANCH_CHECK="false"
while getopts "ch" opt; do
    case "$opt" in
        c)
            SKIP_CURRENT_BRANCH_CHECK="true"
            ;;

        h)
            _showHelpAndExit
            ;;

        ?)
            _fatalError "Unsupported argument: '-$OPTARG'. Run '$0 -h' to list supported arguments."
            ;;

        *)
            _fatalError "Internal error (opt=$opt)"
            ;;
    esac
done



### Check if we're on the master branch
#
CURRENT_GIT_BRANCH=`git branch --show-current`
if [ "$SKIP_CURRENT_BRANCH_CHECK" == "false" ]; then
    if [ "$CURRENT_GIT_BRANCH" != "master" ]; then
        _fatalError "Not on the 'master' git branch (the '-c' flag skips this check)" $LINENO
    fi
fi



### Get the release tag from ChangeLog file
#
_echo "Getting release tag from ChangeLog..."
RELEASE_TAG=`./dev-tools/libexec/get-release-tag.sh -m changelog`
_echo "Got release tag: $RELEASE_TAG"
RELEASE_VERSION=`echo $RELEASE_TAG | sed -e 's/^snoopy-//'`
_echo "Got release version: $RELEASE_VERSION"



### Check git history for the existence of a commit
#
COMMIT_MESSAGE="Release $RELEASE_VERSION"
if git log --pretty=format:"%s" | egrep "^$COMMIT_MESSAGE\$" > /dev/null; then
    _fatalError "Git commit with message'$COMMIT_MESSAGE' already exists" $LINENO
fi



### Check git history for the existence of a tag
#
if git tag | egrep "^$RELEASE_TAG\$" > /dev/null; then
    _fatalError "Git tag '$RELEASE_TAG' already exists" $LINENO
fi



### Verify last version information
#
if ! ./dev-tools/libexec/verify-last-version-everywhere.sh "$RELEASE_VERSION"; then
    _fatalError "Last version information is not consistent everywhere: $RELEASE_VERSION" $LINENO
fi
_echo "Last release version information is consistent everywhere."



### Verify if ChangeLog and README.md changes are not yet committed
#
if ! git status | grep 'modified:' | grep 'ChangeLog$' > /dev/null; then
    _fatalError "Release-related ChangeLog changes must not yet be committed - they must a part of the release commit" $LINENO
fi
if ! git status | grep 'modified:' | grep 'README.md$' > /dev/null; then
    _fatalError "Release-related README.md changes must not yet be committed - they must a part of the release commit" $LINENO
fi



### Create a git commit and tag
#
# - Pre-format the commit message
# - Open the editor for any additional tweaking
# - If the commit is successful, tag the commit
#
git add ChangeLog
git add README.md
git commit -m "Release $RELEASE_VERSION

#
#
# If you want to terminate the commit+tag process here,
# comment out all the lines above and save.
# This will result in the 'Aborting commit due to empty commit message' error.
#
#
#
" -e -s -v
git tag "$RELEASE_TAG"



### Report success
#
_echo ""
_echo "SUCCESS: Commit and tag for version $RELEASE_VERSION created (locally)."
_echo ""



### Suggest next step(s)
#
_echo "
Next step:
==========

4. Build the release package:

    ./dev-tools/build-release-package.sh

"