release_me 0.1.0

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: 19c4ba725cd0d3c5a93a0d88851858a8e402a33e
4
+ data.tar.gz: 422fd68501145f4b52aec5fd9d589d845af7c9aa
5
+ SHA512:
6
+ metadata.gz: f10e8facac55dc9b422b4f1f5752be8cc89f87aaf9bc5ce3f12499d92101d7ef6ab7e2c793f9c365cee445dea98387d82ada84904241f4a0d426457acf1d5846
7
+ data.tar.gz: 7866ed310ede463797dd3b035a4220e149e0a5ffcf18e496bca51d6b0b2fc9612d3fc685163ab5ab594cd6942434642dc1c4605a4bbdea4c681be04c238b7bf1
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/.release_me.yaml ADDED
@@ -0,0 +1,11 @@
1
+ adapter:
2
+ version_file_relative_path: 'lib/release_me/version.rb'
3
+ version_field: 'VERSION'
4
+ version_type: 'semver'
5
+ adapter_name: 'custom'
6
+
7
+ vcs:
8
+ provider: gitlab
9
+ branch_name: master
10
+ author_email: autobot@nwops.io
11
+ author_name: Autobot
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.13.6
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at corey@nwops.io. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in release_me.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "{}"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright {yyyy} {name of copyright owner}
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Corey Osman
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,44 @@
1
+ # ReleaseMe
2
+
3
+ ## Installation
4
+
5
+ Add this line to your application's Gemfile:
6
+
7
+ ```ruby
8
+ gem 'release_me'
9
+ ```
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install release_me
18
+
19
+ ## Usage
20
+
21
+ ### Local Release_me config
22
+
23
+ ```
24
+ file_relative_path: 'lib/release_me/version.rb'
25
+ version_field: 'VERSION'
26
+ version_type: 'semver'
27
+ adapter_name: 'custom'
28
+ ```
29
+
30
+ ## Development
31
+
32
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
33
+
34
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
35
+
36
+ ## Contributing
37
+
38
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/release_me. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
39
+
40
+
41
+ ## License
42
+
43
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
44
+
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/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "release_me"
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
data/exe/bump_and_tag ADDED
@@ -0,0 +1,47 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+ require 'json'
4
+ require 'uri'
5
+ require 'net/http'
6
+ require 'optparse'
7
+ require_relative '../lib/release_me/bump_tag'
8
+
9
+ # Author: Corey Osman
10
+ # Purpose: auto bump and tag, should only be run by a gitlab ci runner
11
+ # make API calls to gitlab in order to update the file and tag a version
12
+
13
+ # this script is not smart. if it fails you may need to perform some manual steps
14
+ # the next version should detect the failed state and perform the neccessary steps
15
+ options = {}
16
+ OptionParser.new do |opts|
17
+ opts.banner = "Usage: #{__FILE__} [options]"
18
+
19
+ opts.on('-j', '--json', 'Output as JSON') do
20
+ options[:json] = true
21
+ end
22
+
23
+ opts.on('--version-type TYPE', 'Version string to use: commit|time|semver') do |arg|
24
+ options[:version_type] = arg.to_sym
25
+ end
26
+
27
+ opts.on('-p', '--path_of_project PATH', "Project path, defaults to: #{Dir.pwd}") do |arg|
28
+ options[:project_path] = arg || Dir.pwd
29
+ end
30
+
31
+ opts.on('--no-tag', 'Do not tag a version') do
32
+ options[:no_tagging] = true
33
+ end
34
+
35
+ opts.on('-n', '--noop', 'Perform a Dry Run') do
36
+ options[:dry_run] = true
37
+ end
38
+
39
+ opts.on('-h', '--help', 'Prints this help') do
40
+ puts opts
41
+ exit 1
42
+ end
43
+ end.parse!
44
+
45
+
46
+ instance = ReleaseMe::BumpTag.new(options)
47
+ puts instance.run
data/exe/bump_version ADDED
@@ -0,0 +1,46 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+ require 'optparse'
4
+ require_relative '../lib/release_me/bump_version'
5
+
6
+ options = {}
7
+ OptionParser.new do |opts|
8
+ opts.banner = "Usage: #{__FILE__} [options]"
9
+
10
+ opts.on('-j', '--json', 'Output as JSON') do
11
+ options[:json] = true
12
+ end
13
+
14
+ opts.on('-n', '--noop', 'Perform a Dry Run') do
15
+ options[:dry_run] = true
16
+ end
17
+
18
+ opts.on('-t', '--use-time', 'Use the time as the version') do
19
+ options[:version] ||= :time
20
+ end
21
+
22
+ opts.on('-c', '--use-commit', 'Use the commit checksum as the version') do
23
+ options[:version] ||= :commit
24
+ end
25
+
26
+ opts.on('-v', '--version-string VER', 'The version string to use') do |arg|
27
+ options[:version] = arg
28
+ end
29
+
30
+ opts.on('-p', '--path_of_project PATH', "Project path, defaults to: #{Dir.pwd}") do |arg|
31
+ options[:project_path] = arg || Dir.pwd
32
+ end
33
+
34
+ # opts.on('-a', '--adapter-type ADAPTER', 'The adapter type in order to bump the correct file') do |arg|
35
+ # options[:adapter] = arg
36
+ # end
37
+
38
+ opts.on('-h', '--help', 'Prints this help') do
39
+ puts opts
40
+ exit 1
41
+ end
42
+
43
+ end.parse!
44
+
45
+ instance = ReleaseMe::BumpVersion.new(options)
46
+ puts instance.run
@@ -0,0 +1,91 @@
1
+ require 'yaml'
2
+ require 'ostruct'
3
+ require 'json'
4
+ require 'erb'
5
+
6
+ module ReleaseMe
7
+ module Adapter
8
+
9
+ # @return [Hash] - adapter config
10
+ # @param [String] - path to the directory in which you want to check
11
+ def adapter_config(project_path = Dir.pwd)
12
+ path = project_path || Dir.pwd
13
+ config = local_config(path) || detect_adapter_config(path)
14
+ raise "Cannot find config" if config.nil?
15
+ adapter = OpenStruct.new(config)
16
+ adapter[:version_file] = version_file(adapter, path)
17
+ adapter[:current_version] = current_version(adapter, adapter[:version_file])
18
+ adapter
19
+ end
20
+
21
+ def adapter_list
22
+ adapters.keys
23
+ end
24
+
25
+ # @return [Hash] adapter settings found in the project directory
26
+ # @param [String] - path to the directory in which you want to check
27
+ def local_config(path = Dir.pwd)
28
+ file = File.join(path, '.release_me.yaml')
29
+ if File.exists?(file)
30
+ data = load_adapter(file)
31
+ data.fetch('adapter', nil)
32
+ end
33
+ end
34
+
35
+ def version_file(adapter, path)
36
+ Dir.glob(File.join(path, adapter.version_file_relative_path)).first
37
+ end
38
+
39
+ private
40
+
41
+ # @param [OpenStruct] - adapter config
42
+ # @param [String] - path to version file
43
+ def current_version(adapter, file)
44
+ file_type = File.extname(file).downcase
45
+ case file_type
46
+ when '.json'
47
+ JSON.parse(File.read(file))[adapter.version_field]
48
+ when '.yaml', '.yml'
49
+ YAML.load_file(file)[adapter.version_field]
50
+ when '.rb'
51
+ # reads in the ruby version file and should return the version if
52
+ # that is the last thing executed
53
+ eval(File.read(file))
54
+ else
55
+ nil
56
+ end
57
+ end
58
+
59
+ # @return [Hash] - adapter config type
60
+ # @param [String] - path to the directory in which you want to check
61
+ def detect_adapter_config(path = Dir.pwd)
62
+ type, config = adapters.find do | _, adapter_config|
63
+ pattern = File.join(path, adapter_config['detection_pattern']) || ''
64
+ Dir.glob(pattern).count > 0
65
+ end
66
+ config
67
+ end
68
+
69
+ # @param [String] path to adapter file
70
+ # @return [Hash] rendered object from YAML
71
+ # renders as an erb file
72
+ def load_adapter(file_name)
73
+ template = ERB.new File.new(file_name).read
74
+ YAML.load(template.result(binding))
75
+ end
76
+
77
+ # @return [Hash] adapter types
78
+ def adapters
79
+ unless @adapters
80
+ @adapters = {}
81
+ dir = File.join(File.dirname(File.expand_path(__FILE__)), 'adapters')
82
+ files = Dir.glob(File.join(dir, '*.yaml'))
83
+ files.each do |file_name|
84
+ data = load_adapter(file_name)
85
+ @adapters[data['adapter_name']] = data
86
+ end
87
+ end
88
+ @adapters
89
+ end
90
+ end
91
+ end
@@ -0,0 +1,10 @@
1
+ # the relative path to the file to update
2
+ version_file_relative_path: 'lib/*/version.rb'
3
+ # the field in the file above to update
4
+ version_field: 'VERSION'
5
+ # type of versioning scheme, currently not used
6
+ version_type: 'semver'
7
+ # adapter name
8
+ adapter_name: 'gem'
9
+ # used to detect that this is a gem, this should be a glob
10
+ detection_pattern: '*.gemspec'
@@ -0,0 +1,10 @@
1
+ # the relative path to the file to update
2
+ version_file_relative_path: 'metadata.json'
3
+ # the field in the file above to update
4
+ version_field: 'version'
5
+ # type of versioning scheme
6
+ version_type: 'semver'
7
+ # adapter name
8
+ adapter_name: 'puppet'
9
+ # used to detect that this is a puppet module type, this should be a glob
10
+ detection_pattern: 'manifests/*.pp'
@@ -0,0 +1,134 @@
1
+ require_relative 'bump_version'
2
+ require_relative 'vcs_provider'
3
+
4
+ module ReleaseMe
5
+ class BumpTag
6
+ attr_reader :options, :version_instance
7
+ include ReleaseMe::VcsProvider
8
+
9
+ def initialize(options)
10
+ @options = options
11
+ opts = {
12
+ :json => true,
13
+ :version => options[:version_type]
14
+ }
15
+ @version_instance = ReleaseMe::BumpVersion.new(opts)
16
+ end
17
+
18
+ def private_token
19
+ vcs_config.private_token
20
+ end
21
+
22
+ def commits_url
23
+ @commit_url ||= URI("#{project_url}/#{vcs_config.commits_path}")
24
+ end
25
+
26
+ def project_url
27
+ @project_url ||= "#{vcs_config.base_url}/#{vcs_config.project_id}"
28
+ end
29
+
30
+ def tags_url
31
+ @tags_url ||= URI("#{project_url}/#{vcs_config.tags_path}")
32
+ end
33
+
34
+ def vcs_config
35
+ @vcs_config ||= provider_config(options[:project_path])
36
+ end
37
+
38
+ # @return [Hash] output from bump version
39
+ def bump_version_file
40
+ JSON.parse(version_instance.run)
41
+ end
42
+
43
+ def file_update_body_request(file_contents, message)
44
+ {
45
+ id: vcs_config.project_id,
46
+ branch_name: vcs_config.branch_name,
47
+ author_email: vcs_config.author_email,
48
+ author_name: vcs_config.author_name,
49
+ commit_message: message,
50
+ actions: [
51
+ {
52
+ action: :update,
53
+ file_path: version_instance.app_version_file,
54
+ content: file_contents
55
+ }
56
+ ]
57
+ }.to_json
58
+ end
59
+
60
+ def tag_body_request(tag_name, commit_id)
61
+ {
62
+ id: vcs_config.project_id,
63
+ tag_name: tag_name,
64
+ ref: commit_id, # or git rev-parse HEAD
65
+ # messasge:
66
+ # release_description:
67
+ }.to_json
68
+ end
69
+
70
+ # @return [String] commit id of submitted body
71
+ def update_version(version_object)
72
+ new_version = version_object['new_version']
73
+ file_content = version_object['file_content']
74
+ message = "Auto tagged to #{new_version}"
75
+ body = file_update_body_request(file_content, message)
76
+ response = send_data(commits_url, body)
77
+ # the id may be specific to gitlab api
78
+ JSON.parse(response)['id']
79
+ end
80
+
81
+ # @param [String] - new version string
82
+ # @param [String] - commit it to tag
83
+ # @return [String] - json encoded result from http call
84
+ def tag(version, commit_id)
85
+ body = tag_body_request(version, commit_id)
86
+ send_data(tags_url, body, :post)
87
+ end
88
+
89
+ # @param [URI] uri of the request
90
+ # @param [Object] Body of request is a hash or array
91
+ # @param [:put or :post] method to use when sending data to gitlab
92
+ # @return [String] message body for url call in JSON format
93
+ def send_data(uri, body, method = nil)
94
+ use_ssl = uri.scheme == 'https'
95
+ conn = Net::HTTP.new(uri.host, uri.port)
96
+ # conn.set_debug_output
97
+ conn.use_ssl = use_ssl
98
+ # Don't verify
99
+ conn.verify_mode = OpenSSL::SSL::VERIFY_NONE if vcs_config.no_verify
100
+ request = case method
101
+ when :put
102
+ Net::HTTP::Put.new(uri.path)
103
+ else
104
+ Net::HTTP::Post.new(uri.path)
105
+ end
106
+ request.body = body
107
+ # private token is specific to gitlab and must be set
108
+ request['PRIVATE-TOKEN'] = vcs_config.private_token
109
+ request.content_type = 'application/json'
110
+ if options[:dry_run]
111
+ puts body
112
+ else
113
+ response = conn.request(request)
114
+ if response.is_a? Net::HTTPSuccess
115
+ response.body
116
+ else
117
+ puts response.code
118
+ puts response.body
119
+ exit 1
120
+ end
121
+ end
122
+ end
123
+
124
+ def run
125
+ version_output = bump_version_file
126
+ unless options[:dry_run]
127
+ commit_id = update_version(version_output)
128
+ tag(version_output['new_version'], commit_id) unless @options[:no_tagging]
129
+ end
130
+ "Tagged: #{version_output['new_version']}"
131
+ end
132
+
133
+ end
134
+ end
@@ -0,0 +1,63 @@
1
+ require 'json'
2
+ require 'time'
3
+ require_relative 'adapter'
4
+ # either pass in the tag name or allow the script to create one
5
+ #
6
+ # outputs the version that was written to the file
7
+ module ReleaseMe
8
+ class BumpVersion
9
+ include ReleaseMe::Adapter
10
+ attr_reader :options
11
+
12
+ def initialize(options)
13
+ @options = options
14
+ end
15
+
16
+ def app_version_file
17
+ app_config.version_file
18
+ end
19
+
20
+ def version_type
21
+ options[:version]
22
+ end
23
+
24
+ def app_config
25
+ @app_config ||= adapter_config(options[:project_path])
26
+ end
27
+
28
+ def new_version
29
+ unless @new_version
30
+ case version_type
31
+ when :commit
32
+ @new_version = `git rev-parse HEAD`.chomp[0..8]
33
+ when :time
34
+ @new_version = Time.now.strftime('%Y.%m.%d.%H%M')
35
+ when :semver
36
+ @new_version = app_config.current_version.next
37
+ else
38
+ @new_version = options[:version] || app_config.current_version.next
39
+ end
40
+ end
41
+ @new_version
42
+ end
43
+
44
+ def run
45
+ app_config_lines = File.read(app_config.version_file)
46
+ app_config_lines.gsub!(app_config.current_version, new_version)
47
+ debug_message = "updated version string from #{app_config.current_version} to #{new_version}"
48
+ if options[:json]
49
+ output = JSON.pretty_generate(message: debug_message,
50
+ file_content: app_config_lines,
51
+ new_version: new_version,
52
+ old_version: app_config.current_version)
53
+ else
54
+ STDERR.puts debug_message
55
+ File.write(app_config.version_file, app_config_lines) unless options[:dry_run]
56
+ output = app_config_lines
57
+ end
58
+ output
59
+ end
60
+ end
61
+ end
62
+
63
+
@@ -0,0 +1,68 @@
1
+ require 'yaml'
2
+ require 'erb'
3
+ require 'ostruct'
4
+
5
+ module ReleaseMe
6
+ module VcsProvider
7
+
8
+ # @return [Hash] - adapter config
9
+ # @param [String] - path to the directory in which you want to check
10
+ def provider_config(project_path = Dir.pwd)
11
+ path = project_path || Dir.pwd
12
+ config = local_config(path) || detect_provider_config
13
+ raise "Cannot find config" if config.nil?
14
+ if vcs = config.fetch('vcs', nil)
15
+ pdata = provider_data(vcs['provider'])
16
+ config = pdata.merge(vcs) # merge and override the default provider data
17
+ end
18
+ OpenStruct.new(config)
19
+ end
20
+
21
+ private
22
+
23
+ def provider_data(provider)
24
+ load_provider(File.join(provider_dir, "#{provider}.yaml"))
25
+ end
26
+
27
+ # @return [Hash] adapter settings found in the project directory
28
+ # @param [String] - path to the directory in which you want to check
29
+ def local_config(path = Dir.pwd)
30
+ file = File.join(path, '.release_me.yaml')
31
+ load_provider(file) if File.exists?(file)
32
+ end
33
+
34
+ # @param [String] path to adapter file
35
+ # @return [Hash] rendered object from YAML
36
+ # renders as an erb file
37
+ def load_provider(file_name)
38
+ template = ERB.new File.read(file_name)
39
+ YAML.load(template.result(binding))
40
+ end
41
+
42
+ # @return [Hash] - adapter config type
43
+ # @param [String] - path to the directory in which you want to check
44
+ def detect_provider_config
45
+ type, config = providers.find do | _, c|
46
+ c['detected'] # return first provider that could be used
47
+ end
48
+ config
49
+ end
50
+
51
+ def provider_dir
52
+ @provider_dir ||= File.join(File.dirname(File.expand_path(__FILE__)), 'vcs_providers')
53
+ end
54
+
55
+ # @return [Hash] provider types
56
+ def providers
57
+ unless @providers
58
+ @providers = {}
59
+ files = Dir.glob(File.join(provider_dir, '*.yaml'))
60
+ files.each do |file_name|
61
+ data = load_provider(file_name)
62
+ @providers[data['provider_name']] = data
63
+ end
64
+ end
65
+ @providers
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,13 @@
1
+ # base url to gitlab instance, defaults to url provided by CI runner
2
+ # or can override in the local config
3
+ base_url: <%= require 'uri'; "https://#{URI(ENV['CI_PROJECT_URL']).host.to_s}/api/v3/projects" %>
4
+ project_id: <%= ENV['CI_PROJECT_ID'] %>
5
+ # private token is specific to gitlab and must be set in the variables settings
6
+ private_token: <%= ENV['PRIVATE_TOKEN'] %>
7
+ provider_name: 'gitlab'
8
+ version_requirement: '8.13'
9
+ # if the variable is present then this provider should be used
10
+ detected: <%= !! ENV['GITLAB_CI'] %>
11
+ tags_path: 'repository/tags'
12
+ commits_path: 'repository/commits'
13
+ no_verify: true
@@ -0,0 +1,3 @@
1
+ module ReleaseMe
2
+ VERSION = "0.1.0"
3
+ end
data/lib/release_me.rb ADDED
@@ -0,0 +1,3 @@
1
+ require "release_me/version"
2
+
3
+
@@ -0,0 +1,38 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'release_me/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "release_me"
8
+ spec.version = ReleaseMe::VERSION
9
+ spec.authors = ["Corey Osman"]
10
+ spec.email = ["corey@nwops.io"]
11
+
12
+ spec.summary = %q{Release related scripts for any type of code}
13
+ spec.description = %q{Automation scripts that help you release code}
14
+ spec.homepage = "https://github.com/nwops/release_me"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ # if spec.respond_to?(:metadata)
20
+ # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
21
+ # else
22
+ # raise "RubyGems 2.0 or newer is required to protect against " \
23
+ # "public gem pushes."
24
+ # end
25
+
26
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
27
+ f.match(%r{^(test|spec|features)/})
28
+ end
29
+ spec.bindir = "exe"
30
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ["lib"]
32
+
33
+ spec.add_development_dependency "bundler", "~> 1.13"
34
+ spec.add_development_dependency "rake", "~> 10.0"
35
+ spec.add_development_dependency "rspec", "~> 3.0"
36
+ spec.add_development_dependency "pry"
37
+
38
+ end
metadata ADDED
@@ -0,0 +1,126 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: release_me
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Corey Osman
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-11-23 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.13'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.13'
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.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Automation scripts that help you release code
70
+ email:
71
+ - corey@nwops.io
72
+ executables:
73
+ - bump_and_tag
74
+ - bump_version
75
+ extensions: []
76
+ extra_rdoc_files: []
77
+ files:
78
+ - ".gitignore"
79
+ - ".release_me.yaml"
80
+ - ".rspec"
81
+ - ".travis.yml"
82
+ - CODE_OF_CONDUCT.md
83
+ - Gemfile
84
+ - LICENSE
85
+ - LICENSE.txt
86
+ - README.md
87
+ - Rakefile
88
+ - bin/console
89
+ - bin/setup
90
+ - exe/bump_and_tag
91
+ - exe/bump_version
92
+ - lib/release_me.rb
93
+ - lib/release_me/adapter.rb
94
+ - lib/release_me/adapters/gem.yaml
95
+ - lib/release_me/adapters/puppet.yaml
96
+ - lib/release_me/bump_tag.rb
97
+ - lib/release_me/bump_version.rb
98
+ - lib/release_me/vcs_provider.rb
99
+ - lib/release_me/vcs_providers/gitlab.yaml
100
+ - lib/release_me/version.rb
101
+ - release_me.gemspec
102
+ homepage: https://github.com/nwops/release_me
103
+ licenses:
104
+ - MIT
105
+ metadata: {}
106
+ post_install_message:
107
+ rdoc_options: []
108
+ require_paths:
109
+ - lib
110
+ required_ruby_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ required_rubygems_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ requirements: []
121
+ rubyforge_project:
122
+ rubygems_version: 2.5.1
123
+ signing_key:
124
+ specification_version: 4
125
+ summary: Release related scripts for any type of code
126
+ test_files: []