dandelion 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/dandelion.rb +22 -17
- data/lib/dandelion/deployment.rb +10 -11
- data/lib/dandelion/git.rb +9 -0
- data/lib/dandelion/service.rb +16 -5
- data/lib/dandelion/version.rb +1 -1
- metadata +3 -3
data/lib/dandelion.rb
CHANGED
@@ -33,24 +33,29 @@ module Dandelion
|
|
33
33
|
puts "Connecting to: #{service.uri}"
|
34
34
|
|
35
35
|
begin
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
36
|
+
begin
|
37
|
+
# Deploy changes since remote revision
|
38
|
+
deployment = Deployment::DiffDeployment.new('.', service, config['exclude'])
|
39
|
+
|
40
|
+
puts "Remote revision: #{deployment.remote_revision}"
|
41
|
+
puts "Local revision: #{deployment.local_revision}"
|
42
|
+
|
43
|
+
deployment.deploy
|
44
|
+
rescue Service::RemoteRevisionError
|
45
|
+
# No remote revision, deploy everything
|
46
|
+
deployment = Deployment::FullDeployment.new('.', service, config['exclude'])
|
47
|
+
|
48
|
+
puts "Remote revision: ---"
|
49
|
+
puts "Local revision: #{deployment.local_revision}"
|
50
|
+
|
51
|
+
deployment.deploy
|
52
|
+
end
|
53
|
+
|
54
|
+
puts "Deployment complete"
|
55
|
+
rescue Git::DiffError
|
56
|
+
puts "Failed to deploy"
|
57
|
+
puts "Try merging remote changes before deploying again"
|
51
58
|
end
|
52
|
-
|
53
|
-
puts "Deployment complete"
|
54
59
|
end
|
55
60
|
end
|
56
61
|
end
|
data/lib/dandelion/deployment.rb
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
require 'dandelion/git'
|
2
2
|
|
3
3
|
module Deployment
|
4
|
-
class RemoteRevisionError < StandardError; end
|
5
|
-
|
6
4
|
class Deployment
|
7
5
|
def initialize(dir, service, exclude = nil, revision = 'HEAD')
|
8
6
|
@service = service
|
@@ -21,6 +19,12 @@ module Deployment
|
|
21
19
|
def write_revision
|
22
20
|
@service.write('.revision', local_revision)
|
23
21
|
end
|
22
|
+
|
23
|
+
protected
|
24
|
+
|
25
|
+
def exclude_file?(file)
|
26
|
+
return @exclude.map { |e| file.start_with?(e) }.any?
|
27
|
+
end
|
24
28
|
end
|
25
29
|
|
26
30
|
class DiffDeployment < Deployment
|
@@ -47,7 +51,7 @@ module Deployment
|
|
47
51
|
|
48
52
|
def deploy_changed
|
49
53
|
@diff.changed.each do |file|
|
50
|
-
if
|
54
|
+
if exclude_file?(file)
|
51
55
|
puts "Skipping file: #{file}"
|
52
56
|
else
|
53
57
|
puts "Uploading file: #{file}"
|
@@ -58,7 +62,7 @@ module Deployment
|
|
58
62
|
|
59
63
|
def deploy_deleted
|
60
64
|
@diff.deleted.each do |file|
|
61
|
-
if
|
65
|
+
if exclude_file?(file)
|
62
66
|
puts "Skipping file: #{file}"
|
63
67
|
else
|
64
68
|
puts "Deleting file: #{file}"
|
@@ -78,19 +82,14 @@ module Deployment
|
|
78
82
|
private
|
79
83
|
|
80
84
|
def read_revision
|
81
|
-
|
82
|
-
@service.read('.revision').chomp
|
83
|
-
rescue Net::SFTP::StatusException => e
|
84
|
-
raise unless e.code == 2
|
85
|
-
raise RemoteRevisionError
|
86
|
-
end
|
85
|
+
@service.read('.revision').chomp
|
87
86
|
end
|
88
87
|
end
|
89
88
|
|
90
89
|
class FullDeployment < Deployment
|
91
90
|
def deploy
|
92
91
|
@tree.files.each do |file|
|
93
|
-
unless
|
92
|
+
unless exclude_file?(file)
|
94
93
|
puts "Uploading file: #{file}"
|
95
94
|
@service.write(file, @tree.show(file))
|
96
95
|
end
|
data/lib/dandelion/git.rb
CHANGED
@@ -1,12 +1,15 @@
|
|
1
1
|
require 'grit'
|
2
2
|
|
3
3
|
module Git
|
4
|
+
class DiffError < StandardError; end
|
5
|
+
|
4
6
|
class Diff
|
5
7
|
attr_reader :revision
|
6
8
|
|
7
9
|
def initialize(dir, revision)
|
8
10
|
@revision = revision
|
9
11
|
@raw = `cd #{dir}; git diff --name-status #{@revision} HEAD`
|
12
|
+
check_state!
|
10
13
|
end
|
11
14
|
|
12
15
|
def changed
|
@@ -27,6 +30,12 @@ module Git
|
|
27
30
|
end
|
28
31
|
items
|
29
32
|
end
|
33
|
+
|
34
|
+
def check_state!
|
35
|
+
if $?.exitstatus != 0
|
36
|
+
raise DiffError
|
37
|
+
end
|
38
|
+
end
|
30
39
|
end
|
31
40
|
|
32
41
|
class Tree
|
data/lib/dandelion/service.rb
CHANGED
@@ -2,6 +2,8 @@ require 'net/sftp'
|
|
2
2
|
require 'tempfile'
|
3
3
|
|
4
4
|
module Service
|
5
|
+
class RemoteRevisionError < StandardError; end
|
6
|
+
|
5
7
|
class Service
|
6
8
|
def initialize(host, username, path)
|
7
9
|
@host = host
|
@@ -22,8 +24,13 @@ module Service
|
|
22
24
|
end
|
23
25
|
|
24
26
|
def read(file)
|
25
|
-
|
26
|
-
f
|
27
|
+
begin
|
28
|
+
@sftp.file.open(File.join(@path, file), 'r') do |f|
|
29
|
+
f.gets
|
30
|
+
end
|
31
|
+
rescue Net::SFTP::StatusException => e
|
32
|
+
raise unless e.code == 2
|
33
|
+
raise RemoteRevisionError
|
27
34
|
end
|
28
35
|
end
|
29
36
|
|
@@ -44,9 +51,13 @@ module Service
|
|
44
51
|
end
|
45
52
|
|
46
53
|
def delete(file)
|
47
|
-
|
48
|
-
|
49
|
-
|
54
|
+
begin
|
55
|
+
path = File.join(@path, file)
|
56
|
+
@sftp.remove!(path)
|
57
|
+
cleanup(File.dirname(path))
|
58
|
+
rescue Net::SFTP::StatusException => e
|
59
|
+
raise unless e.code == 2
|
60
|
+
end
|
50
61
|
end
|
51
62
|
|
52
63
|
private
|
data/lib/dandelion/version.rb
CHANGED
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: dandelion
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.1.
|
5
|
+
version: 0.1.4
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Scott Nelson
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-
|
13
|
+
date: 2011-03-10 00:00:00 -05:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -83,6 +83,6 @@ rubyforge_project:
|
|
83
83
|
rubygems_version: 1.5.0
|
84
84
|
signing_key:
|
85
85
|
specification_version: 3
|
86
|
-
summary: dandelion-0.1.
|
86
|
+
summary: dandelion-0.1.4
|
87
87
|
test_files: []
|
88
88
|
|