salesforce-deploy-tool 1.3.0 → 2.0.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 +4 -4
- data/.gitignore +1 -1
- data/bin/sf +26 -228
- data/cucumber-config.yaml-tpl +15 -0
- data/features/push.feature +104 -23
- data/features/support/env.rb +1 -1
- data/features/support/hooks.rb +1 -1
- data/lib/salesforcedeploytool/app.rb +43 -15
- data/lib/salesforcedeploytool/cli.rb +242 -0
- data/lib/salesforcedeploytool/version.rb +1 -1
- data/lib/salesforcedeploytool.rb +7 -2
- data/tpl/build.xml.erb +59 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 947f71272fa457667c1003576a2459182155903a
|
4
|
+
data.tar.gz: ffbc084e4ecea361755fc80ceb3875785c80f63a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3658f66f329e1c875e17c263db2ba5608f3ad11b97dbc6996dab49528d6e0192c0540e7d374267219a4edd1c24bad93e8ae0c383df441b39688f53a1146df13c
|
7
|
+
data.tar.gz: 4ee7cd94cdac963328742b783f2fed28f3f9251f1067663e71aad6f52b860cdd3dd41e27b6b3f2bae50a33559d5432297410666f3085d94e40e9e7563a69ccd4
|
data/.gitignore
CHANGED
data/bin/sf
CHANGED
@@ -1,7 +1,5 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
require '
|
3
|
-
require 'yaml'
|
4
|
-
require 'fileutils'
|
2
|
+
require 'salesforcedeploytool'
|
5
3
|
|
6
4
|
# Disable stdout buffer
|
7
5
|
STDOUT.sync = true
|
@@ -29,244 +27,44 @@ end
|
|
29
27
|
|
30
28
|
# Read sandbox environment
|
31
29
|
begin
|
32
|
-
sandbox = File.open(File.expand_path(SANDBOX_CONFIG_FILE)).read
|
30
|
+
config[:sandbox] = File.open(File.expand_path(SANDBOX_CONFIG_FILE)).read
|
33
31
|
rescue
|
34
|
-
sandbox = nil
|
32
|
+
config[:sandbox] = nil
|
35
33
|
end
|
36
34
|
|
37
|
-
#
|
38
|
-
|
39
|
-
|
40
|
-
config[:version_file] = ENV["SFDT_VERSION_FILE"] || config[:version_file]
|
41
|
-
config[:build_number_pattern] = ENV["SFDT_BUILD_NUMBER_PATTERN"] || config[:build_number_pattern]
|
42
|
-
config[:commit_hash_pattern] = ENV["SFDT_COMMIT_HASH_PATTERN"] || config[:commit_hash_pattern]
|
35
|
+
# Configuration variables firrst from ENV , if not config file
|
36
|
+
|
37
|
+
# Git configs:
|
43
38
|
config[:git_repo] = ENV["SFDT_GIT_REPO"] || config[:git_repo]
|
39
|
+
config[:git_dir] = ENV["SFDT_GIT_DIR"] || config[:git_dir]
|
40
|
+
config[:src_dir] = ENV["SFDT_SRC_DIR"] || config[:src_dir]
|
41
|
+
|
42
|
+
# Salesforce credential configs
|
44
43
|
config[:username] = ENV["SFDT_USERNAME"] || config[:username]
|
45
44
|
config[:password] = ENV["SFDT_PASSWORD"] || config[:password]
|
46
45
|
config[:salesforce_url] = ENV["SFDT_SALESFORCE_URL"] || config[:salesforce_url]
|
47
|
-
config[:deploy_ignore_files] = ENV["SFDT_DEPLOY_IGNORE_FILES"].nil? ? config[:deploy_ignore_files] : ENV["SFDT_DEPLOY_IGNORE_FILES"].split(',')
|
48
46
|
|
49
|
-
#
|
50
|
-
config[:
|
47
|
+
# Project configs
|
48
|
+
config[:version_file] = ENV["SFDT_VERSION_FILE"] || config[:version_file]
|
49
|
+
config[:build_number_pattern] = ENV["SFDT_BUILD_NUMBER_PATTERN"] || config[:build_number_pattern]
|
50
|
+
config[:commit_hash_pattern] = ENV["SFDT_COMMIT_HASH_PATTERN"] || config[:commit_hash_pattern]
|
51
|
+
config[:deploy_ignore_files] = ENV["SFDT_DEPLOY_IGNORE_FILES"].nil? ? config[:deploy_ignore_files] : ENV["SFDT_DEPLOY_IGNORE_FILES"].split(',')
|
51
52
|
|
52
53
|
# Minimal config validation
|
54
|
+
abort "Config error: src_dir not found in #{GLOBAL_CONFIG_FILE} or through SFDT_SRC_DIR" if config[:src_dir].nil?
|
53
55
|
abort "Config error: git_dir not found in #{GLOBAL_CONFIG_FILE} or through SFDT_GIT_DIR" if config[:git_dir].nil?
|
54
|
-
abort "Config error:
|
56
|
+
abort "Config error: git_repo not found in #{GLOBAL_CONFIG_FILE} or through SFDT_GIT_DIR" if config[:git_repo].nil?
|
55
57
|
abort "Config error: username not found in #{GLOBAL_CONFIG_FILE} or through SFDT_USERNAME" if config[:username].nil? && ARGV[0] != 'config'
|
56
58
|
abort "Config error: password not found in #{GLOBAL_CONFIG_FILE} or through SFDT_PASSWORD" if config[:password].nil? && ARGV[0] != 'config'
|
57
59
|
|
58
|
-
#
|
59
|
-
|
60
|
-
abort "ERROR: The environment is not properly configured, please run sf config to clone the repo and setup the credentials"
|
61
|
-
end
|
62
|
-
|
63
|
-
# Normalize file paths:
|
64
|
-
config[:git_dir] = File.expand_path config[:git_dir]
|
65
|
-
config[:tmp_dir] = File.expand_path config[:tmp_dir]
|
66
|
-
|
67
|
-
require 'salesforcedeploytool'
|
68
|
-
|
69
|
-
program :version, SalesforceDeployTool::VERSION
|
70
|
-
program :description, 'A cli tool to help manage and deploy salesforce sandboxes with git'
|
71
|
-
|
72
|
-
command :pull do |c|
|
73
|
-
c.syntax = 'sf pull'
|
74
|
-
c.summary = 'Pull code from the sandbox'
|
75
|
-
c.description = "Pull code from sandbox and update #{config[:git_dir]}"
|
76
|
-
c.example 'usage:', 'sf pull'
|
77
|
-
c.option "--append", "Pull code appending it to the local repository"
|
78
|
-
c.option "--debug", "Verbose output"
|
79
|
-
c.option "--sandbox NAME", "-s NAME", "use 'prod' to deploy production or sandbox name"
|
80
|
-
c.action do |args, options|
|
81
|
-
|
82
|
-
# short flag mapping
|
83
|
-
options.sandbox = options.s if options.s
|
84
|
-
|
85
|
-
# Parameter validation:
|
86
|
-
if options.sandbox.nil? and sandbox.nil?
|
87
|
-
puts "error: please specify sandbox using --sandbox or sf sandbox"
|
88
|
-
exit 1
|
89
|
-
end
|
90
|
-
config[:sandbox] = options.sandbox || sandbox
|
91
|
-
config[:debug] = options.debug.nil? ? false : true
|
92
|
-
|
93
|
-
# The salesforce URL
|
94
|
-
config[:salesforce_url] =
|
95
|
-
ENV["SFDT_SALESFORCE_URL"] || # First from environment variables
|
96
|
-
config[:salesforce_url] || # Second from the configuration files
|
97
|
-
( config[:sandbox] == 'prod' ? 'https://login.salesforce.com' : 'https://test.salesforce.com' ) # If not defined anywhere, use defaults
|
98
|
-
|
99
|
-
# Initialize
|
100
|
-
sfdt = SalesforceDeployTool::App.new config
|
101
|
-
|
102
|
-
# Clean all files from repo
|
103
|
-
sfdt.clean_git_dir unless options.append
|
104
|
-
|
105
|
-
# Pull the changes
|
106
|
-
print "INFO: Pulling changes from #{config[:sandbox]} using url #{config[:salesforce_url]} "
|
107
|
-
print "\n\n" if options.debug
|
108
|
-
sfdt.pull
|
109
|
-
sfdt.clean_version
|
110
|
-
|
111
|
-
end
|
112
|
-
|
113
|
-
end
|
114
|
-
|
115
|
-
command :push do |c|
|
116
|
-
c.syntax = 'sf push [options]'
|
117
|
-
c.summary = 'Push code into a sandbox'
|
118
|
-
c.description = ''
|
119
|
-
c.example 'description', "Push the code that is located into #{config[:git_dir]} into the active sandbox"
|
120
|
-
c.option "--sandbox NAME", "-s NAME", "use 'prod' to deploy production or sandbox name"
|
121
|
-
c.option "--debug", "Verbose output"
|
122
|
-
c.option "--test", "-T", "Deploy and test"
|
123
|
-
c.option "--exclude LIST", "-x LIST", "a CSV list of metadata to exclude when creating destructiveChange.xml"
|
124
|
-
c.option "--append", "Disable destructive change and do an append deploy"
|
125
|
-
c.option "--build_number NUMBER","Record build number on version file"
|
126
|
-
c.action do |args, options|
|
127
|
-
|
128
|
-
# short flag mapping
|
129
|
-
options.test = true if options.T
|
130
|
-
options.exclude = options.x if options.x
|
131
|
-
options.sandbox = options.s if options.s
|
132
|
-
|
133
|
-
# Parameter validation:
|
134
|
-
if options.sandbox.nil? and sandbox.nil?
|
135
|
-
puts "error: please specify the sandbox to pull from using --sandbox"
|
136
|
-
exit 1
|
137
|
-
end
|
138
|
-
config[:sandbox] = options.sandbox || sandbox
|
139
|
-
config[:test] = options.test.nil? ? false : true
|
140
|
-
config[:debug] = options.debug.nil? ? false : true
|
141
|
-
|
142
|
-
# The salesforce URL
|
143
|
-
config[:salesforce_url] =
|
144
|
-
ENV["SFDT_SALESFORCE_URL"] || # First from environment variables
|
145
|
-
config[:salesforce_url] || # Second from the configuration files
|
146
|
-
( config[:sandbox] == 'prod' ? 'https://login.salesforce.com' : 'https://test.salesforce.com' ) # If not defined anywhere, use defaults
|
147
|
-
|
148
|
-
# Initialize
|
149
|
-
sfdt = SalesforceDeployTool::App.new config.clone
|
60
|
+
# Create a temporary directory
|
61
|
+
config[:tmp_dir] = Dir.mktmpdir 'sfdt-'
|
150
62
|
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
config_tmp[:git_dir] = config_tmp[:tmp_dir]
|
159
|
-
FileUtils.rm_rf config_tmp[:git_dir] if File.exists? config_tmp[:git_dir]
|
160
|
-
FileUtils.cp_r config[:git_dir],config_tmp[:git_dir]
|
161
|
-
sfdt_tmp = SalesforceDeployTool::App.new config_tmp
|
162
|
-
print "INFO: Pulling changes from #{config[:sandbox]} using url #{config[:salesforce_url]} to temporary directory #{config[:tmp_dir]} to generate destructiveChanges.xml "
|
163
|
-
sfdt_tmp.pull
|
164
|
-
|
165
|
-
# Create destructiveChanges.xml
|
166
|
-
puts "INFO: Creating destructive changes xml"
|
167
|
-
dc_gen = Dcgen::App.new
|
168
|
-
dc_gen.master = File.join(config[:git_dir],config[:buildxml_dir],'src')
|
169
|
-
dc_gen.destination = File.join(config[:tmp_dir],config[:buildxml_dir],'src')
|
170
|
-
dc_gen.output = DESTRUCTIVE_CHANGE_FILE
|
171
|
-
dc_gen.exclude = options.exclude.split(',') unless options.exclude.nil?
|
172
|
-
dc_gen.verbose = false if not options.debug
|
173
|
-
dc_gen.generate_destructive_changes
|
174
|
-
|
175
|
-
end
|
176
|
-
|
177
|
-
# Push code to sandbox
|
178
|
-
begin
|
179
|
-
# Set version
|
180
|
-
sfdt.build_number = options.build_number if not options.build_number.nil?
|
181
|
-
sfdt.set_version
|
182
|
-
|
183
|
-
# Enable test if option enabled
|
184
|
-
sfdt.test = options.test.nil? ? false : true
|
185
|
-
|
186
|
-
# Push
|
187
|
-
print(options.test.nil? ? "INFO: Deploying code to #{config[:sandbox]}: ": "INFO: Deploying and Testing code to #{config[:sandbox]}: \n\n")
|
188
|
-
sfdt.push
|
189
|
-
ensure
|
190
|
-
sfdt.clean_version
|
191
|
-
end
|
192
|
-
|
193
|
-
end
|
194
|
-
end
|
195
|
-
|
196
|
-
command :sandbox do |c|
|
197
|
-
c.syntax = 'sf sandbox SANDBOX_NAME'
|
198
|
-
c.summary = 'Set sandbox to work on, this can be overriden by --sandbox '
|
199
|
-
c.description = 'Set the sandbox to work with pull and push. If no parameter defined, it will print the current sandbox selected.'
|
200
|
-
c.action do |args, options|
|
201
|
-
|
202
|
-
if args.size > 1
|
203
|
-
puts "error: Wrong number of arguments"
|
204
|
-
end
|
205
|
-
|
206
|
-
if args.size == 0
|
207
|
-
if ! sandbox.nil?
|
208
|
-
puts "sandbox: " + sandbox
|
209
|
-
exit 0
|
210
|
-
else
|
211
|
-
puts "WARN: Sandbox has not been set yet"
|
212
|
-
exit 1
|
213
|
-
end
|
214
|
-
end
|
215
|
-
File.open(File.expand_path(SANDBOX_CONFIG_FILE),'w').write args.first
|
216
|
-
|
217
|
-
end
|
218
|
-
end
|
219
|
-
|
220
|
-
command :config do |c|
|
221
|
-
c.syntax = 'sf config'
|
222
|
-
c.summary = 'Go through the configuration wizard to config your environment'
|
223
|
-
c.action do |args, options|
|
224
|
-
|
225
|
-
if args.size != 0
|
226
|
-
puts "error: Wrong number of arguments"
|
227
|
-
end
|
228
|
-
|
229
|
-
config_new = {}
|
230
|
-
|
231
|
-
config_new[:username] = ask "Please enter your SalesForce production login user name" do |q|
|
232
|
-
q.validate = /^\S+@\S+$/
|
233
|
-
end.to_s
|
234
|
-
|
235
|
-
config_new[:password] = ask "Please enter your Salesforce production password" do |q|
|
236
|
-
q.echo = "x"
|
237
|
-
end.to_s
|
238
|
-
|
239
|
-
git_name = ask "Please enter your Full name to be used as commit owner on GIT" do |q|
|
240
|
-
q.validate = /^[a-zA-Z\s]+$/
|
241
|
-
end
|
242
|
-
|
243
|
-
git_email = ask "Please enter your email to be used as commit email on GIT" do |q|
|
244
|
-
q.validate = /^\S+@\S+$/
|
245
|
-
end
|
246
|
-
|
247
|
-
sandbox = ask "Please enter your sandbox so to be used as default when push and pull" do |q|
|
248
|
-
q.validate = /^[a-zA-Z]+$/
|
249
|
-
end
|
250
|
-
|
251
|
-
%x[git config --global user.email "#{git_email}"]
|
252
|
-
%x[git config --global user.name "#{git_name}"]
|
253
|
-
|
254
|
-
config[:username] = config_new[:username]
|
255
|
-
config[:password] = config_new[:password]
|
256
|
-
config[:sandbox] = sandbox
|
257
|
-
|
258
|
-
File.open(File.expand_path(SANDBOX_CONFIG_FILE),'w').write sandbox
|
259
|
-
File.open(File.expand_path(CONFIG_FILE),'w').write config_new.to_yaml
|
260
|
-
|
261
|
-
# Initialize
|
262
|
-
sfdt = SalesforceDeployTool::App.new config
|
263
|
-
|
264
|
-
# Clone
|
265
|
-
sfdt.clone
|
266
|
-
|
267
|
-
end
|
63
|
+
begin
|
64
|
+
SalesforceDeployTool::CLI.new.run config
|
65
|
+
rescue => e
|
66
|
+
puts "ERROR: #{e}"
|
67
|
+
exit 1
|
68
|
+
ensure
|
69
|
+
FileUtils.rm_rf config[:tmp_dir] if Dir.exists? config[:tmp_dir]
|
268
70
|
end
|
269
|
-
|
270
|
-
default_command :help
|
271
|
-
|
272
|
-
|
@@ -0,0 +1,15 @@
|
|
1
|
+
:production_username: 'john.doe@example.com'
|
2
|
+
:production_password: 'passw0rd'
|
3
|
+
:git_full_name: 'John Doe'
|
4
|
+
:git_email_address: 'john.doe@example.com'
|
5
|
+
:sandbox: 'test'
|
6
|
+
:environment_variables:
|
7
|
+
:sfdt_git_repo: '/url/to/git/repo/with/test/salesforce/classes'
|
8
|
+
:sfdt_git_dir: 'where/to/be/cloned'
|
9
|
+
:sfdt_src_dir: 'within/the/repo/path/to/salesforce/source/code'
|
10
|
+
:replacement_patterns:
|
11
|
+
:env_a: 'testa'
|
12
|
+
:env_b: 'testb'
|
13
|
+
:build_number_pattern: '%%BUILD_NUMBER%%'
|
14
|
+
:commit_hash_pattern: '%%COMMIT_HASH%%'
|
15
|
+
:version_file: 'classes/VersionTest.cls'
|
data/features/push.feature
CHANGED
@@ -7,10 +7,10 @@ Feature: Push code to salesforce
|
|
7
7
|
Scenario: Push code to a sandbox
|
8
8
|
When I run `sf push`
|
9
9
|
Then the exit status should be 0
|
10
|
-
And a file named "
|
10
|
+
And a file named "sfdt_git_dir/sfdt_src_dir/destructiveChanges.xml" should exist
|
11
11
|
And the output should match:
|
12
12
|
"""
|
13
|
-
^INFO: Pulling changes from env_a using url https:\/\/test.salesforce.com to temporary directory
|
13
|
+
^INFO: Pulling changes from env_a using url https:\/\/test.salesforce.com to temporary directory to generate destructiveChanges.xml.*OK$
|
14
14
|
^INFO: Creating destructive changes xml$
|
15
15
|
^INFO: Deploying code to env_a:.*OK$
|
16
16
|
"""
|
@@ -18,10 +18,10 @@ Feature: Push code to salesforce
|
|
18
18
|
Scenario: Push code to a different sandbox
|
19
19
|
When I run `sf push -s env_b`
|
20
20
|
Then the exit status should be 0
|
21
|
-
And a file named "
|
21
|
+
And a file named "sfdt_git_dir/sfdt_src_dir/destructiveChanges.xml" should exist
|
22
22
|
And the output should match:
|
23
23
|
"""
|
24
|
-
^INFO: Pulling changes from env_b using url https://test.salesforce.com to temporary directory
|
24
|
+
^INFO: Pulling changes from env_b using url https://test.salesforce.com to temporary directory to generate destructiveChanges.xml.*OK$
|
25
25
|
^INFO: Creating destructive changes xml$
|
26
26
|
^INFO: Deploying code to env_b:.*OK$
|
27
27
|
"""
|
@@ -35,28 +35,28 @@ Feature: Push code to salesforce
|
|
35
35
|
Then the exit status should be 1
|
36
36
|
And the output should match:
|
37
37
|
"""
|
38
|
-
^INFO: Pulling changes from prod using url https://login.salesforce.com to temporary directory
|
38
|
+
^INFO: Pulling changes from prod using url https://login.salesforce.com to temporary directory to generate destructiveChanges.xml.*$
|
39
39
|
"""
|
40
40
|
|
41
41
|
Scenario: Push code to a sandbox with debug information
|
42
42
|
When I run `sf push -d`
|
43
43
|
Then the exit status should be 0
|
44
44
|
And the output should match /^.* env_a .*BUILD SUCCESSFUL.*Diff between.*Changes detected.*File generated.*BUILD SUCCESSFUL.*$/
|
45
|
-
And a file named "
|
45
|
+
And a file named "sfdt_git_dir/sfdt_src_dir/destructiveChanges.xml" should exist
|
46
46
|
|
47
47
|
Scenario: Push code to a sandbox with debug information to a different sandbox
|
48
48
|
When I run `sf push -d -s env_b`
|
49
49
|
Then the exit status should be 0
|
50
50
|
And the output should match /^.* env_b .*BUILD SUCCESSFUL.*Diff between.*Changes detected.*File generated.*BUILD SUCCESSFUL.*$/
|
51
|
-
And a file named "
|
51
|
+
And a file named "sfdt_git_dir/sfdt_src_dir/destructiveChanges.xml" should exist
|
52
52
|
|
53
53
|
Scenario: Push code to a sandbox and trigger all the tests
|
54
54
|
When I run `sf push -T`
|
55
55
|
Then the exit status should be 0
|
56
|
-
And a file named "
|
56
|
+
And a file named "sfdt_git_dir/sfdt_src_dir/destructiveChanges.xml" should exist
|
57
57
|
And the output should match:
|
58
58
|
"""
|
59
|
-
^INFO: Pulling changes from env_a using url https://test.salesforce.com to temporary directory
|
59
|
+
^INFO: Pulling changes from env_a using url https://test.salesforce.com to temporary directory to generate destructiveChanges.xml.*OK$
|
60
60
|
^INFO: Creating destructive changes xml$
|
61
61
|
^INFO: Deploying and Testing code to env_a:.*OK$
|
62
62
|
"""
|
@@ -64,13 +64,13 @@ Feature: Push code to salesforce
|
|
64
64
|
Scenario: Push code to a sandbox and trigger all the tests in debug mode
|
65
65
|
When I run `sf push -T -d`
|
66
66
|
Then the exit status should be 0
|
67
|
-
And a file named "
|
67
|
+
And a file named "sfdt_git_dir/sfdt_src_dir/destructiveChanges.xml" should exist
|
68
68
|
And the output should match /^.* env_a .*BUILD SUCCESSFUL.*Diff between.*Changes detected.*File generated.*Running Test:.*DEPLOYMENT SUCCEEDED.*BUILD SUCCESSFUL.*$/
|
69
69
|
|
70
70
|
Scenario: Push code to a sandbox in append mode
|
71
71
|
When I run `sf push -a`
|
72
72
|
Then the exit status should be 0
|
73
|
-
And a file named "
|
73
|
+
And a file named "sfdt_git_dir/sfdt_src_dir/destructiveChanges.xml" should not exist
|
74
74
|
And the output should match:
|
75
75
|
"""
|
76
76
|
^INFO: Deploying code to env_a:.*OK$
|
@@ -79,24 +79,23 @@ Feature: Push code to salesforce
|
|
79
79
|
Scenario: Push code to a sandbox in append mode and run all tests
|
80
80
|
When I run `sf push -a -T`
|
81
81
|
Then the exit status should be 0
|
82
|
-
And a file named "
|
82
|
+
And a file named "sfdt_git_dir/sfdt_src_dir/destructiveChanges.xml" should not exist
|
83
83
|
And the output should match:
|
84
84
|
"""
|
85
85
|
^INFO: Deploying and Testing code to env_a:.*OK$
|
86
86
|
"""
|
87
87
|
|
88
|
-
@test
|
89
88
|
Scenario: Push code to a sandbox in append mode and run all tests and output debug information
|
90
89
|
When I run `sf push -a -T -d`
|
91
90
|
Then the exit status should be 0
|
92
|
-
And a file named "
|
91
|
+
And a file named "sfdt_git_dir/sfdt_src_dir/destructiveChanges.xml" should not exist
|
93
92
|
And the output should match:
|
94
93
|
"""
|
95
94
|
^INFO: Deploying and Testing code to env_a: $
|
96
95
|
^$
|
97
96
|
^Buildfile: .*$
|
98
97
|
^$
|
99
|
-
^
|
98
|
+
^deployAndTestAllCode:$
|
100
99
|
"""
|
101
100
|
And the output should match /Running Test/
|
102
101
|
And the output should match /DEPLOYMENT SUCCEEDED.*BUILD SUCCESSFUL/
|
@@ -106,14 +105,14 @@ Feature: Push code to salesforce
|
|
106
105
|
| variable | value |
|
107
106
|
| SFDT_VERSION_FILE | version_file |
|
108
107
|
| SFDT_BUILD_NUMBER_PATTERN | build_number_pattern |
|
109
|
-
When I watch "sfdt_git_dir/version_file" for changes and copy to "test_file"
|
108
|
+
When I watch "sfdt_git_dir/sfdt_src_dir/version_file" for changes and copy to "test_file"
|
110
109
|
And I run `sf push --build_number 123456789`
|
111
110
|
Then the exit status should be 0
|
112
111
|
And the file "test_file" should contain "123456789"
|
113
|
-
And the file "sfdt_git_dir/version_file" should contain "build_number_pattern"
|
112
|
+
And the file "sfdt_git_dir/sfdt_src_dir/version_file" should contain "build_number_pattern"
|
114
113
|
And the output should match:
|
115
114
|
"""
|
116
|
-
^INFO: Pulling changes from env_a using url https://test.salesforce.com to temporary directory
|
115
|
+
^INFO: Pulling changes from env_a using url https://test.salesforce.com to temporary directory to generate destructiveChanges.xml.*OK$
|
117
116
|
^INFO: Creating destructive changes xml$
|
118
117
|
^INFO: Deploying code to env_a:.*OK$
|
119
118
|
"""
|
@@ -123,14 +122,14 @@ Feature: Push code to salesforce
|
|
123
122
|
| variable | value |
|
124
123
|
| SFDT_VERSION_FILE | version_file |
|
125
124
|
| SFDT_COMMIT_HASH_PATTERN | commit_hash_pattern |
|
126
|
-
When I watch "sfdt_git_dir/version_file" for changes and copy to "test_file"
|
125
|
+
When I watch "sfdt_git_dir/sfdt_src_dir/version_file" for changes and copy to "test_file"
|
127
126
|
And I run `sf push`
|
128
127
|
Then the exit status should be 0
|
129
128
|
And the file "test_file" should not contain "commit_hash_pattern"
|
130
|
-
And the file "sfdt_git_dir/version_file" should contain "commit_hash_pattern"
|
129
|
+
And the file "sfdt_git_dir/sfdt_src_dir/version_file" should contain "commit_hash_pattern"
|
131
130
|
And the output should match:
|
132
131
|
"""
|
133
|
-
^INFO: Pulling changes from env_a using url https://test.salesforce.com to temporary directory
|
132
|
+
^INFO: Pulling changes from env_a using url https://test.salesforce.com to temporary directory to generate destructiveChanges.xml.*OK$
|
134
133
|
^INFO: Creating destructive changes xml$
|
135
134
|
^INFO: Deploying code to env_a:.*OK$
|
136
135
|
"""
|
@@ -141,7 +140,7 @@ Feature: Push code to salesforce
|
|
141
140
|
Then the exit status should be 1
|
142
141
|
And the output should match:
|
143
142
|
"""
|
144
|
-
^ERROR: The
|
143
|
+
^ERROR: The source directory .* is not a valid salesforce source directory
|
145
144
|
"""
|
146
145
|
|
147
146
|
Scenario: Push code to a sandbox specifying a different URL
|
@@ -155,4 +154,86 @@ Feature: Push code to salesforce
|
|
155
154
|
.*Failed to login: Failed to send request to https://invalid_url.salesforce.com.*
|
156
155
|
"""
|
157
156
|
|
158
|
-
|
157
|
+
Scenario: Push code to a sandbox and trigger individual tests in debug mode
|
158
|
+
When I run `sf push -r individual_test -d`
|
159
|
+
Then the exit status should be 0
|
160
|
+
And a file named "sfdt_git_dir/sfdt_src_dir/destructiveChanges.xml" should exist
|
161
|
+
And the output should match:
|
162
|
+
"""
|
163
|
+
^INFO: Deploying and Testing code to env_a: $
|
164
|
+
^$
|
165
|
+
^Buildfile: .*$
|
166
|
+
^$
|
167
|
+
^deployAndTestAllCode:$
|
168
|
+
"""
|
169
|
+
And the output should match /Running Test/
|
170
|
+
And the output should match /DEPLOYMENT SUCCEEDED.*BUILD SUCCESSFUL/
|
171
|
+
|
172
|
+
Scenario: Push code to a sandbox with a build number
|
173
|
+
Given I set the environment variables to:
|
174
|
+
| variable | value |
|
175
|
+
| SFDT_VERSION_FILE | version_file |
|
176
|
+
| SFDT_BUILD_NUMBER_PATTERN | build_number_pattern |
|
177
|
+
When I watch "sfdt_git_dir/sfdt_src_dir/version_file" for changes and copy to "test_file"
|
178
|
+
And I run `sf push --build_number 123456789`
|
179
|
+
Then the exit status should be 0
|
180
|
+
And the file "test_file" should contain "123456789"
|
181
|
+
And the file "sfdt_git_dir/sfdt_src_dir/version_file" should contain "build_number_pattern"
|
182
|
+
And the output should match:
|
183
|
+
"""
|
184
|
+
^INFO: Pulling changes from env_a using url https://test.salesforce.com to temporary directory to generate destructiveChanges.xml.*OK$
|
185
|
+
^INFO: Creating destructive changes xml$
|
186
|
+
^INFO: Deploying code to env_a:.*OK$
|
187
|
+
"""
|
188
|
+
|
189
|
+
Scenario: Push code to a sandbox with the commit hash stamped into a version file
|
190
|
+
Given I set the environment variables to:
|
191
|
+
| variable | value |
|
192
|
+
| SFDT_VERSION_FILE | version_file |
|
193
|
+
| SFDT_COMMIT_HASH_PATTERN | commit_hash_pattern |
|
194
|
+
When I watch "sfdt_git_dir/sfdt_src_dir/version_file" for changes and copy to "test_file"
|
195
|
+
And I run `sf push`
|
196
|
+
Then the exit status should be 0
|
197
|
+
And the file "test_file" should not contain "commit_hash_pattern"
|
198
|
+
And the file "sfdt_git_dir/sfdt_src_dir/version_file" should contain "commit_hash_pattern"
|
199
|
+
And the output should match:
|
200
|
+
"""
|
201
|
+
^INFO: Pulling changes from env_a using url https://test.salesforce.com to temporary directory to generate destructiveChanges.xml.*OK$
|
202
|
+
^INFO: Creating destructive changes xml$
|
203
|
+
^INFO: Deploying code to env_a:.*OK$
|
204
|
+
"""
|
205
|
+
|
206
|
+
Scenario: Push code to a sandbox with the repo not being cloned it should point the user to run sf config
|
207
|
+
When I delete the repository directory
|
208
|
+
And I run `sf push -d`
|
209
|
+
Then the exit status should be 1
|
210
|
+
And the output should match:
|
211
|
+
"""
|
212
|
+
^ERROR: The source directory .* is not a valid salesforce source directory
|
213
|
+
"""
|
214
|
+
|
215
|
+
Scenario: Push code to a sandbox specifying a different URL
|
216
|
+
Given I set the environment variables to:
|
217
|
+
| variable | value |
|
218
|
+
| SFDT_SALESFORCE_URL | https://invalid_url.salesforce.com |
|
219
|
+
When I run `sf push -d`
|
220
|
+
Then the exit status should be 1
|
221
|
+
And the output should match:
|
222
|
+
"""
|
223
|
+
.*Failed to login: Failed to send request to https://invalid_url.salesforce.com.*
|
224
|
+
"""
|
225
|
+
@new
|
226
|
+
Scenario: Push code to a sandbox and trigger individual tests in debug mode
|
227
|
+
When I run `sf push -r individual_test -d`
|
228
|
+
Then the exit status should be 0
|
229
|
+
And a file named "sfdt_git_dir/sfdt_src_dir/destructiveChanges.xml" should exist
|
230
|
+
And the output should match:
|
231
|
+
"""
|
232
|
+
^INFO: Deploying and Testing code to env_a: $
|
233
|
+
^$
|
234
|
+
^Buildfile: .*$
|
235
|
+
^$
|
236
|
+
^deployAndTestCode:$
|
237
|
+
"""
|
238
|
+
And the output should match /Running Test: individual_test/
|
239
|
+
And the output should match /DEPLOYMENT SUCCEEDED.*BUILD SUCCESSFUL/
|
data/features/support/env.rb
CHANGED
data/features/support/hooks.rb
CHANGED
@@ -3,39 +3,49 @@ module SalesforceDeployTool
|
|
3
3
|
class App
|
4
4
|
|
5
5
|
attr_accessor :build_number
|
6
|
-
attr_accessor :
|
6
|
+
attr_accessor :run_all_tests
|
7
7
|
|
8
8
|
def initialize config
|
9
9
|
|
10
10
|
# Config file validation:
|
11
11
|
( @git_repo = config[:git_repo] ).nil? and raise "Invalid Config: git_repo not found"
|
12
12
|
( @git_dir = config[:git_dir] ).nil? and raise "Invalid Config: git_dir not found"
|
13
|
+
( @src_dir = config[:src_dir] ).nil? and raise "Invalid Config: src_dir not found"
|
13
14
|
( @sandbox = config[:sandbox] ).nil? and raise "Invalid Config: sandbox not found"
|
14
|
-
( @password = config[:password] ).nil? and raise "Invalid Config: password not found, please run `sf config`"
|
15
15
|
( @username = config[:username] ).nil? and raise "Invalid Config: username not found, please run `sf config`"
|
16
16
|
( @password = config[:password] ).nil? and raise "Invalid Config: password not found, please run `sf config`"
|
17
17
|
|
18
18
|
# Parameter Normalization
|
19
|
-
@git_dir = File.expand_path
|
20
|
-
@
|
21
|
-
@version_file = File.join(@
|
22
|
-
@deploy_ignore_files = config[:deploy_ignore_files].map {|f| File.expand_path
|
19
|
+
@git_dir = File.expand_path(@git_dir)
|
20
|
+
@full_src_dir = File.join(@git_dir,@src_dir)
|
21
|
+
@version_file = File.join(@full_src_dir,config[:version_file]) if !config[:version_file].nil?
|
22
|
+
@deploy_ignore_files = config[:deploy_ignore_files].map {|f| File.expand_path(File.join(@full_src_dir,f)) } if !config[:deploy_ignore_files].nil?
|
23
23
|
@build_number_pattern = config[:build_number_pattern]
|
24
24
|
@commit_hash_pattern = config[:commit_hash_pattern]
|
25
|
-
@buildxml_dir = config[:buildxml_dir]
|
26
25
|
@username = @sandbox == 'prod' ? @username : @username + '.' + @sandbox
|
27
26
|
@server_url = config[:salesforce_url]
|
28
27
|
|
29
28
|
# Defaults
|
29
|
+
@run_tests = []
|
30
30
|
@debug ||= config[:debug]
|
31
|
-
@test ||= config[:test]
|
32
31
|
@build_number ||= 'N/A'
|
33
32
|
@version_file ||= false
|
34
|
-
@buildxml_dir ||= ''
|
35
33
|
@build_number_pattern ||= false
|
36
34
|
@commit_hash_pattern ||= false
|
37
35
|
@deploy_ignore_files ||= []
|
38
36
|
|
37
|
+
# Template dir
|
38
|
+
buildxml_path = File.join($:.select {|x| x.match(/salesforce-deploy-tool/) },'..','tpl','build.xml.erb')
|
39
|
+
@buildxml_erb = File.read(buildxml_path)
|
40
|
+
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
# @run_tests can't be nil
|
45
|
+
def run_tests= value
|
46
|
+
value ||= []
|
47
|
+
raise "ArgumentError" if value.class != Array
|
48
|
+
@run_tests = value
|
39
49
|
end
|
40
50
|
|
41
51
|
def set_version
|
@@ -78,7 +88,7 @@ module SalesforceDeployTool
|
|
78
88
|
|
79
89
|
def clean_git_dir
|
80
90
|
|
81
|
-
Dir[File.join(@
|
91
|
+
Dir[File.join(@full_src_dir,'*')].each do |dir|
|
82
92
|
FileUtils.rm_rf dir unless dir =~ /.*package.xml$/
|
83
93
|
end
|
84
94
|
|
@@ -86,7 +96,14 @@ module SalesforceDeployTool
|
|
86
96
|
|
87
97
|
def pull
|
88
98
|
|
99
|
+
# Parameter validation
|
100
|
+
raise "package.xml not found under #{@full_src_dir}" if !File.exists? File.join(@full_src_dir,'package.xml')
|
101
|
+
|
102
|
+
renderer = ERB.new(@buildxml_erb, nil,'%<>-')
|
103
|
+
File.open('build.xml','w') {|f| f.write renderer.result(binding) }
|
104
|
+
|
89
105
|
env_vars = ""
|
106
|
+
env_vars += " SF_SRC_DIR=" + @full_src_dir
|
90
107
|
env_vars += " SF_USERNAME=" + @username
|
91
108
|
env_vars += " SF_PASSWORD=" + @password
|
92
109
|
env_vars += " SF_SERVERURL=" + @server_url
|
@@ -94,8 +111,6 @@ module SalesforceDeployTool
|
|
94
111
|
|
95
112
|
full_cmd = env_vars + cmd
|
96
113
|
|
97
|
-
Dir.chdir File.join(@git_dir,@buildxml_dir)
|
98
|
-
|
99
114
|
exec_options = {
|
100
115
|
:stderr => @debug,
|
101
116
|
:stdout => @debug,
|
@@ -123,11 +138,15 @@ module SalesforceDeployTool
|
|
123
138
|
|
124
139
|
def push
|
125
140
|
|
126
|
-
#
|
127
|
-
|
141
|
+
# Parameter validation
|
142
|
+
raise "package.xml not found under #{@full_src_dir}" if !File.exists? File.join(@full_src_dir,'package.xml')
|
143
|
+
|
144
|
+
renderer = ERB.new(@buildxml_erb, nil,'%<>-')
|
145
|
+
File.open('build.xml','w') {|f| f.write renderer.result(binding) }
|
128
146
|
|
129
147
|
# Set env variables to run ant
|
130
148
|
env_vars = ""
|
149
|
+
env_vars += " SF_SRC_DIR=" + @full_src_dir
|
131
150
|
env_vars += " SF_USERNAME=" + @username
|
132
151
|
env_vars += " SF_PASSWORD=" + @password
|
133
152
|
env_vars += " SF_SERVERURL=" + @server_url
|
@@ -146,7 +165,16 @@ module SalesforceDeployTool
|
|
146
165
|
exec_options[:failmsg] = nil
|
147
166
|
end
|
148
167
|
|
149
|
-
|
168
|
+
if @run_all_tests
|
169
|
+
cmd = " ant deployAndTestAllCode"
|
170
|
+
else
|
171
|
+
if @run_tests
|
172
|
+
cmd = " ant deployAndTestCode"
|
173
|
+
else
|
174
|
+
cmd = " ant deployCode"
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
150
178
|
full_cmd = env_vars + cmd
|
151
179
|
|
152
180
|
# Delete files to be ignored:
|
@@ -0,0 +1,242 @@
|
|
1
|
+
|
2
|
+
module SalesforceDeployTool
|
3
|
+
|
4
|
+
class CLI
|
5
|
+
|
6
|
+
include Commander::Methods
|
7
|
+
|
8
|
+
def run config
|
9
|
+
|
10
|
+
# Normalize file paths:
|
11
|
+
config[:git_dir] = File.expand_path config[:git_dir]
|
12
|
+
full_src_dir = File.join(config[:git_dir],config[:src_dir])
|
13
|
+
|
14
|
+
# If the repository is not cloned then fail:
|
15
|
+
if !File.exists?(full_src_dir) && ['pull','push'].include?(ARGV[0]) && !File.exists?(File.join(full_src_dir,"package.xml"))
|
16
|
+
abort "ERROR: The source directory #{full_src_dir} is not a valid salesforce source directory"
|
17
|
+
end
|
18
|
+
|
19
|
+
# Chdir to working directory
|
20
|
+
Dir.chdir config[:tmp_dir]
|
21
|
+
|
22
|
+
# saleforce-deploy-tool version and description
|
23
|
+
program :version, SalesforceDeployTool::VERSION
|
24
|
+
program :description, 'A cli tool to help manage and deploy salesforce sandboxes with git'
|
25
|
+
|
26
|
+
# Commands:
|
27
|
+
command :pull do |c|
|
28
|
+
c.syntax = 'sf pull'
|
29
|
+
c.summary = 'Pull code from the sandbox'
|
30
|
+
c.description = "Pull code from sandbox and update #{config[:git_dir]}"
|
31
|
+
c.example 'usage:', 'sf pull'
|
32
|
+
c.option "--append", "Pull code appending it to the local repository"
|
33
|
+
c.option "--debug", "Verbose output"
|
34
|
+
c.option "--sandbox NAME", "-s NAME", "use 'prod' to deploy production or sandbox name"
|
35
|
+
c.action do |args, options|
|
36
|
+
|
37
|
+
# short flag mapping
|
38
|
+
options.sandbox = options.s if options.s
|
39
|
+
|
40
|
+
# Parameter validation:
|
41
|
+
if options.sandbox.nil? and config[:sandbox].nil?
|
42
|
+
puts "error: please specify sandbox using --sandbox or sf sandbox"
|
43
|
+
exit 1
|
44
|
+
end
|
45
|
+
config[:sandbox] = options.sandbox if options.sandbox
|
46
|
+
config[:debug] = options.debug.nil? ? false : true
|
47
|
+
|
48
|
+
# The salesforce URL
|
49
|
+
config[:salesforce_url] =
|
50
|
+
ENV["SFDT_SALESFORCE_URL"] || # First from environment variables
|
51
|
+
config[:salesforce_url] || # Second from the configuration files
|
52
|
+
( config[:sandbox] == 'prod' ? 'https://login.salesforce.com' : 'https://test.salesforce.com' ) # If not defined anywhere, use defaults
|
53
|
+
|
54
|
+
# Initialize
|
55
|
+
sfdt = SalesforceDeployTool::App.new config
|
56
|
+
|
57
|
+
# Clean all files from repo
|
58
|
+
sfdt.clean_git_dir unless options.append
|
59
|
+
|
60
|
+
# Pull the changes
|
61
|
+
print "INFO: Pulling changes from #{config[:sandbox]} using url #{config[:salesforce_url]} "
|
62
|
+
print "\n\n" if options.debug
|
63
|
+
sfdt.pull
|
64
|
+
sfdt.clean_version
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
|
70
|
+
command :push do |c|
|
71
|
+
c.syntax = 'sf push [options]'
|
72
|
+
c.summary = 'Push code into a sandbox'
|
73
|
+
c.description = ''
|
74
|
+
c.example 'description', "Push the code that is located into #{config[:git_dir]} into the active sandbox"
|
75
|
+
c.option "--sandbox NAME", "-s NAME", "use 'prod' to deploy production or sandbox name"
|
76
|
+
c.option "--debug", "Verbose output"
|
77
|
+
c.option "--exclude CSV_LIST", "-x CSV_LIST", "a CSV list of metadata to exclude when creating destructiveChange.xml"
|
78
|
+
c.option "--append", "Disable destructive change and do an append deploy"
|
79
|
+
c.option "--build_number NUMBER","Record build number on version file"
|
80
|
+
c.option "--run-all-tests", "-T", "Deploy and test"
|
81
|
+
c.option "--run-tests CSV_LIST", "-r CSV_LIST", "a CSV list of individual classes to run tests"
|
82
|
+
c.action do |args, options|
|
83
|
+
|
84
|
+
# short flag mapping
|
85
|
+
options.run_all_tests = true if options.T
|
86
|
+
options.run_tests = options.r if options.r
|
87
|
+
options.exclude = options.x if options.x
|
88
|
+
options.sandbox = options.s if options.s
|
89
|
+
|
90
|
+
# Parameter validation:
|
91
|
+
|
92
|
+
if options.run_all_tests and options.run_tests
|
93
|
+
puts "warning: --run-tests is ignored as --test has been declared "
|
94
|
+
end
|
95
|
+
|
96
|
+
if options.sandbox.nil? and config[:sandbox].nil?
|
97
|
+
puts "error: please specify the sandbox to pull from using --sandbox"
|
98
|
+
exit 1
|
99
|
+
end
|
100
|
+
config[:sandbox] = options.sandbox if options.sandbox
|
101
|
+
config[:debug] = options.debug.nil? ? false : true
|
102
|
+
|
103
|
+
# The salesforce URL
|
104
|
+
config[:salesforce_url] =
|
105
|
+
ENV["SFDT_SALESFORCE_URL"] || # First from environment variables
|
106
|
+
config[:salesforce_url] || # Second from the configuration files
|
107
|
+
( config[:sandbox] == 'prod' ? 'https://login.salesforce.com' : 'https://test.salesforce.com' ) # If not defined anywhere, use defaults
|
108
|
+
|
109
|
+
# Initialize
|
110
|
+
sfdt = SalesforceDeployTool::App.new config
|
111
|
+
|
112
|
+
# Remove destructive change if there is one
|
113
|
+
destructive_change_file = File.join(full_src_dir,'destructiveChanges.xml')
|
114
|
+
FileUtils.rm destructive_change_file if File.exists? destructive_change_file
|
115
|
+
|
116
|
+
if ! options.append
|
117
|
+
# Pull changes from sandbox to temporary directory:
|
118
|
+
config_tmp = config.clone
|
119
|
+
config_tmp[:git_dir] = File.join(config[:tmp_dir],'repo_copy')
|
120
|
+
FileUtils.cp_r config[:git_dir],config_tmp[:git_dir]
|
121
|
+
sfdt_tmp = SalesforceDeployTool::App.new config_tmp
|
122
|
+
print "INFO: Pulling changes from #{config[:sandbox]} using url #{config[:salesforce_url]} to temporary directory to generate destructiveChanges.xml "
|
123
|
+
print( options.debug.nil? ? "" : "\n\n" )
|
124
|
+
sfdt_tmp.pull
|
125
|
+
|
126
|
+
# Create destructiveChanges.xml
|
127
|
+
puts "INFO: Creating destructive changes xml"
|
128
|
+
dc_gen = Dcgen::App.new
|
129
|
+
dc_gen.master = full_src_dir
|
130
|
+
dc_gen.destination = File.join(config_tmp[:git_dir],config_tmp[:src_dir])
|
131
|
+
dc_gen.output = destructive_change_file
|
132
|
+
dc_gen.exclude = options.exclude.split(',') unless options.exclude.nil?
|
133
|
+
dc_gen.verbose = false if not options.debug
|
134
|
+
dc_gen.generate_destructive_changes
|
135
|
+
|
136
|
+
end
|
137
|
+
|
138
|
+
# Push code to sandbox
|
139
|
+
begin
|
140
|
+
# Set version
|
141
|
+
sfdt.build_number = options.build_number if not options.build_number.nil?
|
142
|
+
sfdt.set_version
|
143
|
+
|
144
|
+
# Enable test if option enabled
|
145
|
+
sfdt.run_all_tests = options.run_all_tests.nil? ? false : true
|
146
|
+
sfdt.run_tests = options.run_tests.split(',') unless options.run_tests.nil?
|
147
|
+
|
148
|
+
# Push
|
149
|
+
print( options.run_all_tests.nil? && options.run_tests.nil? ? "INFO: Deploying code to #{config[:sandbox]}: ": "INFO: Deploying and Testing code to #{config[:sandbox]}: " )
|
150
|
+
print( options.debug.nil? ? "" : "\n\n" )
|
151
|
+
sfdt.push
|
152
|
+
ensure
|
153
|
+
sfdt.clean_version
|
154
|
+
end
|
155
|
+
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
command :sandbox do |c|
|
160
|
+
c.syntax = 'sf sandbox SANDBOX_NAME'
|
161
|
+
c.summary = 'Set sandbox to work on, this can be overriden by --sandbox '
|
162
|
+
c.description = 'Set the sandbox to work with pull and push. If no parameter defined, it will print the current sandbox selected.'
|
163
|
+
c.action do |args, options|
|
164
|
+
|
165
|
+
if args.size > 1
|
166
|
+
puts "error: Wrong number of arguments"
|
167
|
+
end
|
168
|
+
|
169
|
+
if args.size == 0
|
170
|
+
if ! config[:sandbox].nil?
|
171
|
+
puts "sandbox: " + config[:sandbox]
|
172
|
+
exit 0
|
173
|
+
else
|
174
|
+
puts "WARN: Sandbox has not been set yet"
|
175
|
+
exit 1
|
176
|
+
end
|
177
|
+
end
|
178
|
+
File.open(File.expand_path(SANDBOX_CONFIG_FILE),'w').write args.first
|
179
|
+
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
command :config do |c|
|
184
|
+
c.syntax = 'sf config'
|
185
|
+
c.summary = 'Go through the configuration wizard to config your environment'
|
186
|
+
c.action do |args, options|
|
187
|
+
|
188
|
+
if args.size != 0
|
189
|
+
puts "error: Wrong number of arguments"
|
190
|
+
end
|
191
|
+
|
192
|
+
config_new = {}
|
193
|
+
|
194
|
+
config_new[:username] = ask "Please enter your SalesForce production login user name" do |q|
|
195
|
+
q.validate = /^\S+@\S+$/
|
196
|
+
end.to_s
|
197
|
+
|
198
|
+
config_new[:password] = ask "Please enter your Salesforce production password" do |q|
|
199
|
+
q.echo = "x"
|
200
|
+
end.to_s
|
201
|
+
|
202
|
+
git_name = ask "Please enter your Full name to be used as commit owner on GIT" do |q|
|
203
|
+
q.validate = /^[a-zA-Z\s]+$/
|
204
|
+
end
|
205
|
+
|
206
|
+
git_email = ask "Please enter your email to be used as commit email on GIT" do |q|
|
207
|
+
q.validate = /^\S+@\S+$/
|
208
|
+
end
|
209
|
+
|
210
|
+
config[:sandbox] = ask "Please enter your sandbox so to be used as default when push and pull" do |q|
|
211
|
+
q.validate = /^[a-zA-Z]+$/
|
212
|
+
end
|
213
|
+
|
214
|
+
%x[git config --global user.email "#{git_email}"]
|
215
|
+
%x[git config --global user.name "#{git_name}"]
|
216
|
+
|
217
|
+
config[:username] = config_new[:username]
|
218
|
+
config[:password] = config_new[:password]
|
219
|
+
|
220
|
+
File.open(File.expand_path(SANDBOX_CONFIG_FILE),'w').write config[:sandbox]
|
221
|
+
File.open(File.expand_path(CONFIG_FILE),'w').write config_new.to_yaml
|
222
|
+
|
223
|
+
# Initialize
|
224
|
+
sfdt = SalesforceDeployTool::App.new config
|
225
|
+
|
226
|
+
# Clone
|
227
|
+
sfdt.clone
|
228
|
+
|
229
|
+
end
|
230
|
+
end
|
231
|
+
|
232
|
+
default_command :help
|
233
|
+
|
234
|
+
run!
|
235
|
+
|
236
|
+
end
|
237
|
+
|
238
|
+
end
|
239
|
+
|
240
|
+
end
|
241
|
+
|
242
|
+
|
data/lib/salesforcedeploytool.rb
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
require "rubygems"
|
2
|
+
require "commander"
|
3
|
+
require 'pp'
|
4
|
+
require 'yaml'
|
5
|
+
require 'fileutils'
|
6
|
+
require 'tmpdir'
|
2
7
|
require "pathname"
|
3
|
-
require "commander/import"
|
4
8
|
require "git"
|
5
9
|
require "pp"
|
6
10
|
require "colorize"
|
@@ -13,4 +17,5 @@ require "stringio"
|
|
13
17
|
require "salesforcedeploytool/version"
|
14
18
|
require "salesforcedeploytool/functions"
|
15
19
|
require "salesforcedeploytool/app"
|
16
|
-
|
20
|
+
require "salesforcedeploytool/cli"
|
21
|
+
require "erb"
|
data/tpl/build.xml.erb
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
<project name="Sample usage of Salesforce Ant tasks" default="test" basedir="." xmlns:sf="antlib:com.salesforce">
|
2
|
+
|
3
|
+
<property environment="env"/>
|
4
|
+
|
5
|
+
<taskdef resource="com/salesforce/antlib.xml" uri="antlib:com.salesforce">
|
6
|
+
<classpath>
|
7
|
+
<pathelement location="../ant-salesforce.jar" />
|
8
|
+
</classpath>
|
9
|
+
</taskdef>
|
10
|
+
|
11
|
+
<target name="deployCode">
|
12
|
+
<sf:deploy
|
13
|
+
username="${env.SF_USERNAME}"
|
14
|
+
password="${env.SF_PASSWORD}"
|
15
|
+
serverurl="${env.SF_SERVERURL}"
|
16
|
+
deployRoot="${env.SF_SRC_DIR}"
|
17
|
+
maxPoll="200"
|
18
|
+
rollbackOnError="true" >
|
19
|
+
</sf:deploy>
|
20
|
+
</target>
|
21
|
+
|
22
|
+
<target name="deployAndTestCode">
|
23
|
+
<sf:deploy
|
24
|
+
username="${env.SF_USERNAME}"
|
25
|
+
password="${env.SF_PASSWORD}"
|
26
|
+
serverurl="${env.SF_SERVERURL}"
|
27
|
+
deployRoot="${env.SF_SRC_DIR}"
|
28
|
+
maxPoll="200"
|
29
|
+
rollbackOnError="true" >
|
30
|
+
<% @run_tests.each do |test| -%>
|
31
|
+
<runTest><%= test %></runTest>
|
32
|
+
<% end -%>
|
33
|
+
</sf:deploy>
|
34
|
+
</target>
|
35
|
+
|
36
|
+
<target name="deployAndTestAllCode">
|
37
|
+
<sf:deploy
|
38
|
+
username="${env.SF_USERNAME}"
|
39
|
+
password="${env.SF_PASSWORD}"
|
40
|
+
serverurl="${env.SF_SERVERURL}"
|
41
|
+
deployRoot="${env.SF_SRC_DIR}"
|
42
|
+
maxPoll="200"
|
43
|
+
runAllTests="true"
|
44
|
+
rollbackOnError="true" >
|
45
|
+
</sf:deploy>
|
46
|
+
</target>
|
47
|
+
|
48
|
+
<target name="retrieveCode">
|
49
|
+
<sf:retrieve
|
50
|
+
username="${env.SF_USERNAME}"
|
51
|
+
password="${env.SF_PASSWORD}"
|
52
|
+
serverurl="${env.SF_SERVERURL}"
|
53
|
+
retrieveTarget="${env.SF_SRC_DIR}"
|
54
|
+
maxPoll="200"
|
55
|
+
unpackaged="${env.SF_SRC_DIR}/package.xml"
|
56
|
+
/>
|
57
|
+
</target>
|
58
|
+
|
59
|
+
</project>
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: salesforce-deploy-tool
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Juan Breinlinger
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-03-
|
11
|
+
date: 2015-03-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -150,6 +150,7 @@ files:
|
|
150
150
|
- README.md
|
151
151
|
- Rakefile
|
152
152
|
- bin/sf
|
153
|
+
- cucumber-config.yaml-tpl
|
153
154
|
- features/config.feature
|
154
155
|
- features/misc.feature
|
155
156
|
- features/pull.feature
|
@@ -158,9 +159,11 @@ files:
|
|
158
159
|
- features/support/hooks.rb
|
159
160
|
- lib/salesforcedeploytool.rb
|
160
161
|
- lib/salesforcedeploytool/app.rb
|
162
|
+
- lib/salesforcedeploytool/cli.rb
|
161
163
|
- lib/salesforcedeploytool/functions.rb
|
162
164
|
- lib/salesforcedeploytool/version.rb
|
163
165
|
- salesforce-deploy-tool.gemspec
|
166
|
+
- tpl/build.xml.erb
|
164
167
|
homepage: ''
|
165
168
|
licenses:
|
166
169
|
- MIT
|