devops_assist 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
+ SHA256:
3
+ metadata.gz: 9341a00d87166f5a645d2d24b70554c4570a902f0349791c18ac17888ec935c6
4
+ data.tar.gz: d82621277b2d51615f4aa9f5dfb1e7e1bfcdc4951735fa87344b327e90f76a15
5
+ SHA512:
6
+ metadata.gz: 3c370df28626241e94c31b66aff7b36bca11ba78ccc78d5af9f62f4a8b3144ecaccbae6fb3993114d68c599d855944e458c0e82c6b376b462de7051305bc2f16
7
+ data.tar.gz: c59c1009ab2dae931096a9d6632aa14b0b0729cafdfa740a9c0469dbf3e8a5b7b95a6c9d31030329d7b7d522ee5beb4d73246351bb0d2844acb755fa6793cfb5
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in devops_assist.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "rspec", "~> 3.0"
11
+
12
+ #gem "git_cli", path: '../../git/git_cli'
13
+ #gem "git_cli_prompt", path: '../../git/git_cli_prompt'
14
+ #
15
+ #gem 'toolrack', path: '../../WIP/toolrack'
16
+
data/Gemfile.lock ADDED
@@ -0,0 +1,69 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ devops_assist (0.1.0)
5
+ git_cli
6
+ git_cli_prompt
7
+ gvcs
8
+ tlogger
9
+ toolrack
10
+ tty-prompt
11
+
12
+ GEM
13
+ remote: https://rubygems.org/
14
+ specs:
15
+ base58 (0.2.3)
16
+ diff-lcs (1.4.4)
17
+ git_cli (0.9.0)
18
+ gvcs
19
+ ptools (~> 1.4.0)
20
+ tlogger
21
+ toolrack
22
+ git_cli_prompt (0.2.0)
23
+ tlogger
24
+ toolrack
25
+ tty-prompt
26
+ gvcs (0.1.0)
27
+ pastel (0.8.0)
28
+ tty-color (~> 0.5)
29
+ ptools (1.4.2)
30
+ rake (13.0.6)
31
+ rspec (3.10.0)
32
+ rspec-core (~> 3.10.0)
33
+ rspec-expectations (~> 3.10.0)
34
+ rspec-mocks (~> 3.10.0)
35
+ rspec-core (3.10.1)
36
+ rspec-support (~> 3.10.0)
37
+ rspec-expectations (3.10.1)
38
+ diff-lcs (>= 1.2.0, < 2.0)
39
+ rspec-support (~> 3.10.0)
40
+ rspec-mocks (3.10.2)
41
+ diff-lcs (>= 1.2.0, < 2.0)
42
+ rspec-support (~> 3.10.0)
43
+ rspec-support (3.10.2)
44
+ tlogger (0.26.1)
45
+ toolrack (0.16.0)
46
+ base58
47
+ tlogger
48
+ tty-color (0.6.0)
49
+ tty-cursor (0.7.1)
50
+ tty-prompt (0.23.1)
51
+ pastel (~> 0.8)
52
+ tty-reader (~> 0.8)
53
+ tty-reader (0.9.0)
54
+ tty-cursor (~> 0.7)
55
+ tty-screen (~> 0.8)
56
+ wisper (~> 2.0)
57
+ tty-screen (0.8.1)
58
+ wisper (2.0.1)
59
+
60
+ PLATFORMS
61
+ x86_64-linux
62
+
63
+ DEPENDENCIES
64
+ devops_assist!
65
+ rake (~> 13.0)
66
+ rspec (~> 3.0)
67
+
68
+ BUNDLED WITH
69
+ 2.2.28
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # DevopsAssist
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_assist`. 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_assist'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install devops_assist
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 spec` 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 the created tag, 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_assist.
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require_relative './lib/devops_assist'
9
+
10
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "devops_assist"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
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,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/devops_assist/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "devops_assist"
7
+ spec.version = DevopsAssist::VERSION
8
+ spec.authors = ["Chris Liaw"]
9
+ spec.email = ["chrisliaw@antrapol.com"]
10
+
11
+ spec.summary = ""
12
+ spec.description = ""
13
+ spec.homepage = ""
14
+ spec.required_ruby_version = ">= 2.4.0"
15
+
16
+ #spec.metadata["allowed_push_host"] = "TODO: Set to your gem server 'https://example.com'"
17
+
18
+ #spec.metadata["homepage_uri"] = spec.homepage
19
+ #spec.metadata["source_code_uri"] = "TODO: Put your gem's public repo URL here."
20
+ #spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
21
+
22
+ # Specify which files should be added to the gem when it is released.
23
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
24
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
25
+ `git ls-files -z`.split("\x0").reject do |f|
26
+ (f == __FILE__) || f.match(%r{\A(?:(?:test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
27
+ end
28
+ end
29
+ spec.bindir = "exe"
30
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ["lib"]
32
+
33
+ spec.add_dependency 'toolrack'
34
+ spec.add_dependency 'tlogger'
35
+ spec.add_dependency 'tty-prompt'
36
+
37
+ spec.add_dependency 'gvcs'
38
+ spec.add_dependency 'git_cli'
39
+ spec.add_dependency 'git_cli_prompt'
40
+
41
+ # Uncomment to register a new dependency of your gem
42
+ # spec.add_dependency "example-gem", "~> 1.0"
43
+
44
+ # For more information and examples about making a new gem, checkout our
45
+ # guide at: https://bundler.io/guides/creating_gem.html
46
+ end
data/lib/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+
2
+
3
+ #require_relative 'devops_assist'
4
+
5
+ path = File.expand_path(File.dirname(__FILE__))
6
+ Dir.glob("#{path}/../tasks/**/*.rake").each { |f|
7
+ #p f
8
+ import f
9
+ }
@@ -0,0 +1,151 @@
1
+
2
+ require 'yaml'
3
+
4
+ require_relative 'gemspec'
5
+
6
+ module DevopsAssist
7
+ module Gem
8
+ include TR::CondUtils
9
+ include Gemspec
10
+
11
+ class GemError < StandardError; end
12
+
13
+ def update_gem_version(root, newVersion, &block)
14
+
15
+ version_file = find_gem_version_file(root)
16
+
17
+ if version_file.length > 1
18
+ if block
19
+ selVerFile = block.call(:select_version_file, version_file)
20
+ raise GemError, "Multiple version files found and user not selected any"
21
+ else
22
+ raise GemError, "Multiple version files found. Please provide a block to select version file or make sure there is no other file named version.rb"
23
+ end
24
+ else
25
+ selVerFile = version_file.first
26
+ end
27
+
28
+ tmpFile = File.join(File.dirname(selVerFile),"version.rb.tmp")
29
+ FileUtils.mv(selVerFile,tmpFile)
30
+
31
+ File.open(selVerFile,"w") do |f|
32
+ File.open(tmpFile,"r").each_line do |l|
33
+ if l =~ /VERSION/
34
+ indx = (l =~ /=/)
35
+ ll = "#{l[0..indx]} \"#{newVersion}\""
36
+ f.puts ll
37
+ else
38
+ f.write l
39
+ end
40
+ end
41
+ end
42
+
43
+ FileUtils.rm tmpFile
44
+
45
+ selVerFile
46
+
47
+ end
48
+
49
+ def find_gem_version_file(root)
50
+ if is_empty?(root)
51
+ raise GemError, "Root path '#{root}' to find_gem_version_file is empty"
52
+ else
53
+ Dir.glob(File.join(root,"**/version.rb"))
54
+ end
55
+ end
56
+
57
+
58
+ def publish_gem(version, opts = { }, &block)
59
+
60
+ cred = find_rubygems_api_key
61
+
62
+ selAcct = cred.keys.first
63
+ if cred.keys.length > 1
64
+ logger.tdebug :pubgem, "Multiple rubygems account detected."
65
+ # multiple account configured...
66
+ selAcct = block.call(:multiple_rubygems_account, cred)
67
+ return :skipped if selAcct == :skip
68
+ raise GemError, "No rubygems account is selected." if is_empty?(selAcct)
69
+ end
70
+
71
+ # find the package
72
+ root = opts[:root] || Dir.getwd
73
+ foundGem = Dir.glob("**/*-#{version}.gem")
74
+ if foundGem.length == 0
75
+ raise GemError, "No built gem found."
76
+ elsif foundGem.length > 1
77
+ if block
78
+ targetGem = block.call(:multiple_built_gems, foundGem)
79
+ else
80
+ raise GemError, "Multiple versions of gem found : #{foundGem}. Please provide a block for selection"
81
+ end
82
+ else
83
+ targetGem = foundGem.first
84
+ end
85
+
86
+ cmd = "cd #{root} && gem push #{targetGem} -k #{selAcct}"
87
+ logger.tdebug :pubgem, "Command to publish gem : #{cmd}"
88
+ res = `#{cmd}`
89
+ [$?, targetGem, res]
90
+
91
+ end
92
+
93
+ def publish_gem_file(gemfile, opts = { }, &block)
94
+
95
+ cred = find_rubygems_api_key
96
+
97
+ selAcct = cred.keys.first
98
+ if cred.keys.length > 1
99
+ logger.tdebug :pubgemfile, "Multiple rubygems account detected."
100
+ # multiple account configured...
101
+ selAcct = block.call(:multiple_rubygems_account, cred)
102
+ raise GemError, "No rubygems account is selected." if is_empty?(selAcct)
103
+ end
104
+
105
+ if File.exist?(gemfile)
106
+ root = File.dirname(gemfile)
107
+ targetGem = File.basename(gemfile)
108
+
109
+ cmd = "cd #{root} && gem push #{targetGem} -k #{selAcct}"
110
+ logger.tdebug :pubgemfile, "Command to publish gem : #{cmd}"
111
+ res = `#{cmd}`
112
+ [$?, res, targetGem]
113
+ else
114
+ raise GemError, "Given Gemfile '#{gemfile}' not found"
115
+ end
116
+
117
+ end
118
+
119
+
120
+ private
121
+ def logger
122
+ if @logger.nil?
123
+ @logger = Tlogger.new
124
+ end
125
+ @logger
126
+ end
127
+
128
+ def find_rubygems_api_key
129
+ if TR::RTUtils.on_windows?
130
+ credFile = File.join(ENV['USERPROFILE'],".gem","credentials")
131
+ else
132
+ credFile = File.join(Dir.home,".local","share","gem","credentials")
133
+ end
134
+
135
+ raise GemError, "Credential file not found at '#{credFile}'" if not File.exist?(credFile)
136
+
137
+ cred = nil
138
+ File.open(credFile,"r") do |f|
139
+ cred = YAML.load(f.read)
140
+ end
141
+
142
+ raise GemError, "Credential file is empty" if is_empty?(cred)
143
+ raise GemError, "No credential created yet for rubygems." if is_empty?(cred.keys)
144
+
145
+ cred
146
+ end
147
+
148
+
149
+
150
+ end
151
+ end
@@ -0,0 +1,28 @@
1
+
2
+
3
+ module DevopsAssist
4
+ module Gem
5
+ module Gemspec
6
+ include TR::CondUtils
7
+
8
+ class GemspecError < StandardError; end
9
+
10
+ def find_gem_name(root)
11
+ spec = find_gemspec(root)
12
+ s = ::Gem::Specification.load(spec)
13
+ s.name
14
+ end
15
+
16
+ private
17
+ def find_gemspec(root)
18
+ if is_empty?(root)
19
+ raise GemspecError, "Root path '#{root}' to find_gemspec is empty"
20
+ else
21
+ Dir.glob(File.join(root,"*.gemspec")).first
22
+ end
23
+ end
24
+
25
+ end
26
+ end
27
+ end
28
+
@@ -0,0 +1,164 @@
1
+
2
+ require 'toolrack'
3
+ require 'yaml'
4
+
5
+ module DevopsAssist
6
+
7
+ class ReleaseLogError < StandardError; end
8
+
9
+ class ReleaseLogger
10
+ include TR::CondUtils
11
+
12
+ LOG_NAME = ".release_history.yml"
13
+
14
+ attr_accessor :relRec
15
+ def initialize(rec = nil)
16
+ if not_empty?(rec)
17
+ @relRec = YAML.load(rec)
18
+ end
19
+ end
20
+
21
+ def log_release(relName, version, &block)
22
+
23
+ raise ReleaseLogError, "Release name cannot be empty" if is_empty?(relName)
24
+ raise ReleaseLogError, "Version cannot be empty" if is_empty?(version)
25
+
26
+ raise ReleaseLogError, "Version '#{version}' already in the log file for release '#{relName}'" if is_version_exist?(version, relName)
27
+
28
+ rec = { version: version, timestamp: Time.now.to_f }
29
+ if block
30
+ relBy = block.call(:released_by)
31
+ rec[:released_by] = relBy if not_empty?(relBy)
32
+
33
+ relFrom = block.call(:released_location)
34
+ rec[:released_location] = relFrom if not_empty?(relFrom)
35
+ end
36
+
37
+ relRec[relName] = [] if is_empty?(relRec[relName])
38
+ relRec[relName] << rec
39
+
40
+ save
41
+
42
+ relRec
43
+ end
44
+
45
+ def last_version_number(relName = nil)
46
+ if is_empty?(relName)
47
+ list = relRec[relRec.keys.first]
48
+ else
49
+ list = relRec[relName]
50
+ end
51
+
52
+ list.last[:version] if not_empty?(list)
53
+ end
54
+
55
+ def is_version_exist?(ver, relName = nil)
56
+ if is_empty?(relName)
57
+ list = relRec[relRec.keys.first]
58
+ else
59
+ list = relRec[relName]
60
+ end
61
+ res = false
62
+ if not_empty?(list)
63
+ ref = ::Gem::Version.new(ver)
64
+ list.each do |l|
65
+ subj = ::Gem::Version.new(l[:version])
66
+ res = (subj == ref)
67
+ break if res
68
+ end
69
+ end
70
+
71
+ res
72
+ end
73
+
74
+ def releases(&block)
75
+ ret = Marshal.load(Marshal.dump(relRec))
76
+ ret.values.each do |v|
77
+ #ret.map { |k,v|
78
+ v.map { |r|
79
+
80
+ t = r[:timestamp]
81
+ tt = Time.at(t)
82
+
83
+ res = nil
84
+
85
+ if block
86
+ res = block.call(:convert_timestamp, tt)
87
+ end
88
+
89
+ if is_empty?(res)
90
+ res = tt.strftime("%a, %d %b %Y, %H:%M:%S")
91
+ end
92
+
93
+ r[:timestamp] = res
94
+
95
+ relBy = r[:released_by]
96
+ if not_empty?(relBy)
97
+
98
+ if block
99
+ res = block.call(:convert_released_by, relBy)
100
+ r[:released_by] = res if not_empty?(res)
101
+ end
102
+
103
+ end
104
+
105
+ relFrom = r[:released_location]
106
+ if not_empty?(relFrom)
107
+
108
+ if block
109
+ res = block.call(:convert_released_location, relFrom)
110
+ r[:released_location] = res if not_empty?(res)
111
+ end
112
+
113
+ end
114
+
115
+ r
116
+
117
+ }
118
+
119
+ v
120
+
121
+ end
122
+
123
+ ret
124
+ end
125
+
126
+ def self.load(root = Dir.getwd)
127
+ f = File.join(root, LOG_NAME)
128
+ if not File.exist?(f)
129
+ ReleaseLogger.new
130
+ else
131
+ relLog = nil
132
+ File.open(f,"r") do |ff|
133
+ relLog = ReleaseLogger.new(ff.read)
134
+ end
135
+ relLog
136
+ end
137
+ end
138
+
139
+ def save(root = Dir.getwd)
140
+ f = File.join(root, LOG_NAME)
141
+ File.open(f,"w") do |ff|
142
+ ff.write YAML.dump(relRec)
143
+ end
144
+ end
145
+
146
+ def reset_log(root = Dir.getwd)
147
+ log = File.join(root, LOG_NAME)
148
+ FileUtils.rm(log) if File.exist?(log)
149
+ end
150
+
151
+ private
152
+ def relRec
153
+ if @relRec.nil?
154
+ @relRec = { }
155
+ end
156
+ @relRec
157
+ end
158
+
159
+
160
+
161
+ end
162
+ end
163
+
164
+
@@ -0,0 +1,14 @@
1
+
2
+ require 'git_cli_prompt'
3
+
4
+ module DevopsAssist
5
+ module Vcs
6
+ module Git
7
+ class CliPrompt
8
+ include GitCliPrompt::Commit
9
+ include GitCliPrompt::Tag
10
+ include GitCliPrompt::Push
11
+ end
12
+ end
13
+ end
14
+ end
File without changes
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DevopsAssist
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,47 @@
1
+
2
+ require 'tty/prompt'
3
+
4
+ module DevopsAssist
5
+ module VersionManager
6
+ extend DevopsAssist::Gem
7
+ extend TR::VUtils
8
+
9
+ def self.prompt_version(gemName, last_version = "0.0.0")
10
+
11
+ begin
12
+
13
+ last_version = "0.0.0" if is_empty?(last_version)
14
+
15
+ pmt = TTY::Prompt.new
16
+ vers = possible_versions(last_version)
17
+
18
+ vers << "Custom"
19
+ vers << "Quit"
20
+ #vers << [ \
21
+ # "Maybe not now..." \
22
+ # ,"Nah, forget it..." \
23
+ #].sample
24
+
25
+ vsel = pmt.select(" Please select one of the versions below:") do |menu|
26
+ vers.each do |v|
27
+ menu.choice v
28
+ end
29
+ end
30
+
31
+ case vsel
32
+ when "Custom"
33
+ vsel = pmt.ask(" Please provide custom version no:", required: true)
34
+ when vers[-1]
35
+ raise DevopsAssist::Error, " Aborted. Have a nice day! "
36
+ end
37
+
38
+ vsel
39
+
40
+ rescue TTY::Reader::InputInterrupt
41
+ raise DevopsAssist::Error
42
+ end
43
+
44
+ end
45
+
46
+ end
47
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "devops_assist/version"
4
+ require_relative 'devops_assist/release_log/release_log'
5
+
6
+ require_relative 'devops_assist/vcs/git/cli_prompt'
7
+
8
+ require_relative 'devops_assist/gem/gem'
9
+
10
+ require_relative 'devops_assist/version_manager'
11
+
12
+ require 'toolrack'
13
+ require 'tlogger'
14
+
15
+ module DevopsAssist
16
+ class Error < StandardError; end
17
+ # Your code goes here...
18
+ end
19
+
20
+ # load the rake tasks
21
+ rf = File.join(File.dirname(__FILE__),"Rakefile")
22
+ load rf
23
+
@@ -0,0 +1,68 @@
1
+
2
+
3
+ require_relative '../lib/devops_assist'
4
+ require 'tty/prompt'
5
+
6
+ namespace :devops do
7
+
8
+ desc "Release gem file project"
9
+ task :release do
10
+
11
+ begin
12
+
13
+ pmt = TTY::Prompt.new
14
+
15
+ root = Dir.getwd
16
+
17
+ gemName = find_gem_name(root)
18
+
19
+ pmt.say " Starting gem release for gem #{gemName}", color: :yellow
20
+
21
+ # check in source code
22
+ res = Rake::Task["devops:vcs:checkin_changes"].execute
23
+ pmt.say " Workspace check in done\n", color: :yellow
24
+
25
+ rl = DevopsAssist::ReleaseLogger.load
26
+
27
+ # select version
28
+ ver = DevopsAssist::VersionManager.prompt_version(gemName, rl.last_version_number(gemName))
29
+ pmt.say " Version no. '#{ver}' chosen", color: :yellow
30
+
31
+ selVerFile = update_gem_version(root, ver) do |*args|
32
+ ops = args.first
33
+ case ops
34
+ when :select_version_file
35
+ files = args[1]
36
+ vfile = pmt.select("Please select one of the gem version file to update the version number:", files)
37
+ vfile
38
+ end
39
+ end
40
+ pmt.say " Version file updated", color: :yellow
41
+
42
+ # build the gem
43
+ Rake::Task["build"].execute
44
+
45
+ rl.log_release(gemName, ver)
46
+ pmt.say " Release version number is logged", color: :yellow
47
+
48
+ # publish gem
49
+ Rake::Task["devops:gem:publish_gem"].execute({ version: ver, pmt: pmt })
50
+
51
+ Rake::Task["devops:vcs:checkin_misc_files"].execute({ root: root, files: [selVerFile, DevopsAssist::ReleaseLogger::LOG_NAME], version: ver })
52
+ pmt.say " Updated files during release prep have committed into version control", color: :yellow
53
+
54
+ Rake::Task["devops:vcs:tag_source_code"].execute({ root: root, version: ver })
55
+ pmt.say " Source code is tagged as version #{ver}", color: :yellow
56
+
57
+ Rake::Task["devops:vcs:push_source_code"].execute({ root: root, pmt: pmt })
58
+
59
+ rescue GitCliPrompt::UserAborted, GitCliPrompt::UserChangedMind
60
+ rescue Exception => ex
61
+ STDERR.puts ex.message
62
+ #STDERR.puts ex.backtrace.join('\n')
63
+ end
64
+
65
+ end
66
+
67
+ end
68
+
data/tasks/gem.rake ADDED
@@ -0,0 +1,81 @@
1
+
2
+ require_relative '../lib/devops_assist'
3
+
4
+ require 'tty/prompt'
5
+
6
+ include DevopsAssist::Gem
7
+ include TR::VUtils
8
+
9
+ namespace :devops do
10
+ namespace :gem do
11
+
12
+ desc "Build the gem"
13
+ task :build_gem, :version do |t, args|
14
+
15
+ root = Dir.getwd
16
+
17
+ selVerFile = update_gem_version(root, args) do |*args|
18
+ ops = args.first
19
+ case ops
20
+ when :select_version_file
21
+ files = args[1]
22
+ vfile = pmt.select(" Please select one of the gem version file to update the version number:", files)
23
+ vfile
24
+ end
25
+ end
26
+
27
+ Rake::Task["build"].execute
28
+
29
+ end
30
+
31
+ desc "Publish specific gem version to Rubygems"
32
+ task :publish_gem, :version do |t, args|
33
+
34
+ pmt = args[:pmt]
35
+ version = args[:version]
36
+
37
+ ans = pmt.yes?(" Proceed to publish the gem to Rubygems?")
38
+ if ans
39
+ res, tg, out = publish_gem(version) do |*args|
40
+ ops = args.first
41
+ case ops
42
+ when :multiple_rubygems_account
43
+ acct = args[1]
44
+ selAct = pmt.select(" Please select one of the Rubygems credential to release:") do |menu|
45
+
46
+ acct.each do |k,v|
47
+ menu.choice k, k
48
+ end
49
+
50
+ menu.choice "Skip", :skip
51
+ menu.choice "Quit", :quit
52
+
53
+ end
54
+
55
+ raise DevopsAssist::Error, " Aborted. Have a nice day " if selAct == :quit
56
+
57
+ selAct
58
+ end
59
+ end
60
+
61
+ pmt.say(" Gem publishing is skipped", color: :yellow) if res == :skipped
62
+
63
+ if res.respond_to?(:success?)
64
+ if res.success?
65
+ pmt.say " Gem published!\n", color: :yellow
66
+ else
67
+ pmt.say " Gem publishing failed. Return message :\n#{out}", color: :red
68
+ end
69
+ end
70
+
71
+ end
72
+
73
+ end
74
+
75
+ desc "Publish specific gem file to Rubygems"
76
+ task :publish_gem_file, :file do |t, args|
77
+
78
+ end
79
+
80
+ end
81
+ end
data/tasks/vcs.rake ADDED
@@ -0,0 +1,64 @@
1
+
2
+ require_relative '../lib/devops_assist'
3
+
4
+ namespace :devops do
5
+ namespace :vcs do
6
+
7
+ desc "Checking in changes of source code"
8
+ task :checkin_changes do
9
+ cli = DevopsAssist::Vcs::Git::CliPrompt.new
10
+ cli.commit(Dir.getwd)
11
+ end
12
+
13
+ desc "Checking in files generated by devops assist"
14
+ task :checkin_misc_files do |t, args|
15
+
16
+ root = args[:root]
17
+ files = args[:files]
18
+ ver = args[:version]
19
+
20
+ ws = Gvcs::Workspace.new(root)
21
+ if ws.is_workspace?
22
+ ws.add_to_staging(files)
23
+ ws.commit(" Committing file changed during release version '#{ver}'")
24
+ else
25
+ raise DevopsAssist::Error, " Given path '#{root}' is not a repository"
26
+ end
27
+
28
+ end
29
+
30
+ desc "Tag source code"
31
+ task :tag_source_code do |t, args|
32
+
33
+ root = args[:root]
34
+ ver = args[:version]
35
+
36
+ pmt = TTY::Prompt.new
37
+ msg = pmt.ask(" Tagging message : ", default: "Automated tagging of source code release version #{ver} by DevOps Assist")
38
+ ws = Gvcs::Workspace.new(root)
39
+ if ws.is_workspace?
40
+ ws.create_tag(ver, msg)
41
+ else
42
+ raise DevopsAssist::Error, "Given path '#{root}' is not a repository"
43
+ end
44
+
45
+ end
46
+
47
+ desc "Push source code to repository"
48
+ task :push_source_code do |t, args|
49
+
50
+ root = args[:root]
51
+ pmt = args[:pmt]
52
+
53
+ cli = DevopsAssist::Vcs::Git::CliPrompt.new
54
+ cli.push(root) do |ops, val|
55
+ case ops
56
+ when :push_info
57
+ pmt.say " Source code push to remote repository '#{val[:name]}'", color: :yellow
58
+ end
59
+ end
60
+
61
+ end
62
+
63
+ end
64
+ end
metadata ADDED
@@ -0,0 +1,146 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: devops_assist
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Chris Liaw
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-10-22 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'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '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'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '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'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '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'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: git_cli_prompt
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: ''
98
+ email:
99
+ - chrisliaw@antrapol.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".rspec"
105
+ - Gemfile
106
+ - Gemfile.lock
107
+ - README.md
108
+ - Rakefile
109
+ - bin/console
110
+ - bin/setup
111
+ - devops_assist.gemspec
112
+ - lib/Rakefile
113
+ - lib/devops_assist.rb
114
+ - lib/devops_assist/gem/gem.rb
115
+ - lib/devops_assist/gem/gemspec.rb
116
+ - lib/devops_assist/release_log/release_log.rb
117
+ - lib/devops_assist/vcs/git/cli_prompt.rb
118
+ - lib/devops_assist/vcs/vcs.rb
119
+ - lib/devops_assist/version.rb
120
+ - lib/devops_assist/version_manager.rb
121
+ - tasks/devops_assist.rake
122
+ - tasks/gem.rake
123
+ - tasks/vcs.rake
124
+ homepage: ''
125
+ licenses: []
126
+ metadata: {}
127
+ post_install_message:
128
+ rdoc_options: []
129
+ require_paths:
130
+ - lib
131
+ required_ruby_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ version: 2.4.0
136
+ required_rubygems_version: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - ">="
139
+ - !ruby/object:Gem::Version
140
+ version: '0'
141
+ requirements: []
142
+ rubygems_version: 3.2.22
143
+ signing_key:
144
+ specification_version: 4
145
+ summary: ''
146
+ test_files: []