travis-custom-deploy 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- Mzc1YWRhMjQ4MGUyNGY3Y2Y0OTllMzdhNjNmMTFiNjFkMTE4OGFlMA==
4
+ YTUxNjk3YmFiMmMwMzE3N2RmZmY3M2Q2OGFkZWRjNDc4ZmY4NTU3NQ==
5
5
  data.tar.gz: !binary |-
6
- NDFiZTRkNWI5ZjRjOGU4NTM4ZWY2MWEyNjEyYzMyYWMwODBkNzY1NQ==
6
+ ZGI0MGM2ZTRjY2ZkZTQyMzc3YzQwNjJhOTMyZjllZGJkZjgxZjNkZQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- NGZhZTAyOWM5MzIxYjkyODRlNWMzMTk3YTQwMDZjMmQ0N2JmMGQ3OTBkYWVj
10
- ZGQyNTU2YmQyYTJjMmY5OTYwNDAyOGZmNWU2ZTZlMmE2ZGQ0NWJmZjZmNTk0
11
- ZWUyM2RlYjM1M2U0NTIyZTMwODNlM2FkNjA5MjZhMGE4YzQ2YWQ=
9
+ Yzg5OWJmNmFjYmQyMjM0ZTQzYTUyNDhhN2ZhNGZlZGRjNWI1NjhkODBhMWJi
10
+ ZDI3NGVlNTdiNWExNjJjODUzZDE5YmZkNGM0NmIzOTEwZWM1OWVjOGU2YTM1
11
+ NmZmNjJkYWQwMGQxY2U5MWFiODIzYjhjZTFhZmYxNWJkZTM3NWQ=
12
12
  data.tar.gz: !binary |-
13
- M2E1M2RkZmU4YWNjNTQ1NWVjZDAxMjQ5NTJkZDVjYzMyOWZjNGNkNmIxNTcw
14
- OTg1NDJiYzViOTAyYTk2Y2JmNTZiYTEyMGY0YzBmMjQ5NjE5YWI3NTg0NjU5
15
- YjJmNmU2MWU0MTYyMDhmNTJiOTU2N2U1MjcxNDc4Mzc2ZTE5Yjg=
13
+ YmJmODZjZDM1MTg1NjQwOTQyNDQyNGZlOTQ1ZGE4YzZjYTZhZjU1NDhhMDRh
14
+ YzdmMmJhMDU0NTE2ZmFlMWMzMTgxYzZhNjAwNzI0MTVhNzRmNmZkODQwOTJm
15
+ NzU1ZTQ5OGU2NTlmZTAyY2I4YzRmYzEzOWM1NWRkMjZlYWE0OGE=
data/README.md CHANGED
@@ -12,7 +12,7 @@ Configuration
12
12
  Add the gem to your Gemfile or gemspec.
13
13
 
14
14
  ```ruby
15
- gem "travis-custom-deploy", "~> 0.0.4"
15
+ gem "travis-custom-deploy", "~> 0.0.6"
16
16
  ```
17
17
  To use travis-custom-deploy with Travis-CI you need to define environment variables. I recommend
18
18
  to use [secure environment variables](http://about.travis-ci.org/docs/user/build-configuration/#Secure-environment-variables) with Travis-CI. The best way to do that is to use travis gem:
@@ -5,6 +5,7 @@ require 'travis-custom-deploy'
5
5
  # The usage for the binary of travis-custom-deploy
6
6
  def usage
7
7
  puts 'Usage: travis-custom-deploy TRANSFER_TYPE FILES...'
8
+ exit 1
8
9
  end
9
10
 
10
11
  # Returns a list of read environment variables in a hash based
@@ -23,6 +24,12 @@ if ARGV.count < 2
23
24
  usage
24
25
  end
25
26
 
27
+ # do not deploy if a pull request is tested
28
+ unless TravisCustomDeploy::Options.deploy_allowed?
29
+ puts 'Deployment not allowed for pull requests.'
30
+ exit 0
31
+ end
32
+
26
33
  transfer_type = ARGV[0]
27
34
  files = ARGV[1..-1]
28
35
 
@@ -47,5 +47,18 @@ module TravisCustomDeploy
47
47
  end
48
48
  nil
49
49
  end
50
+
51
+ # Returns true if travis-custom-deploy is not invoked as part of a pull
52
+ # request. The deployment would fail anyway if secure environment
53
+ # variables are used.
54
+ #
55
+ # Returns true if the deployment is allowed.
56
+ def self.deploy_allowed?
57
+ allowed = ENV['TRAVIS_PULL_REQUEST']
58
+ unless allowed.nil?
59
+ return false if allowed != "false"
60
+ end
61
+ true
62
+ end
50
63
  end
51
64
  end
@@ -14,24 +14,24 @@ module TravisCustomDeploy
14
14
  end
15
15
 
16
16
  def transfer
17
- Net::SFTP.start(@options['host'], @options['username'],
18
- :password => @options['password']) do |sftp|
19
-
17
+ Net::SFTP.start(@options['host'], @options['username'], :password => @options['password']) do |sftp|
20
18
  for e in @files
21
19
  if File.directory?(e)
22
20
  send_dir(sftp, e, @remotedir)
21
+ else
22
+ sftp.upload!(e, @remotedir + "/" + File.basename(e))
23
23
  end
24
24
  end
25
25
  end
26
26
  end
27
27
 
28
+ # Check if the passed arguments are sufficient
28
29
  def check_options(options)
29
30
  raise ArgumentError, 'host name must not be nil' if options['host'].nil?
30
31
  raise ArgumentError, 'userna)e must not be nil' if options['username'].nil?
31
32
  raise ArgumentError, 'password must not be nil' if options['password'].nil?
32
33
  end
33
34
 
34
-
35
35
  # Sends a directory to the remote server with the given parameters
36
36
  #
37
37
  # sftp - the SFTP connection
@@ -39,18 +39,15 @@ module TravisCustomDeploy
39
39
  # the remote folder where to place the files
40
40
  def send_dir(sftp, dir, remote)
41
41
  Dir.foreach(dir) do |file_name|
42
-
43
42
  next if file_name =~ /^(\.|\.\.)$/
44
43
 
45
44
  localfile = File.join(dir, file_name)
46
45
  if File.directory?(localfile)
47
-
48
46
  begin
49
47
  sftp.mkdir!(remote + "/" + file_name)
50
48
  rescue Net::SFTP::StatusException
51
49
  # the directory probably already exists
52
50
  end
53
-
54
51
  send_dir(sftp, File.join(dir, file_name), File.join(remote, file_name))
55
52
  else
56
53
  sftp.upload!(File.join(dir, file_name), File.join(remote, file_name))
@@ -1,5 +1,5 @@
1
1
  module TravisCustomDeploy
2
2
 
3
- VERSION = "0.0.5"
3
+ VERSION = "0.0.6"
4
4
 
5
5
  end
@@ -13,5 +13,35 @@ class TestOptions < Test::Unit::TestCase
13
13
  assert_equal ['host', 'username', 'password', 'remotedir'], @env
14
14
  end
15
15
  end
16
+
17
+ context "no pull request variable" do
18
+ setup do
19
+ ENV['TRAVIS_PULL_REQUEST'] = nil
20
+ end
21
+
22
+ should "allow deployment" do
23
+ assert_equal true, Options::deploy_allowed?
24
+ end
25
+ end
26
+
27
+ context "pull request variable false" do
28
+ setup do
29
+ ENV['TRAVIS_PULL_REQUEST'] = "false"
30
+ end
31
+
32
+ should "allow deployment" do
33
+ assert_equal true, Options::deploy_allowed?
34
+ end
35
+ end
36
+
37
+ context "pull request variable with number" do
38
+ setup do
39
+ ENV['TRAVIS_PULL_REQUEST'] = "1000"
40
+ end
41
+
42
+ should "don't allow deployment" do
43
+ assert_equal false, Options::deploy_allowed?
44
+ end
45
+ end
16
46
  end
17
47
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: travis-custom-deploy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jens Nazarenus
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-21 00:00:00.000000000 Z
11
+ date: 2014-01-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: net-sftp