travis_github_deployer 0.2.1 → 0.2.2
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.
- data/bin/travis_github_deployer +3 -1
- data/lib/travis_github_deployer/git_command_line.rb +21 -2
- data/lib/travis_github_deployer/travis_github_deployer.rb +26 -7
- data/lib/travis_github_deployer/version.rb +1 -1
- data/spec/git_command_line_spec.rb +18 -10
- data/spec/travis_github_deployer_spec.rb +25 -11
- metadata +2 -2
data/bin/travis_github_deployer
CHANGED
@@ -34,10 +34,29 @@ class GitCommandLine
|
|
34
34
|
config("credential.helper", "store --file=#{filename}")
|
35
35
|
end
|
36
36
|
|
37
|
+
def verbose=(value)
|
38
|
+
@verbose = true
|
39
|
+
end
|
40
|
+
|
41
|
+
def verbose
|
42
|
+
@verbose
|
43
|
+
end
|
44
|
+
|
37
45
|
def git(command)
|
38
|
-
|
39
|
-
|
46
|
+
git_command = "git #{command}"
|
47
|
+
puts("command: #{git_command}") if verbose
|
48
|
+
output = do_system("#{git_command} 2>&1")
|
49
|
+
puts("output: #{output}") if verbose
|
50
|
+
raise StandardError, "Git command: '#{command}' failed. Message: : " + output unless previous_command_success
|
40
51
|
output
|
41
52
|
end
|
42
53
|
|
54
|
+
def do_system(command)
|
55
|
+
`#{command}`
|
56
|
+
end
|
57
|
+
|
58
|
+
def previous_command_success
|
59
|
+
$?.success?
|
60
|
+
end
|
61
|
+
|
43
62
|
end
|
@@ -20,6 +20,19 @@ class TravisGithubDeployer
|
|
20
20
|
@destination_repository_dir ||= "travis_github_deployer_repository"
|
21
21
|
end
|
22
22
|
|
23
|
+
def git
|
24
|
+
@git
|
25
|
+
end
|
26
|
+
|
27
|
+
def verbose
|
28
|
+
@verbose ||= false
|
29
|
+
end
|
30
|
+
|
31
|
+
def verbose=(value)
|
32
|
+
git.verbose = value
|
33
|
+
@verbose = value
|
34
|
+
end
|
35
|
+
|
23
36
|
def files_to_deploy
|
24
37
|
@files_to_deploy
|
25
38
|
end
|
@@ -47,9 +60,15 @@ class TravisGithubDeployer
|
|
47
60
|
@destination_repository = configuration["destination_repository"]
|
48
61
|
@files_to_deploy = configuration["files_to_deploy"]
|
49
62
|
end
|
63
|
+
|
64
|
+
def command_line_arguments(arguments)
|
65
|
+
if (arguments[0] == "-v")
|
66
|
+
self.verbose = true
|
67
|
+
end
|
68
|
+
end
|
50
69
|
|
51
70
|
def clone_destination_repository
|
52
|
-
|
71
|
+
git.clone(destination_repository, destination_repository_dir)
|
53
72
|
end
|
54
73
|
|
55
74
|
def change_current_directory_to_cloned_repository
|
@@ -64,18 +83,18 @@ class TravisGithubDeployer
|
|
64
83
|
|
65
84
|
def set_repository_token_based_on_enviroment_variable
|
66
85
|
git_token = environment_variable_value("GIT_TOKEN")
|
67
|
-
|
86
|
+
git.config_credential_helper_store_file(".git/travis_deploy_credentials")
|
68
87
|
File.open(".git/travis_deploy_credentials", "w") { |credential_file|
|
69
88
|
credential_file.write("https://#{git_token}:@github.com")
|
70
89
|
}
|
71
90
|
end
|
72
91
|
|
73
92
|
def set_username_based_on_environment_variable
|
74
|
-
|
93
|
+
git.config_username(environment_variable_value("GIT_NAME"))
|
75
94
|
end
|
76
95
|
|
77
96
|
def set_email_based_on_environment_variable
|
78
|
-
|
97
|
+
git.config_email(environment_variable_value("GIT_EMAIL"))
|
79
98
|
end
|
80
99
|
|
81
100
|
def environment_variable_value (environment_variable_name)
|
@@ -97,10 +116,10 @@ class TravisGithubDeployer
|
|
97
116
|
|
98
117
|
def commit_and_push_files
|
99
118
|
files_to_deploy.each { |source_location, destination_location|
|
100
|
-
|
119
|
+
git.add(Pathname.new(destination_location))
|
101
120
|
}
|
102
|
-
|
103
|
-
|
121
|
+
git.commit("File deployed with Travis Github Deployer")
|
122
|
+
git.push
|
104
123
|
end
|
105
124
|
|
106
125
|
end
|
@@ -45,17 +45,25 @@ describe "simple ruby interface around git command line" do
|
|
45
45
|
subject.config_credential_helper_store_file("filename")
|
46
46
|
end
|
47
47
|
|
48
|
+
it "can do verbose output" do
|
49
|
+
subject.verbose=true
|
50
|
+
subject.should_receive(:puts).with("command: git something")
|
51
|
+
subject.should_receive(:do_system).with("git something 2>&1").and_return("output")
|
52
|
+
subject.should_receive(:previous_command_success).and_return(true)
|
53
|
+
subject.should_receive(:puts).with("output: output")
|
54
|
+
subject.git("something")
|
55
|
+
end
|
56
|
+
|
57
|
+
|
58
|
+
it "Should be able to do a successful command" do
|
59
|
+
subject.should_not_receive(:puts)
|
60
|
+
subject.git('version').should start_with("git version")
|
61
|
+
end
|
48
62
|
|
49
|
-
|
50
|
-
|
51
|
-
subject.git('
|
52
|
-
|
53
|
-
|
54
|
-
it "Should be able to raise an StandardError on failed commands" do
|
55
|
-
expect {
|
56
|
-
subject.git('error')
|
57
|
-
}.to raise_error(StandardError, "Git command: 'error' failed. Message: : git: 'error' is not a git command. See 'git --help'.\n\nDid you mean this?\n rerere\n")
|
58
|
-
end
|
63
|
+
it "Should be able to raise an StandardError on failed commands" do
|
64
|
+
expect {
|
65
|
+
subject.git('error')
|
66
|
+
}.to raise_error(StandardError, "Git command: 'error' failed. Message: : git: 'error' is not a git command. See 'git --help'.\n\nDid you mean this?\n rerere\n")
|
59
67
|
end
|
60
68
|
|
61
69
|
|
@@ -110,20 +110,34 @@ describe "travis github deployer" do
|
|
110
110
|
end
|
111
111
|
end
|
112
112
|
|
113
|
-
|
114
|
-
configuration
|
115
|
-
|
116
|
-
|
117
|
-
"
|
113
|
+
context "configuration" do
|
114
|
+
it "can read configuration parameters out of the .travis_github_deployer.yml" do
|
115
|
+
configuration = {
|
116
|
+
"destination_repository" => "https://github.com/cpputest/cpputest.github.io.git",
|
117
|
+
"files_to_deploy" => {
|
118
|
+
"source_dir/source_file" => "destination_dir/destination_file"
|
119
|
+
}
|
118
120
|
}
|
119
|
-
}
|
120
121
|
|
121
|
-
|
122
|
-
|
122
|
+
YAML.should_receive(:load_file).with(".travis_github_deployer.yml").and_return(configuration)
|
123
|
+
subject.load_configuration
|
123
124
|
|
124
|
-
|
125
|
-
|
125
|
+
subject.destination_repository.should== "https://github.com/cpputest/cpputest.github.io.git"
|
126
|
+
subject.files_to_deploy.should== { "source_dir/source_file" => "destination_dir/destination_file" }
|
126
127
|
|
127
|
-
|
128
|
+
end
|
129
|
+
|
130
|
+
it "isn't verbose by default" do
|
131
|
+
subject.command_line_arguments([""])
|
132
|
+
subject.verbose.should == false
|
133
|
+
end
|
128
134
|
|
135
|
+
it "can be made verbose using the -v" do
|
136
|
+
@git.should_receive(:verbose=).with(true)
|
137
|
+
|
138
|
+
subject.command_line_arguments(["-v"])
|
139
|
+
|
140
|
+
subject.verbose.should== true
|
141
|
+
end
|
142
|
+
end
|
129
143
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: travis_github_deployer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.2.
|
5
|
+
version: 0.2.2
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Bas Vodde
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2013-07-
|
13
|
+
date: 2013-07-16 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rake
|