ebm 0.0.25 → 0.0.26

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA512:
3
- metadata.gz: 786ec8b4b779ca4b493caf7b33be605b8f7153d5aa8c1734f3ff014b586a64757d4695fd1d1bd033f9c539b44a7994ad6cabc535f8156872cc5ff3978db921c2
4
- data.tar.gz: 5fc4701500b320c735e5fe127dc227281ebb938dafd5588a8e31ffa13daeec0ea41fbf0e52fc75f5f629534609b17296ad2c6da5fd51e36da8d83806551c3050
5
2
  SHA1:
6
- metadata.gz: 733ad60292f1607af13abf36606ba345915af87f
7
- data.tar.gz: f27005a74f5dd048a82f6328f7ee54ae2b99e24c
3
+ data.tar.gz: 9d440012f03a9075aa9f82058fee617d8635e90b
4
+ metadata.gz: 76bf9f7a8da9a5feaf71b31315aa3fc288252bd4
5
+ SHA512:
6
+ data.tar.gz: 3c0f5409c5bc890ead4d55696427ba88bea60683beb10590803cccf84cf9b522e00c17800ab1c65140718ed6a2df327635ba94beaa3a3e901547811580bec0dd
7
+ metadata.gz: 0951e0740b50371084f6d00f028a9dbb04acad054394ecc77de3955bad64e22ec8d5e25ef8ac87b80acc0b069a1d1e3e37b77991a103d06d9a8459ecf80a3d43
@@ -34,9 +34,13 @@ module Commands
34
34
  options[:comment] = v
35
35
  end
36
36
 
37
- opts.on("--add", "Also add all new files.") do |v|
37
+ opts.on('-a', "--add", "Also add all new files.") do |v|
38
38
  options[:add] = v
39
39
  end
40
+
41
+ opts.on('-n', "--dry-run", "Perform a dry run.") do |v|
42
+ options[:dry_run] = v
43
+ end
40
44
  end
41
45
 
42
46
  def run(global_options)
@@ -45,13 +49,14 @@ module Commands
45
49
  # the file is expected to be in JSON format
46
50
  comment = options[:comment]
47
51
  add = !!options[:add]
52
+ dry_run = !!options[:dry_run] ? "--dry-run" : ""
48
53
 
49
54
  if ARGV.length > 0
50
55
  raise "You must specify all arguments with their options."
51
56
  end
52
57
 
53
58
  # get config based on name of current dir
54
- info = EbmSharedLib.get_config_from_top_dir(false)
59
+ info = EbmSharedLib.get_config_from_top_dir
55
60
 
56
61
  # Back up to version parent dir. This directory contains the top level repos.
57
62
  top_dir = Dir.pwd
@@ -66,13 +71,13 @@ module Commands
66
71
 
67
72
  if (add)
68
73
  # first add any new files
69
- cmd = "git add ."
74
+ cmd = "git add #{dry_run} ."
70
75
  if EbmSharedLib::CL.do_cmd_result(cmd, repo_path) != 0
71
76
  raise "Git add all failed for #{repo_name}."
72
77
  end
73
78
  end
74
79
 
75
- cmd = "git commit -am \"#{comment}\""
80
+ cmd = "git commit #{dry_run} -am \"#{comment}\""
76
81
  msg = EbmSharedLib::CL.do_cmd_output(cmd, repo_path)
77
82
  puts msg
78
83
  exit_code = $?.exitstatus
@@ -24,16 +24,21 @@ module Commands
24
24
  def register(opts, global_options)
25
25
  opts.banner = "Usage: configs"
26
26
  opts.description = "List all configurations."
27
+
28
+ opts.on('-r', "--config-repo name", "Remote git repository for initial configs file download [corp,stash,<git url>]") do |v|
29
+ options[:config_repo] = v
30
+ end
27
31
  end
28
32
 
29
33
 
30
34
  def run(global_options)
31
35
  # show contents of configs directory for files with .config extension
32
36
  # try to make sure the repo is available
33
- EbmSharedLib.prepare_config_repo
37
+ config_repo = options[:config_repo]
38
+ repo_url = EbmSharedLib.prepare_config_repo(config_repo)
34
39
 
35
- config_path = "#{EbmSharedLib::CONFIG_PATH}/configs"
36
- config_names = Pathname.glob("#{config_path}/*.config").map { |file_info|
40
+ config_path = EbmSharedLib.full_config_path(repo_url)
41
+ config_names = Pathname.glob("#{config_path}/configs/*.config").map { |file_info|
37
42
  if file_info.directory? == false
38
43
  name = file_info.basename.to_s
39
44
  name.slice!("#{EbmSharedLib::CONFIG_SUFFIX}")
@@ -42,7 +47,7 @@ module Commands
42
47
  nil
43
48
  end
44
49
  }
45
- puts "\nCurrent configurations:"
50
+ puts "\nCurrent configurations for #{repo_url}:"
46
51
  config_names.each do |name|
47
52
  puts name unless name.nil?
48
53
  end
@@ -26,6 +26,10 @@ module Commands
26
26
  opts.banner = "Usage: prepare [options]"
27
27
  opts.description = "Prepare your build environment"
28
28
 
29
+ opts.on('-r', "--config-repo name", "Remote git repository for initial configs file download [corp,stash,<git url>]") do |v|
30
+ options[:config_repo] = v
31
+ end
32
+
29
33
  opts.on('-c', "--config name", "Required - Name of the config we are preparing from.") do |v|
30
34
  options[:config] = v
31
35
  end
@@ -34,11 +38,11 @@ module Commands
34
38
  options[:initials] = v
35
39
  end
36
40
 
37
- opts.on("--nobranch", "Don't create developer branch.") do |v|
41
+ opts.on("--no-branch", "Don't create developer branch.") do |v|
38
42
  options[:nobranch] = v
39
43
  end
40
44
 
41
- opts.on("--with_local_version", "Also include a local version branch, only applies with the -i option.") do |v|
45
+ opts.on("--with-local-version", "Also include a local version branch, only applies with the -i option.") do |v|
42
46
  options[:with_local_version] = v
43
47
  end
44
48
 
@@ -154,8 +158,9 @@ module Commands
154
158
  end
155
159
 
156
160
  # try to make sure the repo is available
157
- EbmSharedLib.prepare_config_repo
158
- info = EbmSharedLib.read_repo_config(config_name)
161
+ config_repo = options[:config_repo]
162
+ config_repo_url = EbmSharedLib.prepare_config_repo(config_repo)
163
+ info = EbmSharedLib.read_repo_config(config_repo_url, config_name)
159
164
 
160
165
  # Now that we have the json, prepare the world by creating a directory with the config name and placing
161
166
  # the various repos beneath that. The directory is created relative to the current directory.
@@ -170,6 +175,13 @@ module Commands
170
175
  prepare_repo(repo, top_dir, initials, nobranch, with_local_version)
171
176
  end
172
177
 
178
+ # finish up by writing settings
179
+ settings = {
180
+ :config_repo_url => config_repo_url,
181
+ :config_name => config_name,
182
+ }
183
+ EbmSharedLib.write_settings(settings, top_dir, err_msg = nil)
184
+
173
185
  end
174
186
 
175
187
  end
data/lib/commands/pull.rb CHANGED
@@ -29,18 +29,23 @@ module Commands
29
29
  options[:tag] = v
30
30
  end
31
31
 
32
- opts.on("--remote_version", "Pull from remote version branch into your current branch.") do |v|
32
+ opts.on("--remote-version", "Pull from remote version branch into your current branch.") do |v|
33
33
  options[:remote_version] = v
34
34
  end
35
35
 
36
+ opts.on('-n', "--dry-run", "Perform a dry run.") do |v|
37
+ options[:dry_run] = v
38
+ end
36
39
  end
37
40
 
41
+ # @param [Object] global_options
38
42
  def run(global_options)
39
43
 
40
44
  # see if we can open the config file - we append the .config suffix
41
45
  # the file is expected to be in JSON format
42
46
  tag = options[:tag]
43
- remote_version = options[:remote_version]
47
+ remote_version = !!options[:remote_version]
48
+ dry_run = !!options[:dry_run] ? "--dry-run" : ""
44
49
 
45
50
  if ARGV.length > 0
46
51
  raise "You must specify all arguments with their options."
@@ -51,7 +56,7 @@ module Commands
51
56
  end
52
57
 
53
58
  # get config based on name of current dir
54
- info = EbmSharedLib.get_config_from_top_dir(false)
59
+ info = EbmSharedLib.get_config_from_top_dir
55
60
 
56
61
  # Back up to version parent dir. This directory contains the top level repos.
57
62
  top_dir = Dir.pwd
@@ -64,7 +69,7 @@ module Commands
64
69
  branch = repo[:branch]
65
70
  puts("\n#{repo_name} pull:\n");
66
71
 
67
- cmd = "git fetch --all"
72
+ cmd = "git fetch #{dry_run} --all"
68
73
  if EbmSharedLib::CL.do_cmd_result(cmd, repo_path) != 0
69
74
  raise "Git fetch failed for #{repo_name}."
70
75
  end
@@ -78,16 +83,20 @@ module Commands
78
83
  else
79
84
  if remote_version
80
85
  # pulling from remote version branch
81
- cmd = "git pull --no-edit --recurse-submodules=yes origin #{branch}"
86
+ cmd = "git pull #{dry_run} --no-edit --recurse-submodules=yes origin #{branch}"
82
87
  else
83
88
  # pull from the remote branch of the current branch
84
- cmd = "git pull --no-edit --recurse-submodules=yes"
89
+ cmd = "git pull #{dry_run} --no-edit --recurse-submodules=yes"
85
90
  end
86
91
  if EbmSharedLib::CL.do_cmd_result(cmd, repo_path) != 0
87
92
  raise "Git pull failed for #{repo_name}."
88
93
  end
89
94
  end
90
- cmd = "git submodule update"
95
+ if dry_run.empty?
96
+ cmd = "git submodule update"
97
+ else
98
+ cmd = "git submodule update --no-fetch"
99
+ end
91
100
  if EbmSharedLib::CL.do_cmd_result(cmd, repo_path) != 0
92
101
  raise "Updating submodules for #{repo_name} failed."
93
102
  end
data/lib/commands/push.rb CHANGED
@@ -25,24 +25,29 @@ module Commands
25
25
  opts.banner = "Usage: push [options]"
26
26
  opts.description = "Push code to the remote repo."
27
27
 
28
- opts.on("--remote_version", "Push from your local dev branch to the remote version branch - use with caution!") do |v|
28
+ opts.on("--remote-version", "Push from your local dev branch to the remote version branch - use with caution!") do |v|
29
29
  options[:remote_version] = v
30
30
  end
31
31
 
32
+ opts.on('-n', "--dry-run", "Perform a dry run.") do |v|
33
+ options[:dry_run] = v
34
+ end
35
+
32
36
  end
33
37
 
34
38
  def run(global_options)
35
39
 
36
40
  # see if we can open the config file - we append the .config suffix
37
41
  # the file is expected to be in JSON format
38
- remote_version = options[:remote_version]
42
+ remote_version = !!options[:remote_version]
43
+ dry_run = !!options[:dry_run] ? "--dry-run" : ""
39
44
 
40
45
  if ARGV.length > 0
41
46
  raise "You must specify all arguments with their options."
42
47
  end
43
48
 
44
49
  # get config based on name of current dir
45
- info = EbmSharedLib.get_config_from_top_dir(false)
50
+ info = EbmSharedLib.get_config_from_top_dir
46
51
 
47
52
  # Back up to version parent dir. This directory contains the top level repos.
48
53
  top_dir = Dir.pwd
@@ -59,12 +64,12 @@ module Commands
59
64
  if remote_version
60
65
  # pulling from remote version branch
61
66
  remote_branch = repo[:branch]
62
- cmd = "git push origin #{local_branch}:#{remote_branch}"
67
+ cmd = "git push #{dry_run} origin #{local_branch}:#{remote_branch}"
63
68
  else
64
69
  # pull from the remote branch of the current branch
65
70
  # they want to commit whatever has changed and push to current remote
66
71
  # first grab the current branch name
67
- cmd = "git push origin #{local_branch}"
72
+ cmd = "git push #{dry_run} origin #{local_branch}"
68
73
  end
69
74
  if EbmSharedLib::CL.do_cmd_result(cmd, repo_path) != 0
70
75
  raise "Git push failed for #{repo_name}."
@@ -33,7 +33,7 @@ module Commands
33
33
  # the file is expected to be in JSON format
34
34
 
35
35
  # determine config_name by extracting parent of our directory
36
- info = EbmSharedLib.get_config_from_top_dir(false)
36
+ info = EbmSharedLib.get_config_from_top_dir
37
37
 
38
38
  # Back up to version parent dir. This directory contains the top level repos.
39
39
  # top_dir = File.expand_path("#{Dir.pwd}/..")
data/lib/commands/tag.rb CHANGED
@@ -34,7 +34,7 @@ module Commands
34
34
  options[:delete] = v
35
35
  end
36
36
 
37
- opts.on("--commit_and_push", "Commit any local changes and then push the remote - should only be used by the build system.") do |v|
37
+ opts.on("--commit-and-push", "Commit any local changes and then push the remote - should only be used by the build system.") do |v|
38
38
  options[:commit_and_push] = v
39
39
  end
40
40
 
@@ -52,7 +52,7 @@ module Commands
52
52
  raise "You cannot use --commit_and_push with --delete."
53
53
  end
54
54
 
55
- info = EbmSharedLib.get_config_from_top_dir(false)
55
+ info = EbmSharedLib.get_config_from_top_dir
56
56
 
57
57
  # other than prepare, any commands that work across the repos expect you to start
58
58
  # in the containing directory (i.e. if your config is named iphone_3.1, you are expected
@@ -0,0 +1,34 @@
1
+ #
2
+ # Greg Seitz
3
+ #
4
+ # Copyright 2013, eBay Inc.
5
+ # All rights reserved.
6
+ # http://www.ebay.com
7
+ #
8
+ module Commands
9
+ class Version
10
+
11
+ # holds the options that were passed
12
+ # you can set any initial defaults here
13
+ def options
14
+ @options ||= {
15
+ }
16
+ end
17
+
18
+ # required options
19
+ def required_options
20
+ @required_options ||= Set.new [
21
+ ]
22
+ end
23
+
24
+ def register(opts, global_options)
25
+ opts.banner = "Usage: version"
26
+ opts.description = "Returns the version only."
27
+ end
28
+
29
+ def run(global_options)
30
+ puts "#{Info.version}"
31
+ end
32
+
33
+ end
34
+ end
data/lib/commands.rb CHANGED
@@ -8,6 +8,7 @@
8
8
  #require "FileUtils"
9
9
  require "set"
10
10
  require "fileutils"
11
+ require "hmac-sha1"
11
12
 
12
13
  require 'ebmsharedlib/monkey_patches'
13
14
  require "printer"
@@ -24,3 +25,4 @@ require 'commands/periodic'
24
25
  require 'commands/pull'
25
26
  require 'commands/push'
26
27
  require 'commands/commit'
28
+ require 'commands/version'
data/lib/ebm.rb CHANGED
@@ -52,6 +52,7 @@ class Ebm
52
52
  sub_commands[:pull] = Commands::Pull.new
53
53
  sub_commands[:push] = Commands::Push.new
54
54
  sub_commands[:commit] = Commands::Commit.new
55
+ sub_commands[:version] = Commands::Version.new
55
56
  end
56
57
 
57
58
  def setup
@@ -8,8 +8,16 @@
8
8
  module EbmSharedLib
9
9
  ROOT_PATH = File.expand_path("~/.ebm")
10
10
  CONFIG_DIR = "build_configs"
11
- CONFIG_PATH = "#{ROOT_PATH}/#{CONFIG_DIR}"
12
11
  CONFIG_SUFFIX = ".config"
12
+ SETTINGS_FILE = ".ebm-settings.json"
13
+
14
+ # the key is the shortcut used for the config repos
15
+ CONFIG_REPOS = {
16
+ "stash" => "https://mobiebay.com/git/scm/ebmconfigs/build_configs.git",
17
+ "corp" => "git@github.scm.corp.ebay.com:eBayMobile/build_configs.git",
18
+ "mobi" => "git@github.mobiebay.com:eBayMobile/build_configs.git",
19
+ }
20
+ CONFIG_REPOS["default"] = CONFIG_REPOS["corp"]
13
21
 
14
22
  class CL
15
23
  # run a command line and echo to console
@@ -60,29 +68,68 @@ module EbmSharedLib
60
68
 
61
69
  end
62
70
 
63
- def self.prepare_config_repo
64
- # make the root if missing
65
- FileUtils.mkpath(ROOT_PATH)
66
- #`mkdir -p #{ROOT_PATH}`
71
+ def self.get_config_repo_url(config_repo)
72
+ # convert to lowercase for comparison below if non nil
73
+ repo_alias = config_repo.nil? ? "default" : config_repo.downcase
67
74
 
68
- # try to pull, if it fails could be due to repo not cloned
69
- cmd = "git pull"
70
- if EbmSharedLib::CL.do_cmd_result(cmd, CONFIG_PATH) != 0
71
- # pull failed, try to clone
72
- cmd = "git clone git@github.scm.corp.ebay.com:eBayMobile/build_configs.git"
73
- if EbmSharedLib::CL.do_cmd_result(cmd, ROOT_PATH) != 0
74
- raise "Unable to clone build_configs repo into #{ROOT_PATH}"
75
- end
76
- end
75
+ # loop up matching repo
76
+ found_repo = CONFIG_REPOS[repo_alias]
77
+ # if no match use the passed in repo
78
+ config_repo = found_repo.nil? ? config_repo : found_repo
79
+ end
77
80
 
81
+ # compute a unique hash for this repo so
82
+ # we can store it in a subdir of configs
83
+ def self.repo_url_hash(repo_url)
84
+ Digest::SHA1.hexdigest(repo_url)
78
85
  end
79
86
 
80
- # read and return the config info for this repo
81
- def self.read_repo_config(config_name, err_msg = nil)
82
- config_path = "#{EbmSharedLib::CONFIG_PATH}/configs/#{config_name}#{EbmSharedLib::CONFIG_SUFFIX}"
87
+ # return the base config path minus the git dir
88
+ # for the given url
89
+ def self.base_config_path(repo_url)
90
+ config_hash = repo_url_hash(repo_url)
91
+
92
+ "#{ROOT_PATH}/repo_configs/#{config_hash}"
93
+ end
94
+
95
+ # the full config path
96
+ def self.full_config_path(repo_url)
97
+ "#{base_config_path(repo_url)}/#{CONFIG_DIR}"
98
+ end
83
99
 
100
+ # takes the repo name (shortcut or full url)
101
+ # and fetches config into appropriate location
102
+ # returns the full repo_url
103
+ def self.prepare_config_repo(config_repo_url)
104
+ # get the full url
105
+ repo_url = EbmSharedLib.get_config_repo_url(config_repo_url)
106
+
107
+ # get the local config dir
108
+ base_config_path = base_config_path(repo_url)
109
+
110
+ # make the root if missing
111
+ FileUtils.mkpath(base_config_path)
112
+
113
+ # and the full config path
114
+ config_path = full_config_path(repo_url)
115
+
116
+ # try to pull, if it fails could be due to repo not cloned
117
+ cmd = "git pull"
118
+ if EbmSharedLib::CL.do_cmd_result(cmd, config_path) != 0
119
+ # pull failed, try to clone
120
+ cmd = "git clone #{repo_url} #{CONFIG_DIR}"
121
+ if EbmSharedLib::CL.do_cmd_result(cmd, base_config_path) != 0
122
+ raise "Unable to clone #{CONFIG_DIR} repo into #{base_config_path}"
123
+ end
124
+ end
125
+
126
+ repo_url
127
+ end
128
+
129
+ # read and parse a json file
130
+ def self.read_json_file(file_path, err_msg = nil)
84
131
  begin
85
- json = File.open(config_path, 'r') {|f| f.read }
132
+ json = File.open(file_path, 'r') {|f| f.read }
86
133
  info = JSON.parse(json)
87
134
  info.recursively_symbolize_keys!
88
135
  rescue
@@ -91,10 +138,44 @@ module EbmSharedLib
91
138
  end
92
139
  end
93
140
 
141
+ # write the map as json into the specified file
142
+ def self.write_json_file(map, file_path, err_msg = nil)
143
+ begin
144
+
145
+ json = JSON.pretty_generate(map)
146
+
147
+ File.open(file_path, 'w') { |file| file.write(json) }
148
+ rescue
149
+ msg = err_msg.nil? ? "Error creating JSON file: #{file_path}" : err_msg
150
+ raise msg
151
+ end
152
+ end
153
+
154
+ # write the prepared settings, expects us to pass
155
+ # dir to write into
156
+ def self.write_settings(map, dir, err_msg = nil)
157
+ settings_path = "#{dir}/#{SETTINGS_FILE}"
158
+ write_json_file(map, settings_path, err_msg)
159
+ end
160
+
161
+ # read and return the config info for this repo
162
+ def self.read_repo_config(repo_url, config_name, err_msg = nil)
163
+ config_file_path = "#{full_config_path(repo_url)}/configs/#{config_name}#{EbmSharedLib::CONFIG_SUFFIX}"
164
+
165
+ read_json_file(config_file_path, err_msg)
166
+ end
167
+
168
+ # read top level settings within a prepared dir
169
+ # lets us get to the appropriate config file
170
+ def self.read_settings(err_msg = nil)
171
+ settings_path = "#{Dir.pwd}/#{SETTINGS_FILE}"
172
+ settings = read_json_file(settings_path, err_msg)
173
+ end
174
+
94
175
  # expects us to be in the top level dir that has the same name
95
176
  # as the config. Such as /Users/gseitz/Develop/ebay/iphone_3.1
96
177
  # will extract the config_name of iphone_3.1
97
- def self.config_name_from_dir(dir)
178
+ def self.config_name_from_dir
98
179
  config_name = "#{Dir.pwd}".split("/").last
99
180
  end
100
181
 
@@ -118,13 +199,20 @@ module EbmSharedLib
118
199
  branch = result.rstrip.split("/").last
119
200
  end
120
201
 
121
- def self.get_config_from_top_dir(prepare)
122
- # determine config_name by extracting parent of our directory
123
- config_name = EbmSharedLib.config_name_from_dir(Dir.pwd)
124
-
125
- # try to make sure the repo is available
126
- EbmSharedLib.prepare_config_repo if (prepare)
127
-
128
- info = EbmSharedLib.read_repo_config(config_name, "Config not found, make sure you are in the top level version directory.")
202
+ # read the repo_config file for the prepared directory by
203
+ # first fetching the settings from this dir
204
+ def self.get_config_from_top_dir(err_msg = nil)
205
+ begin
206
+ # for now we still operate without settings by using defaults
207
+ # this should be removed once everyone is on the new tool
208
+ settings = read_settings(".ebm-settings not found, make sure you are in the top level directory.")
209
+ repo_url = settings[:config_repo_url]
210
+ config_name = settings[:config_name]
211
+ rescue
212
+ # use defaults since failed to load settings
213
+ config_name = config_name_from_dir()
214
+ repo_url = get_config_repo_url(nil)
215
+ end
216
+ read_repo_config(repo_url, config_name, "Config not found, make sure you are in the top level directory.")
129
217
  end
130
218
  end
data/lib/info.rb CHANGED
@@ -7,6 +7,6 @@
7
7
  #
8
8
  class Info
9
9
  def self.version
10
- "0.0.25"
10
+ "0.0.26"
11
11
  end
12
12
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ebm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.25
4
+ version: 0.0.26
5
5
  platform: ruby
6
6
  authors:
7
7
  - Greg Seitz
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2013-07-17 00:00:00 Z
12
+ date: 2013-08-01 00:00:00 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: subcommand
@@ -59,6 +59,7 @@ files:
59
59
  - lib/commands/push.rb
60
60
  - lib/commands/status.rb
61
61
  - lib/commands/tag.rb
62
+ - lib/commands/version.rb
62
63
  - lib/commands.rb
63
64
  - lib/ebm.rb
64
65
  - lib/ebmsharedlib/monkey_patches.rb