Skip to content

Instantly share code, notes, and snippets.

@emdeeeks
Forked from richpeck/post-receive
Created April 11, 2019 12:07
Show Gist options
  • Save emdeeeks/7f7f6a224813f1968a4ae0186b0e16e9 to your computer and use it in GitHub Desktop.
Save emdeeeks/7f7f6a224813f1968a4ae0186b0e16e9 to your computer and use it in GitHub Desktop.
Post Receive Hook
#!/usr/bin/env ruby
# REF => https://gist.github.com/karmi/442106#file-post-receive-deploy-rb-L21
###################################################
# === CONFIGURE THE SCRIPT HERE ================= #
deploy_branch = 'master' #=> change to production
git_path = Dir.pwd
application_path = File.dirname(git_path) + "/current"
# =============================================== #
INPUT = STDIN.read.strip
old_revision,
new_revision,
branch = INPUT.split(' ')
# =============================================== #
if branch =~ Regexp.new(deploy_branch)
DEPLOY =<<-END
(
unset GIT_DIR \
&& \
git --work-tree=#{application_path} --git-dir=#{git_path} checkout -f
)
END
# => unset GIT_DIR to fix "fatal . not a git repo" errors
# => http://stackoverflow.com/a/4100577/1143732
BUNDLE =<<-END
(
unset GIT_DIR \
&& \
cd #{application_path} \
&& \
bundle install \
&& \
rake assets:precompile
)
END
RESTART =<<-END
(
touch #{application_path}/tmp/restart.txt
)
END
puts "Updating application code..."
system DEPLOY
puts "Bundling App..."
system BUNDLE
puts "Restarting application..."
system RESTART
end
# =============================================== #
# =============================================== #
@carlosver17
Copy link

Hello I'm getting the following fatal when I try to push:

remote: Updating application code...
remote: fatal: this operation must be run in a work tree
remote: Bundling App...
remote: sh: 2: cd: can't cd to //current
remote: Restarting application...
remote: touch: cannot touch '//current/tmp/restart.txt': No such file or directory

Can you help me?

Regards!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment