-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrelease.sh
executable file
·44 lines (38 loc) · 1.27 KB
/
release.sh
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
#! /bin/sh
set -eo pipefail
if [ $# -ne 1 ]; then
echo "$0 | A script to release new versions automatically"
echo "Usage: $0 VERSION_CODE"
exit -1
fi
VERSION_CODE=$1
GEMSPEC=increment_semver.gemspec
# Only release from master
currentBranch=$(git rev-parse --abbrev-ref HEAD)
if [ "$currentBranch" != 'master' ]; then
printf "Release: You must be on master\\n"
exit 1
fi
# Check that the working repository is clean (without any changes, neither staged nor unstaged).
if ! git diff --exit-code > /dev/null || ! git diff --staged --exit-code > /dev/null
then
echo "ERROR: Working copy not clean! Aborting." 1>&2
echo "Please stash, revert or commit any pending changes before releasing." 1>&2
exit 1
fi
echo "About to release $VERSION_CODE"
echo "Bumping version number in gemspec..."
sed -i '' "s/\\(.*s\\.version = \\).*/\\1'$VERSION_CODE'/" $GEMSPEC
sed -i '' "s/\\(.*~> \\).*$/\\1$VERSION_CODE'/" ./README.md
git add $GEMSPEC ./README.md
git commit -m "chore: Bump version to $VERSION_CODE"
echo "Backing up existing gems in $(pwd)..."
for file in *.gem; do
mv "$file" "$(basename "$file" .gem).bak"
done
echo "Building new gem..."
gem build $GEMSPEC
echo "Pushing release commit to GitHub..."
git push origin master
gem push increment_semver-*.gem
rm ./*.gem