forked from Arduino-CI/arduino_ci
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrelease-new-version.sh
73 lines (59 loc) · 1.79 KB
/
release-new-version.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
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
#!/bin/bash
# This script automates the gem release project for this repo.
GEM_NAME=arduino_ci
GEM_MODULE=ArduinoCI
PUSH_REMOTE=upstream
# test if we have an arguments on the command line
if [ $# -lt 1 ]
then
echo "You must pass an argument for KeepAChangelogManager:"
bundle exec keepachangelog_manager.rb
exit 1
fi
# set up a cleanup function for any errors, so that we git stash pop
cleanup () {
set +x +e
echo -e "\n### Reverting uncommitted changes"
git checkout README.md CHANGELOG.md lib/$GEM_NAME/version.rb
if [ $DID_STASH -eq 0 ]; then
echo -e "\n### Unstashing changes"
git stash pop
fi
exit $1
}
DIDNT_STASH="No local changes to save"
DID_STASH=1
echo -ne "\n### Stashing changes..."
STASH_OUTPUT=$(git stash save)
[ "$DIDNT_STASH" != "$STASH_OUTPUT" ]
DID_STASH=$?
echo DID_STASH=$DID_STASH
trap "cleanup 1" INT TERM ERR
set -xe
echo "### Checking existence of specified git push destination '$PUSH_REMOTE'"
git remote get-url $PUSH_REMOTE
# ensure latest master
git pull --rebase
# update version in changelog and save it
NEW_VERSION=$(bundle exec keepachangelog_manager.rb $@)
echo "Checking whether new version string is a semver"
echo $NEW_VERSION | grep -Eq ^[0-9]*\.[0-9]*\.[0-9]*$
# write version.rb with new version
cat << EOF > lib/$GEM_NAME/version.rb
module $GEM_MODULE
VERSION = "$NEW_VERSION".freeze
end
EOF
# update README with new version
sed -e "s/\/gems\/$GEM_NAME\/[0-9]*\.[0-9]*\.[0-9]*)/\/gems\/$GEM_NAME\/$NEW_VERSION)/" -i "" README.md
# mutation!
git add README.md CHANGELOG.md lib/$GEM_NAME/version.rb
git commit -m "v$NEW_VERSION bump"
git tag -a v$NEW_VERSION -m "Released version $NEW_VERSION"
gem build $GEM_NAME.gemspec
gem push $GEM_NAME-$NEW_VERSION.gem
git push $PUSH_REMOTE
git push $PUSH_REMOTE --tags
git fetch
# do normal cleanup
cleanup 0