Skip to content

Commit 0622746

Browse files
committed
Auto-release script (tested on 0.1.21 release)
1 parent 997ae76 commit 0622746

File tree

4 files changed

+88
-13
lines changed

4 files changed

+88
-13
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
77

88
## [Unreleased]
99
### Added
10+
* `release-new-version.sh` script
1011

1112
### Changed
1213

CONTRIBUTING.md

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,17 @@ ARDUINO_CI_SKIP_RUBY_RSPEC_TESTS=1 bundle exec rspec
4646
## Packaging the Gem
4747

4848
* Merge pull request with new features
49-
* `git stash save` (at least before the gem build step, but easiest here).
50-
* `git pull --rebase`
51-
* Update the sections of `CHANGELOG.md` by running `bundle exec keepachangelog_manager.rb --increment-patch`
52-
* Bump the version in lib/arduino_ci/version.rb and change it in README.md (since rubydoc.info doesn't always redirect to the latest version)
53-
* `git add README.md CHANGELOG.md lib/arduino_ci/version.rb`
54-
* `git commit -m "vVERSION bump"`
55-
* `git tag -a vVERSION -m "Released version VERSION"`
56-
* `gem build arduino_ci.gemspec`
57-
* `git stash pop`
58-
* `gem push arduino_ci-VERSION.gem`
59-
* `git push upstream`
60-
* `git push upstream --tags`
49+
* Execute `release-new-version.sh` with the appropriate argument (e.g. `--increment-patch`), which does the following:
50+
* `git stash save` (at least before the gem build step, but easiest here).
51+
* `git pull --rebase`
52+
* Update the sections of `CHANGELOG.md` by running `bundle exec keepachangelog_manager.rb --increment-patch`
53+
* Bump the version in lib/arduino_ci/version.rb and change it in README.md (since rubydoc.info doesn't always redirect to the latest version)
54+
* `git add README.md CHANGELOG.md lib/arduino_ci/version.rb`
55+
* `git commit -m "vVERSION bump"`
56+
* `git tag -a vVERSION -m "Released version VERSION"`
57+
* `gem build arduino_ci.gemspec`
58+
* `git stash pop`
59+
* `gem push arduino_ci-VERSION.gem`
60+
* `git push upstream`
61+
* `git push upstream --tags`
6162
* Visit http://www.rubydoc.info/gems/arduino_ci/VERSION to initiate the doc generation process

arduino_ci.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Gem::Specification.new do |spec|
2929
spec.add_dependency "rubyzip", "~> 1.2"
3030

3131
spec.add_development_dependency "bundler", "~> 1.15"
32-
spec.add_development_dependency "keepachangelog_manager", "~> 0.0.1"
32+
spec.add_development_dependency "keepachangelog_manager", "~> 0.0.2"
3333
spec.add_development_dependency "rspec", "~> 3.0"
3434
spec.add_development_dependency 'rubocop', '~>0.59.0'
3535
spec.add_development_dependency 'yard', '~>0.9.11'

release-new-version.sh

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#!/bin/bash
2+
3+
# This script automates the gem release project for this repo.
4+
5+
GEM_NAME=arduino_ci
6+
GEM_MODULE=ArduinoCI
7+
PUSH_REMOTE=upstream
8+
9+
# test if we have an arguments on the command line
10+
if [ $# -lt 1 ]
11+
then
12+
echo "You must pass an argument for KeepAChangelogManager:"
13+
bundle exec keepachangelog_manager.rb
14+
exit 1
15+
fi
16+
17+
# set up a cleanup function for any errors, so that we git stash pop
18+
cleanup () {
19+
set +x +e
20+
echo -e "\n### Reverting uncommitted changes"
21+
git checkout README.md CHANGELOG.md lib/$GEM_NAME/version.rb
22+
if [ $DID_STASH -eq 0 ]; then
23+
echo -e "\n### Unstashing changes"
24+
git stash pop
25+
fi
26+
exit $1
27+
}
28+
29+
DIDNT_STASH="No local changes to save"
30+
DID_STASH=1
31+
echo -ne "\n### Stashing changes..."
32+
STASH_OUTPUT=$(git stash save)
33+
[ "$DIDNT_STASH" != "$STASH_OUTPUT" ]
34+
DID_STASH=$?
35+
echo DID_STASH=$DID_STASH
36+
37+
trap "cleanup 1" INT TERM ERR
38+
set -xe
39+
40+
echo "### Checking existence of specified git push destination '$PUSH_REMOTE'"
41+
git remote get-url $PUSH_REMOTE
42+
43+
# ensure latest master
44+
git pull --rebase
45+
46+
# update version in changelog and save it
47+
NEW_VERSION=$(bundle exec keepachangelog_manager.rb $@)
48+
49+
echo "Checking whether new version string is a semver"
50+
echo $NEW_VERSION | grep -Eq ^[0-9]*\.[0-9]*\.[0-9]*$
51+
52+
# write version.rb with new version
53+
cat << EOF > lib/$GEM_NAME/version.rb
54+
module $GEM_MODULE
55+
VERSION = "$NEW_VERSION".freeze
56+
end
57+
EOF
58+
59+
# update README with new version
60+
sed -e "s/\/gems\/$GEM_NAME\/[0-9]*\.[0-9]*\.[0-9]*)/\/gems\/$GEM_NAME\/$NEW_VERSION)/" -i "" README.md
61+
62+
# mutation!
63+
git add README.md CHANGELOG.md lib/$GEM_NAME/version.rb
64+
git commit -m "v$NEW_VERSION bump"
65+
git tag -a v$NEW_VERSION -m "Released version $NEW_VERSION"
66+
gem build $GEM_NAME.gemspec
67+
gem push $GEM_NAME-$NEW_VERSION.gem
68+
git push $PUSH_REMOTE
69+
git push $PUSH_REMOTE --tags
70+
git fetch
71+
72+
# do normal cleanup
73+
cleanup 0

0 commit comments

Comments
 (0)