travis_github_deployer 0.2.4 → 0.2.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a8f20a4c4ce37d11b2ef8b7424c5beb0640f9b10
4
- data.tar.gz: 9edd37bab8fa9a5ac853a806c18f6794b4927329
3
+ metadata.gz: e11bde28a88d34baf6233595fe490f13518dbd19
4
+ data.tar.gz: ef12a9b9f9312191fa0865437dec087ac2fd6318
5
5
  SHA512:
6
- metadata.gz: 4f74213d9dcda4b693b10abaa637a272e90566fc23616d91b383c777151062237d69a23b343535192862613d48673339677296296ab771025ff9ff9fd1b23aee
7
- data.tar.gz: cc29b250a8817db828b3686e63d794b34e1b0907ce32c2e0fb00e3da463fa7a9f44ce8a6df2f390ab4c16316dcfe806c63544a1c5fcd8701fa82e0c60f77059a
6
+ metadata.gz: 7ddff0780fbf8549584f7be3d198ace186182ecc062867a32c790b357acb055de188bfaca94249b1782a9de98c5f10449690361f686267f80b90509c520a245a
7
+ data.tar.gz: dbd98689fc07858fb02284d9408c519992b2d7122f26d85e467b26985a22bf0d7cded83f4be44426fd4bc2b8129829927d7b1fcdda83a0d7681c985074245e71
@@ -18,6 +18,17 @@ class GitCommandLine
18
18
  git("commit -m \"#{message}\"")
19
19
  end
20
20
 
21
+ def filter_branch(patterns)
22
+ git("filter-branch --force --index-filter " +
23
+ "'git rm --cached --ignore-unmatch #{patterns}' " +
24
+ "--prune-empty --tag-name-filter cat -- --all"
25
+ )
26
+ end
27
+
28
+ def force_push
29
+ git("push -f")
30
+ end
31
+
21
32
  def push
22
33
  git("push")
23
34
  end
@@ -37,6 +37,10 @@ class TravisGithubDeployer
37
37
  @files_to_deploy ||= {}
38
38
  end
39
39
 
40
+ def files_to_purge
41
+ @files_to_purge ||= []
42
+ end
43
+
40
44
  ## Deployment
41
45
 
42
46
  def deploy
@@ -55,6 +59,7 @@ class TravisGithubDeployer
55
59
  copy_files_in_destination_repository
56
60
  change_current_directory_to_cloned_repository
57
61
  prepare_credentials_based_on_environment_variables
62
+ purge_files_from_history if not files_to_purge.empty?
58
63
  commit_and_push_files
59
64
  end
60
65
 
@@ -66,15 +71,24 @@ class TravisGithubDeployer
66
71
  prepare_files_to_deploy(configuration["files_to_deploy"])
67
72
  end
68
73
 
74
+ def get_destination_and_add_file_to_purge source, target_or_hash
75
+ if target_or_hash.instance_of?(Hash)
76
+ files_to_purge << source if (target_or_hash["purge"] == "yes")
77
+ destination_file = target_or_hash["destination"]
78
+ else
79
+ destination_file = target_or_hash
80
+ end
81
+ end
82
+
69
83
  def prepare_files_to_deploy files_hash
70
- files_hash.each { |source_file_from_configuration, destination_file|
71
-
72
- source_files = Dir.glob(source_file_from_configuration)
84
+ files_hash.each { |source, values|
73
85
 
86
+ source_files = Dir.glob(source)
74
87
  if source_files.empty?
75
- raise StandardError.new("File: '#{source_file_from_configuration}' found in the configuration didn't exist. Deploy failed.")
88
+ raise StandardError.new("File: '#{source}' found in the configuration didn't exist. Deploy failed.")
76
89
  end
77
90
 
91
+ destination_file = get_destination_and_add_file_to_purge(source, values)
78
92
  source_files.each { |source_file|
79
93
  files_to_deploy[source_file] = destination_file
80
94
  }
@@ -134,11 +148,19 @@ class TravisGithubDeployer
134
148
 
135
149
  end
136
150
 
151
+ def purge_files_from_history
152
+ git.filter_branch(files_to_purge.join(" "))
153
+ end
154
+
137
155
  def commit_and_push_files
138
156
  files_to_deploy.each { |source_location, destination_location|
139
157
  git.add(Pathname.new(destination_location))
140
158
  }
141
159
  git.commit("File deployed with Travis Github Deployer")
142
- git.push
160
+ if(files_to_purge.empty?)
161
+ git.push
162
+ else
163
+ git.force_push
164
+ end
143
165
  end
144
166
  end
@@ -1,4 +1,4 @@
1
1
 
2
2
  module TravisGithubDeployerVersion
3
- VERSION = "0.2.4"
3
+ VERSION = "0.2.5"
4
4
  end
@@ -6,57 +6,71 @@ describe "simple ruby interface around git command line" do
6
6
  subject { GitCommandLine.new}
7
7
 
8
8
  it "can do a git clone" do
9
- subject.should_receive(:git).with("clone repository destination")
9
+ expect(subject).to receive(:git).with("clone repository destination")
10
10
  subject.clone("repository", "destination")
11
11
  end
12
12
 
13
13
  it "can add files" do
14
- subject.should_receive(:git).with("add filename")
14
+ expect(subject).to receive(:git).with("add filename")
15
15
  subject.add("filename")
16
16
  end
17
17
 
18
18
  it "can commit" do
19
- subject.should_receive(:git).with('commit -m "message"')
19
+ expect(subject).to receive(:git).with('commit -m "message"')
20
20
  subject.commit("message")
21
21
  end
22
22
 
23
+ it "can purge files from history" do
24
+ expect(subject).to receive(:git).with(
25
+ "filter-branch --force --index-filter " +
26
+ "'git rm --cached --ignore-unmatch file1 file2' " +
27
+ "--prune-empty --tag-name-filter cat -- --all"
28
+ )
29
+ subject.filter_branch("file1 file2")
30
+ end
31
+
23
32
  it "can push" do
24
- subject.should_receive(:git).with("push")
33
+ expect(subject).to receive(:git).with("push")
25
34
  subject.push
26
35
  end
27
36
 
37
+ it "can force-push" do
38
+ expect(subject).to receive(:git).with("push -f")
39
+ subject.force_push
40
+ end
41
+
28
42
  it "can do a config" do
29
- subject.should_receive(:git).with("config key 'value'")
43
+ expect(subject).to receive(:git).with("config key 'value'")
30
44
  subject.config("key", "value")
31
45
  end
32
46
 
33
47
  it "can configure the username" do
34
- subject.should_receive(:config).with("user.name", "basvodde")
48
+ expect(subject).to receive(:config).with("user.name", "basvodde")
35
49
  subject.config_username("basvodde")
36
50
  end
37
51
 
38
52
  it "can configure the email" do
39
- subject.should_receive(:config).with("user.email", "basv@sokewl.com")
53
+ expect(subject).to receive(:config).with("user.email", "basv@sokewl.com")
40
54
  subject.config_email("basv@sokewl.com")
41
55
  end
42
56
 
43
57
  it "can configure the credential helper" do
44
- subject.should_receive(:config).with("credential.helper", "store --file=filename")
58
+ expect(subject).to receive(:config).with("credential.helper", "store --file=filename")
45
59
  subject.config_credential_helper_store_file("filename")
46
60
  end
47
61
 
48
62
  it "can do verbose output" do
49
63
  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")
64
+ expect(subject).to receive(:puts).with("command: git something")
65
+ expect(subject).to receive(:do_system).with("git something 2>&1").and_return("output")
66
+ expect(subject).to receive(:previous_command_success).and_return(true)
67
+ expect(subject).to receive(:puts).with("output: output")
54
68
  subject.git("something")
55
69
  end
56
70
 
57
71
  it "Should be able to do a successful command" do
58
- subject.should_not_receive(:puts)
59
- subject.git('version').should start_with("git version")
72
+ expect(subject).not_to receive(:puts)
73
+ expect(subject.git('version')).to start_with("git version")
60
74
  end
61
75
 
62
76
  it "Should be able to raise an StandardError on failed commands" do
@@ -8,68 +8,68 @@ describe "travis github deployer" do
8
8
  before(:each) do
9
9
  ENV::clear
10
10
  @git = double
11
- GitCommandLine.should_receive(:new).and_return(@git)
11
+ expect(GitCommandLine).to receive(:new).and_return(@git)
12
12
  subject
13
13
  end
14
14
 
15
15
  it "can deploy to an destination repository" do
16
16
  ENV['TRAVIS_PULL_REQUEST']="false"
17
17
  ENV['GIT_NAME']="Foo"
18
- subject.should_receive(:load_configuration)
19
- subject.should_receive(:clone_destination_repository)
20
- subject.should_receive(:change_current_directory_to_cloned_repository)
21
- subject.should_receive(:prepare_credentials_based_on_environment_variables)
22
- subject.should_receive(:copy_files_in_destination_repository)
23
- subject.should_receive(:commit_and_push_files)
18
+ expect(subject).to receive(:load_configuration)
19
+ expect(subject).to receive(:clone_destination_repository)
20
+ expect(subject).to receive(:change_current_directory_to_cloned_repository)
21
+ expect(subject).to receive(:prepare_credentials_based_on_environment_variables)
22
+ expect(subject).to receive(:copy_files_in_destination_repository)
23
+ expect(subject).to receive(:commit_and_push_files)
24
24
  subject.deploy
25
25
  end
26
26
 
27
27
  it "will not deploy on a pull request" do
28
28
  ENV['TRAVIS_PULL_REQUEST']="10"
29
- subject.should_not_receive(:load_configuration)
30
- subject.should_receive(:puts).with("In pull request and won't be deploying")
29
+ expect(subject).not_to receive(:load_configuration)
30
+ expect(subject).to receive(:puts).with("In pull request and won't be deploying")
31
31
  subject.deploy
32
32
  end
33
33
 
34
34
  it "will not deploy when run in a fork, e.g. when GIT_NAME isn't set" do
35
35
  ENV['TRAVIS_PULL_REQUEST']="false"
36
- subject.should_not_receive(:load_configuration)
37
- subject.should_receive(:puts).with("In fork and won't be deploying")
36
+ expect(subject).not_to receive(:load_configuration)
37
+ expect(subject).to receive(:puts).with("In fork and won't be deploying")
38
38
  subject.deploy
39
39
  end
40
40
 
41
41
  context "Prepare repository for being able to commit" do
42
42
 
43
43
  it "can clone the destination repository" do
44
- subject.should_receive(:destination_repository).and_return("https://github.com/cpputest/cpputest")
45
- subject.should_receive(:destination_repository_dir).and_return("destdir")
46
- @git.should_receive(:clone).with("https://github.com/cpputest/cpputest", "destdir")
44
+ expect(subject).to receive(:destination_repository).and_return("https://github.com/cpputest/cpputest")
45
+ expect(subject).to receive(:destination_repository_dir).and_return("destdir")
46
+ expect(@git).to receive(:clone).with("https://github.com/cpputest/cpputest", "destdir")
47
47
 
48
48
  subject.clone_destination_repository
49
49
  end
50
50
 
51
51
  it "can change the directory to the cloned directory" do
52
- subject.should_receive(:destination_repository_dir).and_return("destinationdir")
53
- Dir.should_receive(:chdir).with("destinationdir")
52
+ expect(subject).to receive(:destination_repository_dir).and_return("destinationdir")
53
+ expect(Dir).to receive(:chdir).with("destinationdir")
54
54
  subject.change_current_directory_to_cloned_repository
55
55
  end
56
56
 
57
57
  it "Should be able to set the credentials for pushing stuff up" do
58
- subject.should_receive(:set_username_based_on_environment_variable)
59
- subject.should_receive(:set_email_based_on_environment_variable)
60
- subject.should_receive(:set_repository_token_based_on_enviroment_variable)
58
+ expect(subject).to receive(:set_username_based_on_environment_variable)
59
+ expect(subject).to receive(:set_email_based_on_environment_variable)
60
+ expect(subject).to receive(:set_repository_token_based_on_enviroment_variable)
61
61
  subject.prepare_credentials_based_on_environment_variables
62
62
  end
63
63
 
64
64
  it "Should be able to set the username based on an environment variable" do
65
65
  ENV['GIT_NAME'] = "basvodde"
66
- @git.should_receive(:config_username).with("basvodde")
66
+ expect(@git).to receive(:config_username).with("basvodde")
67
67
  subject.set_username_based_on_environment_variable
68
68
  end
69
69
 
70
70
  it "Should be able to set the password based on an environment variable" do
71
71
  ENV['GIT_EMAIL'] = "basv@bestcompanythatexists.com"
72
- @git.should_receive(:config_email).with("basv@bestcompanythatexists.com")
72
+ expect(@git).to receive(:config_email).with("basv@bestcompanythatexists.com")
73
73
  subject.set_email_based_on_environment_variable
74
74
  end
75
75
 
@@ -77,9 +77,9 @@ describe "travis github deployer" do
77
77
  credential_file = double
78
78
  ENV['GIT_TOKEN'] = "Token"
79
79
 
80
- @git.should_receive(:config_credential_helper_store_file).with(".git/travis_deploy_credentials")
81
- File.should_receive(:open).with(".git/travis_deploy_credentials", "w").and_yield(credential_file)
82
- credential_file.should_receive(:write).with("https://Token:@github.com")
80
+ expect(@git).to receive(:config_credential_helper_store_file).with(".git/travis_deploy_credentials")
81
+ expect(File).to receive(:open).with(".git/travis_deploy_credentials", "w").and_yield(credential_file)
82
+ expect(credential_file).to receive(:write).with("https://Token:@github.com")
83
83
 
84
84
  subject.set_repository_token_based_on_enviroment_variable
85
85
  end
@@ -87,59 +87,91 @@ describe "travis github deployer" do
87
87
 
88
88
  context "Prepare the changes that need to be made commit" do
89
89
 
90
- it "should be able to copy a file from the root of the source repository to the root of the destination reportistory" do
91
- subject.should_receive(:files_to_deploy).and_return( { "sourcefile" => ""})
92
- FileUtils.should_receive(:cp_r).with(Pathname.new("sourcefile"), Pathname.new("travis_github_deployer_repository"))
90
+ it "should be able to copy a file from the root of the source repository to the root of the destination repository" do
91
+ expect(subject).to receive(:files_to_deploy).and_return( { "sourcefile" => ""})
92
+ expect(FileUtils).to receive(:cp_r).with(Pathname.new("sourcefile"), Pathname.new("travis_github_deployer_repository"))
93
93
  subject.copy_files_in_destination_repository
94
94
  end
95
95
 
96
96
  it "Should be able to copy multiple files" do
97
- subject.should_receive(:files_to_deploy).and_return({ "dir/onefile" => "destonefile", "twofile" => "dir/desttwofile"})
98
- FileUtils.should_receive(:cp_r).with(Pathname.new("dir/onefile"), Pathname.new("travis_github_deployer_repository/destonefile"))
99
- FileUtils.should_receive(:cp_r).with(Pathname.new("twofile"), Pathname.new("travis_github_deployer_repository/dir/desttwofile"))
97
+ expect(subject).to receive(:files_to_deploy).and_return({ "dir/onefile" => "destonefile", "twofile" => "dir/desttwofile"})
98
+ expect(FileUtils).to receive(:cp_r).with(Pathname.new("dir/onefile"), Pathname.new("travis_github_deployer_repository/destonefile"))
99
+ expect(FileUtils).to receive(:cp_r).with(Pathname.new("twofile"), Pathname.new("travis_github_deployer_repository/dir/desttwofile"))
100
100
  subject.copy_files_in_destination_repository
101
101
  end
102
102
  end
103
103
 
104
104
  context "Actually committing the files" do
105
105
 
106
+ it "can purge files from history and force-push" do
107
+ files = ["dir/onefile", "twofile"]
108
+ expect(subject).to receive(:files_to_purge).and_return(files, files)
109
+ allow(@git).to receive_messages(add: nil, commit: nil)
110
+ expect(@git).to receive(:filter_branch).with(files.join(" "))
111
+ expect(@git).to receive(:force_push)
112
+ subject.purge_files_from_history
113
+ subject.commit_and_push_files
114
+ end
115
+
106
116
  it "can add, commit and push up the files" do
107
- subject.should_receive(:files_to_deploy).and_return({ "dir/onefile" => "destonefile", "twofile" => "dir/desttwofile"})
108
- @git.should_receive(:add).with(Pathname.new("destonefile"))
109
- @git.should_receive(:add).with(Pathname.new("dir/desttwofile"))
110
- @git.should_receive(:commit).with("File deployed with Travis Github Deployer")
111
- @git.should_receive(:push)
117
+ expect(subject).to receive(:files_to_deploy).and_return({ "dir/onefile" => "destonefile", "twofile" => "dir/desttwofile"})
118
+ expect(@git).to receive(:add).with(Pathname.new("destonefile"))
119
+ expect(@git).to receive(:add).with(Pathname.new("dir/desttwofile"))
120
+ expect(@git).to receive(:commit).with("File deployed with Travis Github Deployer")
121
+ expect(@git).to receive(:push)
112
122
  subject.commit_and_push_files
113
123
  end
114
124
  end
115
125
 
116
126
  context "configuration" do
117
127
  it "can read configuration parameters out of the .travis_github_deployer.yml" do
128
+ files_to_deploy = { "source_dir/source_file" => "destination_dir/destination_file" }
118
129
  configuration = {
119
130
  "destination_repository" => "https://github.com/cpputest/cpputest.github.io.git",
120
- "files_to_deploy" => {
121
- "source_dir/source_file" => "destination_dir/destination_file"
122
- }
131
+ "files_to_deploy" => files_to_deploy
123
132
  }
124
133
 
125
- YAML.should_receive(:load_file).with(".travis_github_deployer.yml").and_return(configuration)
126
- subject.should_receive(:prepare_files_to_deploy).with({"source_dir/source_file" => "destination_dir/destination_file"})
134
+ expect(YAML).to receive(:load_file).with(".travis_github_deployer.yml").and_return(configuration)
135
+ expect(subject).to receive(:prepare_files_to_deploy).with(files_to_deploy)
127
136
  subject.load_configuration
128
137
 
129
- subject.destination_repository.should== "https://github.com/cpputest/cpputest.github.io.git"
138
+ expect(subject.destination_repository).to eq("https://github.com/cpputest/cpputest.github.io.git")
139
+
140
+ end
141
+
142
+ it "can parse destination with file to purge" do
143
+ source = "src_file"
144
+ target = {"destination"=>"dest", "purge"=>"yes"}
145
+ expect(subject.get_destination_and_add_file_to_purge(source, target)).to eq("dest")
146
+ expect(subject.files_to_purge).to eq(["src_file"])
147
+ end
148
+
149
+ it "can parse destination without file to purge" do
150
+ source = "src_file"
151
+ target = "dest"
152
+ expect(subject.get_destination_and_add_file_to_purge(source, target)).to eq("dest")
153
+ expect(subject.files_to_purge).to eq([])
154
+ end
130
155
 
156
+ it "can have sources to purge from history" do
157
+ files_to_purge = { "myfile" => { "destination" => "destination_dir", "purge" => "yes" } }
158
+ expect(Dir).to receive(:glob).with("myfile").and_return(["myfile"])
159
+
160
+ subject.prepare_files_to_deploy(files_to_purge)
161
+ expect(subject.files_to_deploy).to eq({ "myfile" => "destination_dir" })
162
+ expect(subject.files_to_purge).to eq([ "myfile" ])
131
163
  end
132
164
 
133
165
  it "can have files with wildcards in the configuration" do
134
166
  wild_card_files = { "source_dir/*" => "destination_dir" }
135
- Dir.should_receive(:glob).with("source_dir/*").and_return(["file1", "file2"])
167
+ expect(Dir).to receive(:glob).with("source_dir/*").and_return(["file1", "file2"])
136
168
 
137
169
  subject.prepare_files_to_deploy(wild_card_files)
138
- subject.files_to_deploy.should== { "file1" => "destination_dir", "file2" => "destination_dir" }
170
+ expect(subject.files_to_deploy).to eq({ "file1" => "destination_dir", "file2" => "destination_dir" })
139
171
  end
140
172
 
141
- it "raises an error when one of the source files doesn't exists" do
142
- Dir.should_receive(:glob).with("not_exists").and_return([])
173
+ it "raises an error when one of the source files doesn't exist" do
174
+ expect(Dir).to receive(:glob).with("not_exists").and_return([])
143
175
  expect {
144
176
  subject.prepare_files_to_deploy( { "not_exists" => "" })
145
177
  }.to raise_error(StandardError, "File: 'not_exists' found in the configuration didn't exist. Deploy failed.")
@@ -148,15 +180,15 @@ describe "travis github deployer" do
148
180
 
149
181
  it "isn't verbose by default" do
150
182
  subject.command_line_arguments([""])
151
- subject.verbose.should == false
183
+ expect(subject.verbose).to eq(false)
152
184
  end
153
185
 
154
186
  it "can be made verbose using the -v" do
155
- @git.should_receive(:verbose=).with(true)
187
+ expect(@git).to receive(:verbose=).with(true)
156
188
 
157
189
  subject.command_line_arguments(["-v"])
158
190
 
159
- subject.verbose.should== true
191
+ expect(subject.verbose).to eq(true)
160
192
  end
161
193
  end
162
194
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: travis_github_deployer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bas Vodde
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-01 00:00:00.000000000 Z
11
+ date: 2014-09-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake