ecb 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,54 +0,0 @@
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 Periodic
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
- :command,
22
- :interval
23
- ]
24
- end
25
-
26
- def register(opts, global_options)
27
- opts.banner = "Usage: periodic [options]"
28
- opts.description = "Run a periodic command"
29
-
30
- opts.on('-c', "--command name", "Required - Command to run.") do |v|
31
- options[:command] = v
32
- end
33
-
34
- opts.on('-i', "--interval value", Integer, "Required - Interval in seconds.") do |v|
35
- options[:interval] = v
36
- end
37
-
38
- end
39
-
40
- def run(global_options)
41
-
42
- # see if we can open the config file - we append the .config suffix
43
- # the file is expected to be in JSON format
44
- command = options[:command]
45
- interval = options[:interval]
46
-
47
- while true
48
- EbmSharedLib::CL.do_cmd_result(command)
49
- sleep(interval)
50
- end
51
- end
52
-
53
- end
54
- end
@@ -1,191 +0,0 @@
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 Prepare
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
- :config,
22
- ]
23
- end
24
-
25
- def register(opts, global_options)
26
- opts.banner = "Usage: prepare [options]"
27
- opts.description = "Prepare your build environment"
28
-
29
- opts.on('-r', "--config-repo name", EbmSharedLib::REPO_COMMAND_DETAILS) do |v|
30
- options[:config_repo] = v
31
- end
32
-
33
- opts.on('-c', "--config name", "Required - Name of the config we are preparing from.") do |v|
34
- options[:config] = v
35
- end
36
-
37
- opts.on('-i', "--initials name", "Initials prepended to your branch For example --initials gws will result in something like gws_iphone_3.0.") do |v|
38
- options[:initials] = v
39
- end
40
-
41
- opts.on("--no-branch", "Don't create developer branch.") do |v|
42
- options[:nobranch] = true # just indicate that the option was set (parms used --no to mean false but we don't want that)
43
- end
44
-
45
- opts.on("--with-local-version", "Also include a local version branch, only applies with the -i option.") do |v|
46
- options[:with_local_version] = true
47
- end
48
- opts.on('-n', "--shallow", "Checkout only level one to only have first level of history") do |v|
49
- options[:shallow] = true
50
- end
51
- end
52
-
53
- # prepare a single repo and create a local and tracking branch if it should have one
54
- # if the repo specifies a branch then we will do the initial fetch from that branch
55
- # if the create_dev_branch flag is set, we will create a local and tracking branch with
56
- # the developer initials prepended
57
- def prepare_repo(repo, top_dir, initials, nobranch, with_local_version, shallow)
58
- git_path = repo[:git_path]
59
- branch = repo[:branch]
60
- create_dev_branch = (repo[:create_dev_branch] == true) && (!nobranch)
61
- tag = repo[:tag]
62
- parent_path = repo[:parent_path]
63
-
64
- if tag && branch
65
- raise "We only support branching relative to HEAD, you cannot specify a branch:#{branch} and a tag:#{tag}."
66
- end
67
-
68
- if tag && create_dev_branch
69
- raise "We do not support creating dev branches when using a tag"
70
- end
71
-
72
- # build the parent path if we have one and make it the new top dir
73
- if parent_path
74
- Dir.chdir(top_dir){
75
- FileUtils.mkpath(parent_path)
76
- }
77
- top_dir = "#{top_dir}/#{parent_path}"
78
- end
79
-
80
- # first clone the repo
81
- cmd = "git clone #{git_path} -b #{branch} #{shallow}"
82
- if EbmSharedLib::CL.do_cmd_result(cmd, top_dir) != 0
83
- raise "Cloning repo at #{git_path} failed."
84
- end
85
-
86
- # extract the directory name that this repo ended up in
87
- repo_name = EbmSharedLib.get_repo_name(git_path)
88
- repo_path = "#{top_dir}/#{repo_name}"
89
-
90
- # now set up the remote tracking base branch if we have one
91
- if branch
92
- cmd = "git checkout -B #{branch} --track origin/#{branch}"
93
- if EbmSharedLib::CL.do_cmd_result(cmd, repo_path) != 0
94
- raise "Checking out branch #{branch} for #{repo_name} failed."
95
- end
96
-
97
- # now create the developer branch off of the base branch
98
- if create_dev_branch
99
- dev_branch_name = "#{initials}_#{branch}"
100
- # first assume dev branch already exists and try to switch to it
101
- cmd = "git checkout --track origin/#{dev_branch_name}"
102
- if EbmSharedLib::CL.do_cmd_result(cmd, repo_path) != 0
103
- # no remote branch, so create local and push as remote
104
- cmd = "git checkout -B #{dev_branch_name}"
105
- if EbmSharedLib::CL.do_cmd_result(cmd, repo_path) != 0
106
- raise "Unable to create local and tracking developer branch #{dev_branch_name} for #{repo_name}."
107
- end
108
- cmd = "git push -u origin #{dev_branch_name}"
109
- if EbmSharedLib::CL.do_cmd_result(cmd, repo_path) != 0
110
- raise "Unable to create local and tracking developer branch #{dev_branch_name} for #{repo_name}."
111
- end
112
- end
113
- if with_local_version == false
114
- # they don't want the local version branch so drop it
115
- cmd = "git branch -D #{branch}"
116
- if EbmSharedLib::CL.do_cmd_result(cmd, repo_path) != 0
117
- raise "Unable to delete local version branch #{branch} for #{repo_name}."
118
- end
119
- end
120
- end
121
- elsif tag
122
- # they are using a tag so don't create dev branches
123
- cmd = "git checkout #{tag}"
124
- if EbmSharedLib::CL.do_cmd_result(cmd, repo_path) != 0
125
- raise "Unable to checkout tag:#{tag} for #{repo_name}."
126
- end
127
- end
128
-
129
- # pull any submodules
130
- cmd = "git submodule init"
131
- if EbmSharedLib::CL.do_cmd_result(cmd, repo_path) != 0
132
- raise "Cloning submodules in repo at #{git_path} failed."
133
- end
134
- cmd = "git submodule update"
135
- if EbmSharedLib::CL.do_cmd_result(cmd, repo_path) != 0
136
- raise "Cloning submodules in repo at #{git_path} failed."
137
- end
138
-
139
- end
140
-
141
- def run(global_options)
142
-
143
- # see if we can open the config file - we append the .config suffix
144
- # the file is expected to be in JSON format
145
- config_name = options[:config]
146
- initials = options[:initials]
147
- nobranch = !!options[:nobranch]
148
- with_local_version = !!options[:with_local_version]
149
- shallow = !!options[:shallow] ? "--depth=1" : ""
150
-
151
- if (nobranch && initials)
152
- raise "You must specify either the --initials or --no-branch, not both."
153
- end
154
-
155
- if (initials.nil? && nobranch == false)
156
- raise "You must specify either --initials or --no-branch"
157
- end
158
-
159
- if (with_local_version && initials.nil?)
160
- raise "Using --with-local-version is only applicable if you are also creating a developer branch -i."
161
- end
162
-
163
- # try to make sure the repo is available
164
- config_repo = options[:config_repo]
165
- config_repo_url = EbmSharedLib.prepare_config_repo(config_repo)
166
- info = EbmSharedLib.read_repo_config(config_repo_url, config_name)
167
-
168
- # Now that we have the json, prepare the world by creating a directory with the config name and placing
169
- # the various repos beneath that. The directory is created relative to the current directory.
170
-
171
- top_dir = "#{Dir.pwd}/#{config_name}"
172
- raise "Cannot prepare since top level directory already exists: #{top_dir}" if File.directory?(top_dir)
173
-
174
- Dir::mkdir(top_dir)
175
-
176
- repos = info[:repos]
177
- repos.each do |repo|
178
- prepare_repo(repo, top_dir, initials, nobranch, with_local_version, shallow)
179
- end
180
-
181
- # finish up by writing settings
182
- settings = {
183
- :config_repo_url => config_repo_url,
184
- :config_name => config_name,
185
- }
186
- EbmSharedLib.write_settings(settings, top_dir, err_msg = nil)
187
-
188
- end
189
-
190
- end
191
- end
@@ -1,53 +0,0 @@
1
- #
2
- # Rick Hoiberg
3
- #
4
- # Copyright 2013, eBay Inc.
5
- # All rights reserved.
6
- # http://www.ebay.com
7
- #
8
- module Commands
9
- class Prune
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: prune"
26
- opts.description = "Removes branches in the local repository that no longer exist on origin."
27
- end
28
-
29
- def run(global_options)
30
-
31
- # see if we can open the config file - we append the .config suffix
32
- # the file is expected to be in JSON format
33
-
34
- # determine config_name by extracting parent of our directory
35
- info = EbmSharedLib.get_config_from_top_dir
36
-
37
- # Back up to version parent dir. This directory contains the top level repos.
38
- top_dir = Dir.pwd
39
-
40
- repos = info[:repos]
41
- repos.each do |repo|
42
- if repo[:create_dev_branch]
43
- repo_name = EbmSharedLib.get_repo_name(repo[:git_path])
44
- repo_path = "#{top_dir}/#{repo_name}"
45
- cmd = "git remote prune origin"
46
- if EbmSharedLib::CL.do_cmd_result(cmd, repo_path) != 0
47
- raise "Git push origin failed for #{repo_name}. Make sure you run the command from within a top level repo directory."
48
- end
49
- end
50
- end
51
- end
52
- end
53
- end
data/lib/commands/pull.rb DELETED
@@ -1,140 +0,0 @@
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 Pull
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: pull [options]"
26
- opts.description = "Pull code from remote repo."
27
-
28
- opts.on('-t', "--tag name", "Name of the remote tag that you want to checkout. Warning this will overwrite any local changes.") do |v|
29
- options[:tag] = v
30
- end
31
-
32
- opts.on("--remote-version", "Pull from remote version branch into your current branch.") do |v|
33
- options[:remote_version] = true
34
- end
35
-
36
- opts.on("--base-version", "Pull from base remote version branch into your current branch.") do |v|
37
- options[:base_version] = true
38
- end
39
-
40
- opts.on('-n', "--dry-run", "Perform a dry run.") do |v|
41
- options[:dry_run] = true
42
- end
43
- end
44
-
45
- # @param [Object] global_options
46
- def run(global_options)
47
-
48
- # see if we can open the config file - we append the .config suffix
49
- # the file is expected to be in JSON format
50
- tag = options[:tag]
51
- remote_version = !!options[:remote_version]
52
- base_version = !!options[:base_version]
53
- dry_run = !!options[:dry_run] ? "--dry-run" : ""
54
-
55
- if ARGV.length > 0
56
- raise "You must specify all arguments with their options."
57
- end
58
-
59
- if (!tag.nil? && (remote_version || base_version))
60
- raise "You can't specify both a pull from a tag and a pull from a remote version branch together."
61
- end
62
-
63
- if (remote_version && base_version)
64
- raise "You can only specify base-version or remote-version, not both."
65
- end
66
-
67
- # get config based on name of current dir
68
- info = EbmSharedLib.get_config_from_top_dir
69
-
70
- # Back up to version parent dir. This directory contains the top level repos.
71
- top_dir = Dir.pwd
72
-
73
- merge_failed = false
74
- repos = info[:repos]
75
- repos.each do |repo|
76
- repo_name = EbmSharedLib.get_repo_name(repo[:git_path])
77
- repo_path = "#{top_dir}/#{repo_name}"
78
- branch = repo[:branch]
79
- base_branch = repo[:base_branch]
80
-
81
- puts("\n#{repo_name} pull:\n");
82
-
83
- cmd = "git fetch #{dry_run} --all"
84
- if EbmSharedLib::CL.do_cmd_result(cmd, repo_path) != 0
85
- raise "Git fetch failed for #{repo_name}."
86
- end
87
-
88
- if tag
89
- # use git checkout to force changes from either tag or branch
90
- cmd = "git checkout -f refs/tags/#{tag}"
91
- if EbmSharedLib::CL.do_cmd_result(cmd, repo_path) != 0
92
- raise "Git checkout failed for #{repo_name}."
93
- end
94
- elsif repo[:create_dev_branch]
95
- if remote_version
96
- # pulling from remote version branch
97
- cmd = "git pull #{dry_run} --no-ff --no-edit --recurse-submodules=yes origin #{branch}"
98
- elsif base_version
99
- # pulling from base remote version branch
100
- if base_branch.nil?
101
- raise "You specified base-version but the config has no base_branch."
102
- end
103
- cmd = "git pull #{dry_run} --no-ff --no-edit --recurse-submodules=yes origin #{base_branch}"
104
- else
105
- # pull from the remote branch of the current branch
106
- cmd = "git pull #{dry_run} --no-ff --no-edit --recurse-submodules=yes"
107
- end
108
-
109
- exit_code = EbmSharedLib::CL.do_cmd_ignore_str(cmd, "Automatic merge failed", repo_path)
110
- if exit_code != 0 && exit_code != 999
111
- raise "Git pull failed for #{repo_name}."
112
- end
113
- if exit_code == 999
114
- merge_failed = true
115
- end
116
- end
117
-
118
- cmd = "git submodule sync"
119
- if EbmSharedLib::CL.do_cmd_result(cmd, repo_path) != 0
120
- raise "Submodule sync for #{repo_name} failed."
121
- end
122
- if dry_run.empty?
123
- cmd = "git submodule update"
124
- else
125
- cmd = "git submodule update --no-fetch"
126
- end
127
- if EbmSharedLib::CL.do_cmd_result(cmd, repo_path) != 0
128
- raise "Updating submodules for #{repo_name} failed."
129
- end
130
-
131
- end
132
-
133
- if merge_failed
134
- raise "Automatic merge failed, you must hand merge the conflicts"
135
- end
136
-
137
- end
138
-
139
- end
140
- end
data/lib/commands/push.rb DELETED
@@ -1,83 +0,0 @@
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 Push
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: push [options]"
26
- opts.description = "Push code to the remote repo."
27
-
28
- opts.on("--remote-version", "Push from your local dev branch to the remote version branch - use with caution!") do |v|
29
- options[:remote_version] = true
30
- end
31
-
32
- opts.on('-n', "--dry-run", "Perform a dry run.") do |v|
33
- options[:dry_run] = true
34
- end
35
-
36
- end
37
-
38
- def run(global_options)
39
-
40
- # see if we can open the config file - we append the .config suffix
41
- # the file is expected to be in JSON format
42
- remote_version = !!options[:remote_version]
43
- dry_run = !!options[:dry_run] ? "--dry-run" : ""
44
-
45
- if ARGV.length > 0
46
- raise "You must specify all arguments with their options."
47
- end
48
-
49
- # get config based on name of current dir
50
- info = EbmSharedLib.get_config_from_top_dir
51
-
52
- # Back up to version parent dir. This directory contains the top level repos.
53
- top_dir = Dir.pwd
54
-
55
- repos = info[:repos]
56
- repos.each do |repo|
57
- if repo[:create_dev_branch]
58
- repo_name = EbmSharedLib.get_repo_name(repo[:git_path])
59
- repo_path = "#{top_dir}/#{repo_name}"
60
- local_branch = EbmSharedLib.get_current_branch(repo, repo_path)
61
-
62
- puts("\n#{repo_name} push:\n");
63
-
64
- if remote_version
65
- # pulling from remote version branch
66
- remote_branch = repo[:branch]
67
- cmd = "git push #{dry_run} origin #{local_branch}:#{remote_branch}"
68
- else
69
- # pull from the remote branch of the current branch
70
- # they want to commit whatever has changed and push to current remote
71
- # first grab the current branch name
72
- cmd = "git push #{dry_run} origin #{local_branch}"
73
- end
74
- if EbmSharedLib::CL.do_cmd_result(cmd, repo_path) != 0
75
- raise "Git push failed for #{repo_name}."
76
- end
77
- end
78
- end
79
-
80
- end
81
-
82
- end
83
- end
@@ -1,60 +0,0 @@
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 RemoveMergedBranches
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: status"
26
- opts.description = "Shows the git status of all repos in the config."
27
- opts.on('-n', "--dry-run", "Perform a dry run.") do |v|
28
- options[:dry_run] = true
29
- end
30
-
31
- end
32
-
33
- def run(global_options)
34
-
35
- # see if we can open the config file - we append the .config suffix
36
- # the file is expected to be in JSON format
37
-
38
- # determine config_name by extracting parent of our directory
39
- info = EbmSharedLib.get_config_from_top_dir
40
- dry_run = !!options[:dry_run] ? "--dry-run" : ""
41
-
42
- # Back up to version parent dir. This directory contains the top level repos.
43
- # top_dir = File.expand_path("#{Dir.pwd}/..")
44
- top_dir = Dir.pwd
45
-
46
- repos = info[:repos]
47
- repos.each do |repo|
48
- if repo[:create_dev_branch]
49
- repo_name = EbmSharedLib.get_repo_name(repo[:git_path])
50
- repo_path = "#{top_dir}/#{repo_name}"
51
- File.open("#{repo_name}/merged_branches.txt").each do |line|
52
- cmd = "git push #{dry_run} origin :#{line}"
53
- if EbmSharedLib::CL.do_cmd_result(cmd, repo_path) != 0
54
- end
55
- end
56
- end
57
- end
58
- end
59
- end
60
- end
data/lib/commands/tag.rb DELETED
@@ -1,107 +0,0 @@
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 Tag
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
- :tag,
22
- ]
23
- end
24
-
25
- def register(opts, global_options)
26
- opts.banner = "Usage: tag [options]"
27
- opts.description = "Apply or delete a tag for all taggable repos in a config"
28
-
29
- opts.on('-t', "--tag name", "Required - Name of the tag.") do |v|
30
- options[:tag] = v
31
- end
32
-
33
- opts.on('-d', "--delete", "When set causes tag to be deleted.") do |v|
34
- options[:delete] = true
35
- end
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|
38
- options[:commit_and_push] = true
39
- end
40
-
41
- end
42
-
43
- def run(global_options)
44
-
45
- # see if we can open the config file - we append the .config suffix
46
- # the file is expected to be in JSON format
47
- tag = options[:tag]
48
- delete_tag = !!options[:delete]
49
- commit_and_push = !!options[:commit_and_push] # the !! forces conversion to a boolean
50
-
51
- if (commit_and_push && delete_tag)
52
- raise "You cannot use --commit-and-push with --delete."
53
- end
54
-
55
- info = EbmSharedLib.get_config_from_top_dir
56
-
57
- # other than prepare, any commands that work across the repos expect you to start
58
- # in the containing directory (i.e. if your config is named iphone_3.1, you are expected
59
- # to be in that directory when you run the command).
60
- top_dir = "#{Dir.pwd}"
61
-
62
- repos = info[:repos]
63
- repos.each do |repo|
64
- if repo[:taggable]
65
- repo_name = EbmSharedLib.get_repo_name(repo[:git_path])
66
- repo_path = "#{top_dir}/#{repo_name}"
67
- if delete_tag
68
- cmd = "git tag -d #{tag}"
69
- if EbmSharedLib::CL.do_cmd_result(cmd, repo_path) != 0
70
- raise "Deleting tag failed for #{repo_name}."
71
- end
72
- cmd = "git push origin :refs/tags/#{tag}"
73
- if EbmSharedLib::CL.do_cmd_result(cmd, repo_path) != 0
74
- raise "Deleting tag failed failed for #{repo_name}."
75
- end
76
- else
77
- if commit_and_push
78
- # they want to commit whatever has changed and push to current remote
79
- # first grab the current branch name
80
- branch = EbmSharedLib.get_current_branch(repo, repo_path)
81
-
82
- # we have the local branch so now commit and push to the remote branch
83
- cmd = "git commit -am \"Committing changes via ebm tag --commit_and_push for tag #{tag}.\""
84
- EbmSharedLib::CL.do_cmd_result(cmd, repo_path) # ignore any error
85
-
86
- # now push what we just committed
87
- cmd = "git push origin #{branch}"
88
- if EbmSharedLib::CL.do_cmd_result(cmd, repo_path) != 0
89
- raise "Push failed failed for #{repo_name}."
90
- end
91
- end
92
- cmd = "git tag #{tag}"
93
- if EbmSharedLib::CL.do_cmd_result(cmd, repo_path) != 0
94
- raise "Tagging operation failed for #{repo_name}. Make sure you are in the top level #{config_name} directory."
95
- end
96
- cmd = "git push origin refs/tags/#{tag}"
97
- if EbmSharedLib::CL.do_cmd_result(cmd, repo_path) != 0
98
- raise "Tagging operation failed for #{repo_name}. Make sure you are in the top level #{config_name} directory."
99
- end
100
- end
101
- end
102
- end
103
-
104
- end
105
-
106
- end
107
- end