release_tagger 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2b61ec6e9b9428c4fed0e4b50ea7c9e3a38d4327
4
+ data.tar.gz: 33fb22c3503b91a8cbe7ca19038b382f15512a2d
5
+ SHA512:
6
+ metadata.gz: d08b4af17c06ff0368e4eb05949ace93eabb2627e680518d535bde099445324d3bfa3652c12d187c1ae1d1fc9c23e0b9a5b91ace5ea3d524643449692d67f0a5
7
+ data.tar.gz: a9d3daf083b54d3ddc026862dbf9fa55a65ea486cbac81fba60f28975785bd273b7830aadff3c1b1942677a26cffd0573984f4f175f1297eef2cd3fbe364c9d5
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.6
4
+ before_install: gem install bundler -v 1.10.3
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in release_tagger.gemspec
4
+ gemspec
data/MIT-LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Lostmy.name Ltd.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a
6
+ copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included
14
+ in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17
+ OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.markdown ADDED
@@ -0,0 +1,61 @@
1
+ # ReleaseTagger
2
+
3
+ A simple command-line tool to manage a git tag-based release workflow.
4
+ It:
5
+
6
+ 1. Ensures the working directory is clean and up-to-date
7
+ 2. Ensures a non-master branch is not being released
8
+ 3. Bumps the requested version number (major, minor or patch)
9
+ 4. Creates a release commit noting changes since the last release
10
+ 5. Tags the release commit
11
+ 6. Pushes the whole lot to the origin repo
12
+
13
+ That's all. Any other build steps are to be managed manually, or by CI
14
+ watching for release tags in the origin repo.
15
+
16
+ ## Installation
17
+
18
+ Add this line to your application's Gemfile:
19
+
20
+ ```ruby
21
+ gem 'release_tagger'
22
+ ```
23
+
24
+ And then execute:
25
+
26
+ $ bundle
27
+
28
+ Or install it yourself as:
29
+
30
+ $ gem install release_tagger
31
+
32
+ ## Usage
33
+
34
+ $ do_release (major|minor|patch)
35
+
36
+ ## Development
37
+
38
+ After checking out the repo, run `bin/setup` to install dependencies.
39
+ Then, run `rake rspec` to run the tests. You can also run `bin/console`
40
+ for an interactive prompt that will allow you to experiment. Run `bundle
41
+ exec release_tagger` to use the gem in this directory, ignoring other
42
+ installed copies of this gem.
43
+
44
+ To install this gem onto your local machine, run `bundle exec rake
45
+ install`.
46
+
47
+ To release a new version, use the gem itself to apply the version tag,
48
+ then manually:
49
+
50
+ $ gem build release_tagger.gemspec
51
+ $ gem push
52
+
53
+ This will be handled by CI when this has tests.
54
+
55
+ ## Contributing
56
+
57
+ Bug reports and pull requests are welcome on GitHub at
58
+ https://github.com/Lostmyname/release_tagger. This project is intended
59
+ to be a safe, welcoming space for collaboration, and contributors are
60
+ expected to adhere to the [Contributor
61
+ Covenant](contributor-covenant.org) code of conduct.
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.2.1
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "release_tagger"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
data/exe/do_release ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "release_tagger"
@@ -0,0 +1,5 @@
1
+ module ReleaseTagger
2
+ VERSION = File.read(
3
+ File.join(File.dirname(__FILE__), "..", "..", "VERSION")
4
+ ).strip
5
+ end
@@ -0,0 +1,175 @@
1
+ require "release_tagger/version"
2
+ require 'pathname'
3
+
4
+ module ReleaseTagger
5
+
6
+ Version = Struct.new(:major, :minor, :patch) do
7
+ def bump(type)
8
+ raise ArgumentError,
9
+ "Could not bump #{type} version" unless respond_to?(type)
10
+
11
+ numbers =
12
+ case type
13
+ when "major" then [major + 1, 0, 0]
14
+ when "minor" then [major, minor + 1, 0]
15
+ when "patch" then [major, minor, patch + 1]
16
+ end
17
+
18
+ self.class.new(*numbers)
19
+ end
20
+
21
+ def to_s
22
+ [major, minor, patch].join(".")
23
+ end
24
+ end
25
+
26
+ class << self
27
+
28
+ def color_terminal?
29
+ ENV["TERM"] =~ /color/
30
+ end
31
+
32
+ def green(string)
33
+ if color_terminal?
34
+ "\x1b[0;32m#{string}\x1b[0m"
35
+ else
36
+ string
37
+ end
38
+ end
39
+
40
+ def red(string)
41
+ if color_terminal?
42
+ "\x1b[0;31m#{string}\x1b[0m"
43
+ else
44
+ string
45
+ end
46
+ end
47
+
48
+ def log(message)
49
+ $stdout.puts(green(message))
50
+ end
51
+
52
+ def err(message)
53
+ $stderr.puts(red(message))
54
+ end
55
+
56
+ def usage
57
+ puts "Usage: #{File.basename($0)} (major|minor|patch)"
58
+ end
59
+
60
+ def valid_release_type?(type)
61
+ %w{ major minor patch }.include?(type)
62
+ end
63
+
64
+ def on_master_branch?
65
+ `git rev-parse --abbrev-ref HEAD`.strip == "master"
66
+ end
67
+
68
+ def behind_origin?
69
+ %x{git fetch origin >/dev/null 2>&1; git diff --stat HEAD...@{u}}.strip != ""
70
+ end
71
+
72
+ def dirty_working_tree?
73
+ %x{git status --porcelain 2>/dev/null | egrep "^(M| M)"}.strip != ""
74
+ end
75
+
76
+ def release_message(version)
77
+ "Release v#{version}"
78
+ end
79
+
80
+ def changelog(old_version)
81
+ commits = %x{git log --pretty="format:* %s" v#{old_version}..HEAD}
82
+ unless $?.success?
83
+ raise RuntimeError, "Error getting changelog!"
84
+ end
85
+ commits
86
+ end
87
+
88
+ def run!
89
+ if ARGV.length != 1
90
+ usage
91
+ exit 1
92
+ end
93
+
94
+ release_type = ARGV.first
95
+
96
+ if !valid_release_type?(release_type)
97
+ usage
98
+ exit 1
99
+ end
100
+
101
+ if !on_master_branch?
102
+ err "You must be on the master branch to make a release"
103
+ exit 1
104
+ end
105
+
106
+ if behind_origin?
107
+ err "You are behind the origin/master branch - please pull before releasing."
108
+ exit 1
109
+ end
110
+
111
+ if dirty_working_tree?
112
+ err "There are uncommitted changes in the working directory."
113
+ err "Please commit or stash all changes before making a release."
114
+ exit 1
115
+ end
116
+
117
+ version_file = Pathname.new(__FILE__).join("..", "..", "VERSION")
118
+
119
+ if !version_file.exist?
120
+ err "Could not find VERSION file - this must be present to make a release"
121
+ exit 1
122
+ end
123
+
124
+ old_version_string = version_file.read.strip
125
+ old_version_parts = old_version_string.split(".").map(&:to_i)
126
+ old_version = Version.new(*old_version_parts)
127
+ new_version = old_version.bump(release_type)
128
+
129
+ $stderr.write "This will release version #{new_version}. Are you sure? [y/N]: "
130
+ unless STDIN.gets.strip == "y"
131
+ err "Exiting."
132
+ exit 1
133
+ end
134
+
135
+ if !version_file.writable?
136
+ err "Could not write to VERSION file - please check you have write permissions"
137
+ exit 1
138
+ end
139
+
140
+ log "Updating VERSION file to #{new_version}"
141
+ version_file.open("w") do |f|
142
+ f.write(new_version.to_s)
143
+ end
144
+
145
+ log "Creating release commit"
146
+ commits = changelog(old_version)
147
+ commit_output = %x{git add -u . && git commit -m "#{release_message(new_version)}\n\n#{commits}" 2>&1}
148
+ unless $?.success?
149
+ err "Error committing VERSION update:"
150
+ err commit_output
151
+ exit 1
152
+ end
153
+
154
+ log "Adding release tag"
155
+ tag_output = %x{git tag v#{new_version} 2>&1}
156
+ unless $?.success?
157
+ err "Error adding version tag v#{new_version}:"
158
+ err tag_output
159
+ exit 1
160
+ end
161
+
162
+ log "Pushing release to origin"
163
+ # Separate `push` and `push --tags` here, because only relatively recent
164
+ # versions of git push both refs and tags with the single command.
165
+ push_output = %x{git push 2>&1 && git push --tags 2>&1}
166
+ unless $?.success?
167
+ err "Error pushing release tag to origin:"
168
+ err push_output
169
+ exit 1
170
+ end
171
+ end
172
+ end
173
+ end
174
+
175
+ ReleaseTagger.run!
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'release_tagger/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "release_tagger"
8
+ spec.version = ReleaseTagger::VERSION
9
+ spec.authors = ["Simon Coffey"]
10
+ spec.email = ["dev@lostmy.name"]
11
+ spec.license = "MIT"
12
+
13
+ spec.summary = %q{Helpers for managing a simple git tag-based release workflow}
14
+ spec.description = %q{A set of helpers for tagging releases and logging changes between releases}
15
+ spec.homepage = "https://github.com/Lostmyname/release_tagger"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.10"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "rspec", "~> 3.3", ">= 3.3.0"
25
+ spec.add_development_dependency "rubocop", "~> 0.32.1"
26
+ end
metadata ADDED
@@ -0,0 +1,122 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: release_tagger
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.1
5
+ platform: ruby
6
+ authors:
7
+ - Simon Coffey
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-06-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.3'
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: 3.3.0
51
+ type: :development
52
+ prerelease: false
53
+ version_requirements: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - "~>"
56
+ - !ruby/object:Gem::Version
57
+ version: '3.3'
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: 3.3.0
61
+ - !ruby/object:Gem::Dependency
62
+ name: rubocop
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: 0.32.1
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: 0.32.1
75
+ description: A set of helpers for tagging releases and logging changes between releases
76
+ email:
77
+ - dev@lostmy.name
78
+ executables:
79
+ - do_release
80
+ extensions: []
81
+ extra_rdoc_files: []
82
+ files:
83
+ - ".gitignore"
84
+ - ".rspec"
85
+ - ".travis.yml"
86
+ - CODE_OF_CONDUCT.markdown
87
+ - Gemfile
88
+ - MIT-LICENSE
89
+ - README.markdown
90
+ - Rakefile
91
+ - VERSION
92
+ - bin/console
93
+ - bin/setup
94
+ - exe/do_release
95
+ - lib/release_tagger.rb
96
+ - lib/release_tagger/version.rb
97
+ - release_tagger.gemspec
98
+ homepage: https://github.com/Lostmyname/release_tagger
99
+ licenses:
100
+ - MIT
101
+ metadata: {}
102
+ post_install_message:
103
+ rdoc_options: []
104
+ require_paths:
105
+ - lib
106
+ required_ruby_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ required_rubygems_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ requirements: []
117
+ rubyforge_project:
118
+ rubygems_version: 2.4.8
119
+ signing_key:
120
+ specification_version: 4
121
+ summary: Helpers for managing a simple git tag-based release workflow
122
+ test_files: []