allegro_release 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 56b0dfd54cc7eb8aefc1ddd57e97da79cb555835
4
+ data.tar.gz: 3434b556d2684591e59d211dd64771d7c9338328
5
+ SHA512:
6
+ metadata.gz: 2541f42d32a176474d5ab4288263b574c7c0554b617d7bfa4ca51c674f337c561617c65cd1102e1ec166d1313691ee7996277381e3ba5bcc6aab30a67412b67a
7
+ data.tar.gz: 376a3340996bf64c4b3ba90872f0f22b48dfe35cc69e7ad44006c0900dfc7a156b38bdfaa9df7ef3f8171f761380099ee872c9e05df4969795df7c76c76873eb
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/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in release.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,9 @@
1
+ # Release
2
+
3
+ ## Installation
4
+
5
+ ## Usage
6
+
7
+ ## Development
8
+
9
+ ## Contributing
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'allegro_release/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "allegro_release"
8
+ spec.version = Release::VERSION
9
+ spec.authors = ["Aleksander Grzyb"]
10
+ spec.email = ["aleksander.grzyb@allegrogroup.com"]
11
+
12
+ spec.summary = "A command line tools to release module."
13
+ spec.description = "A command line tools to release module easily."
14
+
15
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
16
+ spec.bindir = "exe"
17
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.11"
21
+ spec.add_development_dependency "rake", "~> 10.0"
22
+
23
+ spec.add_dependency "colorize", '~> 0'
24
+ spec.add_dependency "highline", '~> 1.0'
25
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "release"
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,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env ruby
2
+ require 'optparse'
3
+ require 'allegro_release'
4
+
5
+ options = {}
6
+ OptionParser.new do |opts|
7
+ opts.banner = <<BANNER
8
+ Bump your podspec version.
9
+ Usage:
10
+ allegro_release current # show current version
11
+ allegro_release patch # increase patch version of your podspec (1.0.X) and creates PR
12
+ allegro_release minor # increase minor version of your podspec (1.X.0) and creates PR
13
+ allegro_release major # increase major version of your podspec (X.0.0) and creates PR
14
+ allegro_release to_master # created PR from develop to master
15
+ allegro_release finish # pushes changes to spec repo
16
+ BANNER
17
+ opts.on("-h", "--help","Show this.") { puts opts; exit }
18
+ end.parse!
19
+
20
+ Release::Bump.run(ARGV.first, options)
@@ -0,0 +1,3 @@
1
+ module Release
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,206 @@
1
+ require 'release/version'
2
+ require 'colorize'
3
+ require 'highline'
4
+ require 'fileutils'
5
+
6
+ module Release
7
+ class InvalidOptionError < StandardError; end
8
+ class NotFoundSpecFileError < StandardError; end
9
+
10
+ class Bump
11
+ BUMPS = %w(major minor patch)
12
+ OPTIONS = BUMPS | ["current", "to_master", "finish"]
13
+ VERSION_REGEX = /(\d+\.\d+\.\d+)/
14
+
15
+ def self.run(bump, options={})
16
+ case bump
17
+ when *BUMPS
18
+ bump_part(bump, options)
19
+ when "current"
20
+ puts "Current version: #{version_from_file()}".colorize(:green)
21
+ when "to_master"
22
+ to_master
23
+ when "finish"
24
+ finish
25
+ else
26
+ raise InvalidOptionError
27
+ end
28
+ rescue InvalidOptionError
29
+ puts "Invalid option. Choose between #{OPTIONS.join(', ')}.".colorize(:red)
30
+ rescue NotFoundSpecFileError
31
+ puts "Not found .podspec file.".colorize(:red)
32
+ rescue Exception => e
33
+ puts "Shell command error. See message above. Stack: #{e.backtrace.join("\n")}".colorize(:red)
34
+ end
35
+
36
+ def self.finish
37
+ checkout_master
38
+ add_tag
39
+ push_to_spec_repository
40
+ puts "Last step is done! You released #{spec_file}.".colorize(:green)
41
+ end
42
+
43
+ def self.checkout_master
44
+ puts "Pulling current master branch.".colorize(:green)
45
+ return unless File.directory?(".git")
46
+ system_cmd("git checkout master")
47
+ system_cmd("git pull")
48
+ end
49
+
50
+ def self.add_tag
51
+ puts "Adding tag #{version_from_file} and pushing to origin.".colorize(:green)
52
+ system_cmd("git tag #{version_from_file}")
53
+ system_cmd("git push origin --tags")
54
+ end
55
+
56
+ def self.push_to_spec_repository
57
+ puts "Pushing #{spec_file} to spec repository.".colorize(:green)
58
+ system_cmd("pod repo push allegro-specs --allow-warnings #{spec_file}")
59
+ end
60
+
61
+ def self.to_master
62
+ checkout_develop
63
+ create_pull_request_to_master
64
+ puts "Second step is done! Now head to HipChat and paste the content of clipboard that contains link to pull request. After manual merge perform `release finish`.".colorize(:green)
65
+ end
66
+
67
+ def self.create_pull_request_to_master
68
+ puts "Creating pull request to master on Stash.".colorize(:green)
69
+ link = `stash pull-request master -T \"Release #{version_from_file}.\" -d \"Release #{version_from_file}.\"`
70
+ pbcopy "(kotek) (kotek) (successful) (successful) #{link}"
71
+ end
72
+
73
+ def self.bump(current, next_version, options)
74
+ checkout_develop
75
+ create_branch(next_version)
76
+ replace(current, next_version)
77
+ update_changelog(next_version)
78
+ check_podspec
79
+ commit_release(next_version)
80
+ push_changes_to_remote_branch(next_version)
81
+ create_pull_request_to_develop(next_version)
82
+ puts "First step is done! Now head to HipChat and paste the content of clipboard that contains link to pull request. After manual merge perform `release to_master`.".colorize(:green)
83
+ end
84
+
85
+ def self.create_pull_request_to_develop(version)
86
+ puts "Creating pull request to develop on Stash.".colorize(:green)
87
+ link = `stash pull-request develop -T \"Release #{version_from_file}.\" -d \"Release #{version_from_file}.\"`
88
+ pbcopy "(kotek) (kotek) (successful) (successful) #{link}"
89
+ end
90
+
91
+ def self.push_changes_to_remote_branch(version)
92
+ puts "Pushing branch to upstream.".colorize(:green)
93
+ system_cmd("git push -u origin release_#{version}")
94
+ end
95
+
96
+ def self.commit_release(version)
97
+ cli = HighLine.new
98
+ jira_id = cli.ask("Give JIRA issue ID to commit changes: ".colorize(:yellow)) { |q| q.validate = /^\d{4}\z/ }
99
+ commit(jira_id, version)
100
+ end
101
+
102
+ def self.update_changelog(version)
103
+ puts "Updating CHANGELOG.md with #{version} version and #{Time.now.strftime("%d.%m.%Y")} release date.".colorize(:green)
104
+ if Dir.glob('CHANGELOG.md').empty?
105
+ puts "There is no CHANGELOG.md in the repository. Skipping...".colorize(:red)
106
+ return
107
+ end
108
+ changelog_file = Dir.glob('CHANGELOG.md')[0]
109
+ temp_changelog_file = "CHANGELOG.tmp"
110
+ temp_file = File.open(temp_changelog_file, 'w')
111
+
112
+ temp_file << "# CHANGELOG\n"
113
+ temp_file << "\n"
114
+ temp_file << "## Version X.Y.Z\n"
115
+ temp_file << "#### Released ?\n"
116
+ temp_file << "\n"
117
+ temp_file << "## Version #{version}\n"
118
+ temp_file << "#### Released #{Time.now.strftime("%d.%m.%Y")}\n"
119
+
120
+ File.readlines(changelog_file).each_with_index do |line, index|
121
+ if index > 4
122
+ temp_file << line
123
+ end
124
+ end
125
+
126
+ changelog = File.new(changelog_file)
127
+ temp_file.close
128
+ FileUtils.mv(temp_changelog_file, changelog)
129
+ changelog.close
130
+ end
131
+
132
+ def self.replace(old, new)
133
+ puts "Bumping version #{old} to #{new} of #{spec_file}.".colorize(:green)
134
+ content = File.read(spec_file)
135
+ File.open(spec_file, "w"){|f| f.write(content.sub(old, new)) }
136
+ end
137
+
138
+ def self.checkout_develop
139
+ return unless File.directory?(".git")
140
+ puts "Pulling current develop branch.".colorize(:green)
141
+ system_cmd("git checkout develop")
142
+ system_cmd("git pull")
143
+ end
144
+
145
+ def self.commit(jira_id, version)
146
+ return unless File.directory?(".git")
147
+ commit_message = "'[IOSBUYERS-#{jira_id}] Release #{version}.'"
148
+ puts "Committing changes with message #{commit_message}.".colorize(:green)
149
+ system_cmd("git add --all")
150
+ system_cmd("git commit -m #{commit_message}")
151
+ end
152
+
153
+ def self.create_branch(version)
154
+ return unless File.directory?(".git")
155
+ puts "Creating release branch.".colorize(:green)
156
+ system_cmd("git checkout -b release_#{version}")
157
+ end
158
+
159
+ def self.system_cmd(command)
160
+ puts ("[SHELL] " + command).colorize(:white)
161
+ raise Exception unless system command
162
+ end
163
+
164
+ def self.spec_file
165
+ raise NotFoundSpecFileError if Dir.glob('*.podspec')[0].empty?
166
+ Dir.glob('*.podspec')[0]
167
+ end
168
+
169
+ def self.version_from_file
170
+ raise NotFoundSpecFileError if Dir.glob('*.podspec').empty?
171
+ File.read(spec_file)[VERSION_REGEX]
172
+ end
173
+
174
+ def self.bump_part(part, options)
175
+ current = version_from_file
176
+ next_version = next_version(current, part)
177
+ bump(current, next_version, options)
178
+ end
179
+
180
+ def self.next_version(current, part)
181
+ major, minor, patch = current.split('.')
182
+ case part
183
+ when "major"
184
+ major, minor, patch = major.succ, 0, 0, nil
185
+ when "minor"
186
+ minor, patch = minor.succ, 0
187
+ when "patch"
188
+ patch = patch.succ
189
+ else
190
+ raise "unknown part #{part.inspect}"
191
+ end
192
+ [major, minor, patch].compact.join('.')
193
+ end
194
+
195
+ def self.check_podspec
196
+ puts "Validating #{spec_file}.".colorize(:green)
197
+ system_cmd("pod lib lint --allow-warnings")
198
+ end
199
+
200
+ def self.pbcopy(input)
201
+ str = input.to_s
202
+ IO.popen('pbcopy', 'w') { |f| f << str }
203
+ str
204
+ end
205
+ end
206
+ end
metadata ADDED
@@ -0,0 +1,110 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: allegro_release
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Aleksander Grzyb
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-03-15 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.11'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
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: colorize
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: highline
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.0'
69
+ description: A command line tools to release module easily.
70
+ email:
71
+ - aleksander.grzyb@allegrogroup.com
72
+ executables:
73
+ - allegro_release
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - Gemfile
79
+ - README.md
80
+ - Rakefile
81
+ - allegro_release.gemspec
82
+ - bin/console
83
+ - bin/setup
84
+ - exe/allegro_release
85
+ - lib/allegro_release.rb
86
+ - lib/allegro_release/version.rb
87
+ homepage:
88
+ licenses: []
89
+ metadata: {}
90
+ post_install_message:
91
+ rdoc_options: []
92
+ require_paths:
93
+ - lib
94
+ required_ruby_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ requirements: []
105
+ rubyforge_project:
106
+ rubygems_version: 2.6.2
107
+ signing_key:
108
+ specification_version: 4
109
+ summary: A command line tools to release module.
110
+ test_files: []