pushdeploy 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,40 +1,34 @@
1
- #!/bin/bash
1
+ #!/usr/bin/env ruby
2
2
 
3
3
  #
4
4
  # This script creates a file 'after_deploy.rb' in your config directory.
5
5
  # You should run it inside of your project directory.
6
6
  #
7
7
 
8
- generate_config_body()
9
- {
10
- cat <<-EOF
11
- #!/usr/bin/env ruby
12
-
13
- #
14
- # This script is launched by post-receive hook when push is completed.
15
- # The general purpose of this script is to run bundler, migration and
16
- # other commands that you want to launch after deployment.
17
- #
18
-
19
- require 'pushdeploy'
20
-
21
- PushDeploy.new(ARGV) do
22
- bundle
23
- migrate
24
- run "touch #{@deploy_to}/tmp/restart.txt"
25
- end
26
- EOF
8
+ Dir.mkdir "./config" if !File.directory? './config'
9
+
10
+ config_file = File.open "./config/after_deploy.rb", "w"
11
+ raise "A error has been occured while trying to write to $(pwd)/config/after_deploy.rb. Not enough permission?" if config_file.nil?
27
12
 
28
- }
13
+ config_file.write %{#!/usr/bin/env ruby
14
+
15
+ #
16
+ # This script is launched by post-receive hook when push is completed.
17
+ # The general purpose of this script is to run bundler, migration and
18
+ # other commands that you want to launch after deployment.
19
+ #
20
+
21
+ require 'pushdeploy'
29
22
 
30
- if [ ! -d "./config" ]; then mkdir config; fi
23
+ PushDeploy.new(ARGV) do
24
+ bundle
25
+ migrate
26
+ run "touch #{@deploy_to}/tmp/restart.txt"
27
+ end
28
+ }
31
29
 
32
- generate_config_body > ./config/after_deploy.rb
30
+ puts "\n*************************************"
31
+ puts "\e[00;32mConfig has been successfully created!\e[00m"
32
+ puts "*************************************\n"
33
33
 
34
- if [ -f "./config/after_deploy.rb" ]; then
35
- echo -e "\n**********************************"
36
- echo -e "\n\x1B[00;32mConfig has been successfully created!\x1B[00m\n"
37
- echo -e "You can edit $(pwd)/config/after_deploy.rb to add commands that you want to run after deployment.\n"
38
- else
39
- echo -e "\n\x1B[00;31mAn error has been occured while trying to write to $(pwd)/config/after_deploy.rb. Not enough permission?\e[00m"
40
- fi
34
+ puts "You can edit " + `pwd`.chop + "/config/after_deploy.rb to add commands that you want to run after deployment.\n\n"
@@ -1,4 +1,4 @@
1
- #!/bin/sh
1
+ #!/usr/bin/env ruby
2
2
 
3
3
  #
4
4
  # Overrides post-receive hook in your git repository.
@@ -18,121 +18,87 @@
18
18
  # which lauches bundler, migrate and other commands that you specified.
19
19
  #
20
20
 
21
- repository=$(git config --get remote.origin.url)
22
-
23
- get_rvm_string()
24
- {
25
- if [[ -n "$rvm_path" ]];
26
- then
27
- rvm_string=$(rvm current)
28
- fi
29
- }
30
-
31
- manual_setup()
32
- {
33
- echo "Let's set up some variables"
34
- if [ -z $repository ]; then
35
- echo -e "\n\x1B[00;31m*** Can't locate your git repository. ***\x1B[00m"
36
- echo -e "\nMay be you run installer from a wrong directory?"
37
- echo -e "\nYou should run it from the root folder of your project. Something like /var/www/html/myapp/"
38
- echo "Current dir is: $(pwd)"
39
- echo -e "\n\x1B[00;32mAnyway, no worries, we can try to set everything up manually. Just answer some questions about your environment.\x1B[00m "
40
- fi
21
+ repository=`git config --get remote.origin.url`
22
+
23
+ rvm_path = ENV['rvm_path']
24
+ rvm_string = rvm_path.nil? ? nil : `rvm current`
25
+ current_path = `pwd`.chop
26
+
27
+ if ! File.directory?(repository) || ARGV[0] == '-m'
28
+
29
+ if ! File.directory?(repository)
30
+ puts "\n\e[00;31m*** Can't locate your git repository. ***\e[00m"
31
+ puts "\nMay be you run installer from a wrong directory?"
32
+ puts "\nYou should run it from the root folder of your project. Something like /var/www/html/myapp/"
33
+ puts "Current dir is: #{current_path}"
34
+ puts "\n\e[00;32mAnyway, no worries, we can try to set everything up manually. Just answer some questions about your environment.\e[00m "
35
+ end
41
36
 
42
- echo -ne "Where is the git repository for this project located?: "
43
- read repository
44
-
45
- get_rvm_string
37
+ print "\nWhere is the git repository for this project located?: "
38
+ repository = gets.chomp
46
39
 
47
- if [ -n $rvm_path ]; then
48
- echo -e "\n\x1B[00;32mRVM path found:\x1B[00m \x1B[00;34m$rvm_path\x1B[00m.\n"
49
- echo -e "* hit Enter if this is a correct path."
40
+ if !rvm_path.nil?
41
+ puts "\n\e[00;32mRVM path found:\e[00m \e[00;34m#{rvm_path}\e[00m.\n"
42
+ puts "* hit Enter if this is a correct path."
50
43
  else
51
- echo -e "\nRVM path not found.\n"
52
- fi
53
-
54
- echo -e "* type \x1B[00;32mn\x1B[00m if you don't even use RVM."
55
- echo -e "* or just enter your own path."
56
- echo -ne "\nYour answer: "
57
- read new_rvm_path
58
-
59
- if [ -n "$new_rvm_path" ]; then
60
- if [ "$new_rvm_path" == "n" ]; then
61
- rvm_path=""
62
- else
63
- rvm_path=$new_rvm_path
64
- fi
65
- fi
44
+ puts "\nRVM path not found.\n"
45
+ end
46
+
47
+ puts "* type \e[00;32mn\e[00m if you don't even use RVM."
48
+ puts "* or just enter your own path."
49
+ print "\nYour answer: "
50
+ new_rvm_path = gets.chomp
51
+
52
+ if new_rvm_path == 'n'
53
+ rvm_path = nil
54
+ elsif !new_rvm_path.empty?
55
+ rvm_path = new_rvm_path
56
+ end
57
+
66
58
 
67
- if [ "$new_rvm_path" != "n" -a -n "$rvm_path" ]; then
68
- echo -e "\n***************************************************************************\n"
59
+ if new_rvm_path != "n" && !rvm_path.nil?
60
+ puts "\n***************************************************************************\n"
69
61
 
70
- if [ -n $rvm_string ]; then
71
- echo -e "This is your active gemset and version of Ruby: \x1B[00;34m$rvm_string\x1B[00m."
72
- echo -e "\n* Just hit Enter if this is correct for your project."
62
+ if !rvm_string.nil?
63
+ puts "This is your active gemset and version of Ruby: \e[00;34m#{rvm_string}\e[00m."
64
+ puts "\n* Just hit Enter if this is correct for your project."
73
65
  else
74
- echo "Your rvm ruby string is not detected for some reason."
75
- fi
76
- echo -ne "\nEnter a rvm ruby string (usually something like 1.9.2@rails3): "
77
- read rvm_string
78
- fi
66
+ puts "Your rvm ruby string is not detected for some reason."
67
+ end
68
+ print "\nEnter a rvm ruby string (usually something like 1.9.2@rails3): "
69
+
70
+ new_rvm_string = gets.chomp
71
+ rvm_string = new_rvm_string.empty? ? rvm_string : new_rvm_string
72
+
73
+ end
79
74
 
80
- echo $repository
81
- echo $rvm_path
82
- echo $rvm_string
83
-
75
+ end
76
+
77
+ # create 'hooks' folder if it doesn't exist
78
+ Dir.mkdir "#{repository}/hooks" if !File.directory? "#{repository}/hooks"
79
+
80
+ hook_file = File.open "#{repository}/hooks/post-receive", "w"
81
+ puts "\e[00;31mA error has been occured while trying to write to #{repository}/hooks/post-receive. Not enough permission?\e[00m\n\n Try using: sudo\n" && exit if hook_file.nil?
82
+
83
+ # writing a bash script to a hook
84
+ hook_file.write %{#!/bin/sh
85
+ deploy_dir=#{current_path}
86
+ read oldrev newrev refname
87
+
88
+ unset GIT_DIR && cd \$deploy_dir && git --work-tree=\$deploy_dir pull #{repository} -f
84
89
  }
85
90
 
86
- generate_hook_body()
87
- {
88
- cat <<-EOF
89
- #!/bin/sh
90
- deploy_dir=$(pwd)
91
- read oldrev newrev refname
92
-
93
- unset GIT_DIR && cd \$deploy_dir && git --work-tree=\$deploy_dir pull $repository -f
94
- EOF
95
-
96
- if [ -n "$rvm_path" -a -n "$rvm_string" ]; then
97
- cat <<-EOF
98
- source "$rvm_path/scripts/rvm"
99
- rvm $rvm_string
100
- EOF
101
- fi
102
-
103
- cat <<-EOF
104
- \$deploy_dir/config/auto_deploy.rb \$oldrev \$newrev \$refname \$deploy_dir
105
- EOF
106
-
107
- }
108
-
109
- if [ -z "$repository" -o "$1" == "-m" ]; then
110
- manual_setup
111
- else
112
- get_rvm_string
113
- fi
114
-
115
- # create 'hooks' folder if it doesn't exist
116
-
117
- if [ -z "$repository/hooks" ]; then
118
- echo "Creating a hook folder (didn't exist).."
119
- mkdir -p "$repository/hooks"
120
- fi
91
+ hook_file.write %{source "#{rvm_path}/scripts/rvm"\nrvm #{rvm_string}} if rvm_path && rvm_string
121
92
 
122
- # check if we have permissions to write to the 'hooks' folder
93
+ hook_file.write "\$deploy_dir/config/auto_deploy.rb \$oldrev \$newrev \$refname \$deploy_dir"
123
94
 
124
- if [ ! -w "$repository/hooks" ]; then
125
- echo -e "\x1B[00;31mYou don't have permission to modify $repository/hooks/\x1B[00m"
126
- echo "Try using: sudo $0"
127
- exit 1
128
- fi
95
+ `chmod 770 #{repository}/hooks/post-receive`
129
96
 
130
- generate_hook_body > $repository/hooks/post-receive
131
- if [ "$?" -ne 0 ]; then echo "A error occured while trying to write a hook."; exit 1; fi
97
+ puts "A error occured while trying to set permission of the hook. Try sudo?" && exit if !$?.success?
132
98
 
133
- chmod 770 $repository/hooks/post-receive
134
- if [ "$?" -ne 0 ]; then echo "A error occured while trying to set permission of the hook. Try sudo?"; exit 1; fi
99
+ puts "\n*****************************************************************"
100
+ puts "\e[00;32mpost-receive hook has been successfully installed to #{repository}/hooks/post-receive\e[00m"
101
+ puts "*******************************************************************\n"
135
102
 
136
- echo -e "\n\x1B[00;32mpost-receive hook has been successfully installed to $repository/hooks/post-receive\x1B[00m"
137
- echo "Don't forget to run 'pushdeploy_create_config' inside of your project directory"
103
+ puts "Don't forget to run 'pushdeploy_create_config' inside of your project directory on a development machine.\n\n"
138
104
 
@@ -1,3 +1,3 @@
1
1
  module Pushdeploy
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: pushdeploy
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.1
5
+ version: 0.0.2
6
6
  platform: ruby
7
7
  authors:
8
8
  - Artem Yankov