devops_helper 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 +7 -0
- data/.gitignore +12 -0
- data/.travis.yml +6 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +7 -0
- data/LICENSE.txt +21 -0
- data/README.md +44 -0
- data/Rakefile +16 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/devops_helper.gemspec +39 -0
- data/lib/Rakefile +5 -0
- data/lib/devops_helper.rb +33 -0
- data/lib/devops_helper/gem_core_helper.rb +20 -0
- data/lib/devops_helper/gem_rake_helper.rb +34 -0
- data/lib/devops_helper/gem_version_helper.rb +142 -0
- data/lib/devops_helper/global.rb +26 -0
- data/lib/devops_helper/tasks/release/gem.rake +113 -0
- data/lib/devops_helper/vcs_helper.rb +47 -0
- data/lib/devops_helper/version.rb +3 -0
- data/lib/devops_helper/version_store.rb +61 -0
- metadata +133 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: de680446ea31db8037dc619b1eef1fad1936a57afdcdd9495cd35a411a61f7a4
|
4
|
+
data.tar.gz: 244a9bb9f7b792a8af1b3ca2df4f7a7b7a111686dac4626306568ef10a01c9b8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d61ba38f0de3919d554e3a036dd773487d89119372ce5d3e0bf612cae2df160d3a21d2df4cef2bee9e4e68c8304111e5aaa6f10f03943aa3b988b395eb64571d
|
7
|
+
data.tar.gz: 5eeb5192dcd6d694bb3a1d7d82fc2a0fa6abb56e2cc72f037c0f9201092452ba46133473d78883db03db9789e306e81f41b0afe6e611f666b842f379fd0a2401
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -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 chrisliaw@antrapol.com. 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 [https://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: https://contributor-covenant.org
|
74
|
+
[version]: https://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 Chris
|
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
|
+
# DevopsHelper
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/devops_helper`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'devops_helper'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle install
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install devops_helper
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
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).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/devops_helper. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/devops_helper/blob/master/CODE_OF_CONDUCT.md).
|
36
|
+
|
37
|
+
|
38
|
+
## License
|
39
|
+
|
40
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
41
|
+
|
42
|
+
## Code of Conduct
|
43
|
+
|
44
|
+
Everyone interacting in the DevopsHelper project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/devops_helper/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require "rake/testtask"
|
3
|
+
|
4
|
+
require "devops_helper"
|
5
|
+
|
6
|
+
#spec = Gem::Specification.find_by_name "devops_helper"
|
7
|
+
#rf = "#{spec.gem_dir}/lib/Rakefile"
|
8
|
+
#load rf
|
9
|
+
|
10
|
+
Rake::TestTask.new(:test) do |t|
|
11
|
+
t.libs << "test"
|
12
|
+
t.libs << "lib"
|
13
|
+
t.test_files = FileList["test/**/*_test.rb"]
|
14
|
+
end
|
15
|
+
|
16
|
+
task :default => :test
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "devops_helper"
|
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(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
require_relative 'lib/devops_helper/version'
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "devops_helper"
|
5
|
+
spec.version = DevopsHelper::VERSION
|
6
|
+
spec.authors = ["Chris"]
|
7
|
+
spec.email = ["chrisliaw@antrapol.com"]
|
8
|
+
|
9
|
+
spec.summary = %q{DevOps Helper to assist in DevOps operation}
|
10
|
+
spec.description = %q{ }
|
11
|
+
spec.homepage = "https://github.com/chrisliaw/devops_helper"
|
12
|
+
spec.license = "MIT"
|
13
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
|
14
|
+
|
15
|
+
#spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
|
16
|
+
|
17
|
+
#spec.metadata["homepage_uri"] = spec.homepage
|
18
|
+
#spec.metadata["source_code_uri"] = "TODO: Put your gem's public repo URL here."
|
19
|
+
#spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
|
20
|
+
|
21
|
+
# Specify which files should be added to the gem when it is released.
|
22
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
23
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
24
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
25
|
+
end
|
26
|
+
spec.bindir = "exe"
|
27
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
|
+
spec.require_paths = ["lib"]
|
29
|
+
|
30
|
+
spec.add_dependency 'toolrack', '~> 0.4.0'
|
31
|
+
spec.add_dependency 'tlogger', '~> 0.22.0'
|
32
|
+
spec.add_dependency 'tty-prompt'
|
33
|
+
|
34
|
+
spec.add_dependency 'gvcs', '~> 0.1.0'
|
35
|
+
spec.add_dependency 'git_cli', '~> 0.6.0'
|
36
|
+
|
37
|
+
#spec.add_dependency 'rubygems-tasks'
|
38
|
+
|
39
|
+
end
|
data/lib/Rakefile
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require "devops_helper/version"
|
2
|
+
|
3
|
+
require "devops_helper/gem_core_helper"
|
4
|
+
require "devops_helper/gem_version_helper"
|
5
|
+
require "devops_helper/gem_rake_helper"
|
6
|
+
require "devops_helper/vcs_helper"
|
7
|
+
|
8
|
+
module DevopsHelper
|
9
|
+
class Error < StandardError; end
|
10
|
+
# Your code goes here...
|
11
|
+
|
12
|
+
class GemReleaseHelper
|
13
|
+
include GemCoreHelper
|
14
|
+
include GemVersionHelper
|
15
|
+
include GemRakeHelper
|
16
|
+
end
|
17
|
+
|
18
|
+
class VcsHelper
|
19
|
+
include GvcsHelper
|
20
|
+
|
21
|
+
def initialize(root, opts = { })
|
22
|
+
@logger = opts[:logger] || Global.instance.logger
|
23
|
+
@root = root
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
spec = Gem::Specification.find_by_name "devops_helper"
|
30
|
+
rf = "#{spec.gem_dir}/lib/Rakefile"
|
31
|
+
load rf
|
32
|
+
|
33
|
+
|
@@ -0,0 +1,20 @@
|
|
1
|
+
|
2
|
+
require 'toolrack'
|
3
|
+
require 'tty-prompt'
|
4
|
+
|
5
|
+
require_relative 'version_store'
|
6
|
+
|
7
|
+
module DevopsHelper
|
8
|
+
module GemCoreHelper
|
9
|
+
include Antrapol::ToolRack::ConditionUtils
|
10
|
+
|
11
|
+
def find_gemspec(root)
|
12
|
+
if is_empty?(root)
|
13
|
+
raise DevopsHelper::Error, "Root path '#{root}' to find_gemspec is empty"
|
14
|
+
else
|
15
|
+
Dir.glob(File.join(root,"*.gemspec")).first
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
# include task like 'rake build'
|
4
|
+
require 'bundler/gem_tasks'
|
5
|
+
# another way to build the gem
|
6
|
+
#require 'rubygems/commands/build_command'
|
7
|
+
|
8
|
+
module DevopsHelper
|
9
|
+
module GemRakeHelper
|
10
|
+
|
11
|
+
def build_gem
|
12
|
+
t = find_build_task
|
13
|
+
raise DevopsHelper::Error, "Cannot find the build task. Please ensure the GEM is configured properly" if is_empty?(t)
|
14
|
+
execute_build_task(t)
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
def find_build_task
|
19
|
+
task = nil
|
20
|
+
Rake::Task.tasks.each do |t|
|
21
|
+
if t.name == "build"
|
22
|
+
task = t
|
23
|
+
break
|
24
|
+
end
|
25
|
+
end
|
26
|
+
task
|
27
|
+
end
|
28
|
+
|
29
|
+
def execute_build_task(task)
|
30
|
+
task.execute if not_empty?(task) and task.is_a?(Rake::Task)
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,142 @@
|
|
1
|
+
|
2
|
+
require 'toolrack'
|
3
|
+
|
4
|
+
module DevopsHelper
|
5
|
+
module GemVersionHelper
|
6
|
+
include Antrapol::ToolRack::ConditionUtils
|
7
|
+
|
8
|
+
def find_gem_version_file(root)
|
9
|
+
if is_empty?(root)
|
10
|
+
raise DevopsHelper::Error, "Root path '#{root}' to find_version_file is empty"
|
11
|
+
else
|
12
|
+
Dir.glob(File.join(root,"**/version.rb"))
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def get_version_record(root)
|
17
|
+
VersionStore.load(root)
|
18
|
+
end # find_last_version
|
19
|
+
|
20
|
+
def prompt_version(gname,current,currentAt)
|
21
|
+
|
22
|
+
current = "" if is_empty?(current)
|
23
|
+
|
24
|
+
prompt = TTY::Prompt.new
|
25
|
+
|
26
|
+
ops = []
|
27
|
+
ops << increase_version(current,1)
|
28
|
+
ops << increase_version(current,2)
|
29
|
+
ops << increase_version(current,3)
|
30
|
+
ops << "Custom"
|
31
|
+
ops << "Quit"
|
32
|
+
|
33
|
+
curInfo = []
|
34
|
+
if not_empty?(current)
|
35
|
+
curInfo << "Current version is '#{current}'"
|
36
|
+
curInfo << "created at #{currentAt}" if not_empty?(currentAt)
|
37
|
+
else
|
38
|
+
curInfo << "There is not a previous version found in record."
|
39
|
+
end
|
40
|
+
prompt.ok curInfo.join(" ")
|
41
|
+
|
42
|
+
begin
|
43
|
+
sel = prompt.select("Version of this release of '#{gname}'", ops)
|
44
|
+
if sel != "Quit"
|
45
|
+
if sel == "Custom"
|
46
|
+
loop do
|
47
|
+
sel = prompt.ask("Please provide the custom version number: ") do |q|
|
48
|
+
q.required true
|
49
|
+
end
|
50
|
+
|
51
|
+
pro = prompt.yes?("Proceed using version '#{sel}'?")
|
52
|
+
break if pro
|
53
|
+
end # loop
|
54
|
+
end
|
55
|
+
|
56
|
+
sel
|
57
|
+
|
58
|
+
else
|
59
|
+
-1
|
60
|
+
end
|
61
|
+
rescue TTY::Reader::InputInterrupt
|
62
|
+
STDERR.puts "\n\nAborted"
|
63
|
+
exit(3)
|
64
|
+
end
|
65
|
+
|
66
|
+
end # prompt_version
|
67
|
+
|
68
|
+
def rewrite_gem_version_file(version_file, newVersion)
|
69
|
+
if not_empty?(version_file) and not_empty?(version_file)
|
70
|
+
tmpFile = File.join(File.dirname(version_file),"version.rb.tmp")
|
71
|
+
FileUtils.mv(version_file,tmpFile)
|
72
|
+
|
73
|
+
File.open(version_file,"w") do |f|
|
74
|
+
File.open(tmpFile,"r").each_line do |l|
|
75
|
+
if l =~ /VERSION/
|
76
|
+
indx = (l =~ /=/)
|
77
|
+
ll = "#{l[0..indx]} \"#{newVersion}\""
|
78
|
+
f.puts ll
|
79
|
+
else
|
80
|
+
f.write l
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
FileUtils.rm tmpFile
|
86
|
+
|
87
|
+
else
|
88
|
+
raise DevopsHelper::Error, "Given version file '#{version_file}' does not exist"
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
def increase_version(input, digitNo)
|
93
|
+
input = "" if is_empty?(input)
|
94
|
+
|
95
|
+
si = input.split(".")
|
96
|
+
cnt = 0
|
97
|
+
res = []
|
98
|
+
if si.length >= digitNo
|
99
|
+
Global.instance.logger.debug "Given length longer then digit no"
|
100
|
+
|
101
|
+
hit = false
|
102
|
+
si.each do |i|
|
103
|
+
# digitNo = start at 1
|
104
|
+
if (cnt+1) < digitNo
|
105
|
+
res << i
|
106
|
+
elsif cnt+1 == digitNo
|
107
|
+
i = i.to_i
|
108
|
+
res << (i += 1)
|
109
|
+
else
|
110
|
+
res << "0"
|
111
|
+
end
|
112
|
+
|
113
|
+
cnt += 1
|
114
|
+
|
115
|
+
end
|
116
|
+
|
117
|
+
else
|
118
|
+
|
119
|
+
Global.instance.logger.debug "Given digit no longer then length"
|
120
|
+
|
121
|
+
res = si
|
122
|
+
cnt = si.length
|
123
|
+
(0...(digitNo-si.length)-1).each do |i|
|
124
|
+
res << "0"
|
125
|
+
end
|
126
|
+
|
127
|
+
res << "1"
|
128
|
+
|
129
|
+
end
|
130
|
+
|
131
|
+
if res.length == 1
|
132
|
+
res << "0"
|
133
|
+
elsif res.length == 2 and res[-1].to_i != 0
|
134
|
+
res << "0"
|
135
|
+
end
|
136
|
+
|
137
|
+
res.join(".")
|
138
|
+
|
139
|
+
end
|
140
|
+
|
141
|
+
end
|
142
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
|
2
|
+
require 'singleton'
|
3
|
+
require 'tlogger'
|
4
|
+
require 'fileutils'
|
5
|
+
|
6
|
+
module DevopsHelper
|
7
|
+
class Global
|
8
|
+
include Singleton
|
9
|
+
|
10
|
+
attr_accessor :logger
|
11
|
+
attr_reader :root_store
|
12
|
+
def initialize()
|
13
|
+
debug = ENV['DevOpsHelper_Debug']
|
14
|
+
debugOut = ENV['DevOpsHelper_DebugOut'] || STDOUT
|
15
|
+
|
16
|
+
if debug.nil?
|
17
|
+
@logger = Tlogger.new('devops_helper.log', 5, 1024*1024*10)
|
18
|
+
else
|
19
|
+
@logger = Tlogger.new(debugOut)
|
20
|
+
end
|
21
|
+
@root_store = File.join(Dir.home,".devops_helper")
|
22
|
+
FileUtils.mkdir_p(@root_store) if not File.exist?(@root_store)
|
23
|
+
end # initialize
|
24
|
+
|
25
|
+
end # class Global
|
26
|
+
end # module DevopsHelper
|
@@ -0,0 +1,113 @@
|
|
1
|
+
|
2
|
+
require 'toolrack'
|
3
|
+
include Antrapol::ToolRack::ConditionUtils
|
4
|
+
|
5
|
+
require 'devops_helper'
|
6
|
+
|
7
|
+
# include task like 'rake build'
|
8
|
+
require 'bundler/gem_tasks'
|
9
|
+
# another way to build the gem
|
10
|
+
#require 'rubygems/commands/build_command'
|
11
|
+
|
12
|
+
require 'fileutils'
|
13
|
+
|
14
|
+
desc "Some simple rake tasks to assist gem developer in releasing new version of gem"
|
15
|
+
|
16
|
+
namespace :devops do
|
17
|
+
|
18
|
+
task :gem_release do
|
19
|
+
|
20
|
+
STDOUT.puts "Managed gem release V#{DevopsHelper::VERSION}"
|
21
|
+
|
22
|
+
wd = Dir.getwd
|
23
|
+
tp = TTY::Prompt.new
|
24
|
+
|
25
|
+
vh = DevopsHelper::VcsHelper.new(wd)
|
26
|
+
if vh.is_workspace?
|
27
|
+
|
28
|
+
begin
|
29
|
+
if vh.has_pending_changes? or vh.has_new_changes?
|
30
|
+
cc = tp.yes?("There are pending changes not yet commit. Commit first? ")
|
31
|
+
if cc
|
32
|
+
STDOUT.puts "Commit the changes first before release"
|
33
|
+
exit(0)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
rescue TTY::Reader::InputInterrupt
|
37
|
+
STDOUT.puts "\n\nAborted"
|
38
|
+
exit(1)
|
39
|
+
end
|
40
|
+
|
41
|
+
end # is_workspace?
|
42
|
+
|
43
|
+
rh = DevopsHelper::GemReleaseHelper.new
|
44
|
+
spec = rh.find_gemspec(wd)
|
45
|
+
|
46
|
+
vf = rh.find_gem_version_file(wd)
|
47
|
+
if vf.length > 1
|
48
|
+
# more then one. User has to select
|
49
|
+
svf = vf.first
|
50
|
+
else
|
51
|
+
svf = vf.first
|
52
|
+
end
|
53
|
+
|
54
|
+
if not_empty?(spec) #and not_empty?(svf)
|
55
|
+
|
56
|
+
vs = rh.get_version_record(wd)
|
57
|
+
gs = Gem::Specification.load(spec)
|
58
|
+
lstVer = vs.last_version(gs.name)
|
59
|
+
if not is_empty?(lstVer)
|
60
|
+
targetVersion = rh.prompt_version(gs.name, lstVer[:version], lstVer[:created_at])
|
61
|
+
else
|
62
|
+
targetVersion = rh.prompt_version(gs.name, "", nil)
|
63
|
+
end
|
64
|
+
|
65
|
+
if targetVersion == -1
|
66
|
+
STDERR.puts "Aborted"
|
67
|
+
exit(1)
|
68
|
+
end
|
69
|
+
|
70
|
+
if not_empty?(svf)
|
71
|
+
rh.rewrite_gem_version_file(svf,targetVersion)
|
72
|
+
STDOUT.puts "Gem version file rewritten"
|
73
|
+
|
74
|
+
if vh.is_workspace?
|
75
|
+
# commit changes
|
76
|
+
vh.add(svf)
|
77
|
+
vh.commit("Automated commit by DevOps Helper during release process", { files: [svf] })
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
81
|
+
|
82
|
+
if vh.is_workspace?
|
83
|
+
begin
|
84
|
+
tagSrc = tp.yes?("Tag the source code for this release? ")
|
85
|
+
if tagSrc
|
86
|
+
msg = tp.ask("Please provide message for this tag (optional) : ", default: "Tagged version '#{targetVersion}' by DevOps Helper")
|
87
|
+
msg = "Automated tagging version '#{targetVersion}' by DevOps Helper" if is_empty?(msg)
|
88
|
+
vh.create_tag(targetVersion, msg)
|
89
|
+
end
|
90
|
+
rescue TTY::Reader::InputInterrupt
|
91
|
+
STDERR.puts "\n\nAborted"
|
92
|
+
exit(1)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
res = rh.build_gem
|
97
|
+
STDOUT.puts "Gem '#{gs.name}' built"
|
98
|
+
|
99
|
+
vs.register_version(gs.name, targetVersion)
|
100
|
+
vs.save(wd)
|
101
|
+
STDOUT.puts "Version '#{targetVersion}' registered"
|
102
|
+
|
103
|
+
elsif is_empty?(spec)
|
104
|
+
STDERR.puts "gemspec file not found at '#{wd}'"
|
105
|
+
exit(2)
|
106
|
+
elsif is_empty?(svf)
|
107
|
+
STDERR.puts "Cannot find version.rb to update GEM version"
|
108
|
+
exit(2)
|
109
|
+
end
|
110
|
+
|
111
|
+
end # gem_release
|
112
|
+
|
113
|
+
end # devops
|
@@ -0,0 +1,47 @@
|
|
1
|
+
|
2
|
+
require 'gvcs'
|
3
|
+
require 'git_cli'
|
4
|
+
|
5
|
+
module DevopsHelper
|
6
|
+
module GvcsHelper
|
7
|
+
|
8
|
+
def has_pending_changes?
|
9
|
+
ws = Gvcs::Workspace.new(vcs,@root)
|
10
|
+
|
11
|
+
mst, mf = ws.modified_files
|
12
|
+
dst, df = ws.deleted_files
|
13
|
+
|
14
|
+
mf.length > 0 or df.length > 0
|
15
|
+
end
|
16
|
+
|
17
|
+
def has_new_changes?
|
18
|
+
ws = Gvcs::Workspace.new(vcs,@root)
|
19
|
+
|
20
|
+
nst, nf = ws.new_files
|
21
|
+
|
22
|
+
nf.length > 0
|
23
|
+
end
|
24
|
+
|
25
|
+
def is_workspace?
|
26
|
+
Gvcs::Workspace.new(vcs,@root).is_workspace?
|
27
|
+
end
|
28
|
+
|
29
|
+
def method_missing(mtd, *args, &block)
|
30
|
+
ws = Gvcs::Workspace.new(vcs,@root)
|
31
|
+
if ws.respond_to?(mtd)
|
32
|
+
ws.send(mtd,*args,&block)
|
33
|
+
else
|
34
|
+
super
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
def vcs
|
40
|
+
if is_empty?(@vcs)
|
41
|
+
@vcs = Gvcs::Vcs.new
|
42
|
+
end
|
43
|
+
@vcs
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
|
2
|
+
require_relative "global"
|
3
|
+
|
4
|
+
require 'yaml'
|
5
|
+
|
6
|
+
module DevopsHelper
|
7
|
+
|
8
|
+
class VersionStore
|
9
|
+
|
10
|
+
VERSTORE_NAME = ".version_history.yml"
|
11
|
+
attr_accessor :history
|
12
|
+
|
13
|
+
def initialize(history = { }, opts = { })
|
14
|
+
@history = history
|
15
|
+
@root = opts[:root]
|
16
|
+
@logger = opts[:logger] || Global.instance.logger
|
17
|
+
end
|
18
|
+
|
19
|
+
def register_version(gname, version)
|
20
|
+
raise DevopsHelper::Error, "Gem name cannot be empty" if is_empty?(gname)
|
21
|
+
raise DevopsHelper::Error, "Version cannot be empty" if is_empty?(version)
|
22
|
+
|
23
|
+
# todo validate version is in form 'x.y.z' and not 'vx.y.z' or 'version x.y.z'
|
24
|
+
nm = gname.strip
|
25
|
+
@history[nm] = [] if not @history.keys.include?(nm)
|
26
|
+
verInfo = { }
|
27
|
+
verInfo[:version] = version
|
28
|
+
verInfo[:created_at] = Time.now
|
29
|
+
@history[nm] << verInfo
|
30
|
+
@history[nm]
|
31
|
+
end # register_version
|
32
|
+
|
33
|
+
def last_version(gname)
|
34
|
+
if not_empty?(gname)
|
35
|
+
rec = @history[gname.strip]
|
36
|
+
rec.last if not_empty?(rec)
|
37
|
+
else
|
38
|
+
raise DevopsHelper::Error, "Gem name is empty"
|
39
|
+
end
|
40
|
+
end # last_version
|
41
|
+
|
42
|
+
|
43
|
+
def save(root = @root)
|
44
|
+
File.open(File.join(root,VERSTORE_NAME),"w") do |f|
|
45
|
+
f.write YAML.dump(@history)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.load(root)
|
50
|
+
path = File.join(root,VERSTORE_NAME)
|
51
|
+
if File.exist?(path)
|
52
|
+
hist = YAML.load(File.read(path))
|
53
|
+
VersionStore.new(hist, { root: root })
|
54
|
+
else
|
55
|
+
VersionStore.new
|
56
|
+
end
|
57
|
+
end # load
|
58
|
+
|
59
|
+
end # class VersionStore
|
60
|
+
|
61
|
+
end
|
metadata
ADDED
@@ -0,0 +1,133 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: devops_helper
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Chris
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-11-21 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: toolrack
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.4.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.4.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: tlogger
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.22.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.22.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: tty-prompt
|
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: gvcs
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.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: 0.1.0
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: git_cli
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.6.0
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 0.6.0
|
83
|
+
description: " "
|
84
|
+
email:
|
85
|
+
- chrisliaw@antrapol.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- ".travis.yml"
|
92
|
+
- CODE_OF_CONDUCT.md
|
93
|
+
- Gemfile
|
94
|
+
- LICENSE.txt
|
95
|
+
- README.md
|
96
|
+
- Rakefile
|
97
|
+
- bin/console
|
98
|
+
- bin/setup
|
99
|
+
- devops_helper.gemspec
|
100
|
+
- lib/Rakefile
|
101
|
+
- lib/devops_helper.rb
|
102
|
+
- lib/devops_helper/gem_core_helper.rb
|
103
|
+
- lib/devops_helper/gem_rake_helper.rb
|
104
|
+
- lib/devops_helper/gem_version_helper.rb
|
105
|
+
- lib/devops_helper/global.rb
|
106
|
+
- lib/devops_helper/tasks/release/gem.rake
|
107
|
+
- lib/devops_helper/vcs_helper.rb
|
108
|
+
- lib/devops_helper/version.rb
|
109
|
+
- lib/devops_helper/version_store.rb
|
110
|
+
homepage: https://github.com/chrisliaw/devops_helper
|
111
|
+
licenses:
|
112
|
+
- MIT
|
113
|
+
metadata: {}
|
114
|
+
post_install_message:
|
115
|
+
rdoc_options: []
|
116
|
+
require_paths:
|
117
|
+
- lib
|
118
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
119
|
+
requirements:
|
120
|
+
- - ">="
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: 2.3.0
|
123
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
124
|
+
requirements:
|
125
|
+
- - ">="
|
126
|
+
- !ruby/object:Gem::Version
|
127
|
+
version: '0'
|
128
|
+
requirements: []
|
129
|
+
rubygems_version: 3.1.4
|
130
|
+
signing_key:
|
131
|
+
specification_version: 4
|
132
|
+
summary: DevOps Helper to assist in DevOps operation
|
133
|
+
test_files: []
|