diff --git a/bin/post-receive-hook_dev b/bin/post-receive-hook.partial similarity index 51% rename from bin/post-receive-hook_dev rename to bin/post-receive-hook.partial index b577daa5b..b1e39a205 100644 --- a/bin/post-receive-hook_dev +++ b/bin/post-receive-hook.partial @@ -9,7 +9,4 @@ owner=`basename \`dirname $pwd\`` while read oldrev newrev ref do newrev_type=$(git cat-file -t $newrev 2> /dev/null) - oldrev_type=$(git cat-file -t "$oldrev" 2> /dev/null) - - /bin/bash -l -c "cd /srv/rosa_build/current && bundle exec rails runner 'Project.delay.process_hook(\"$owner\", \"$reponame\", \"$newrev\", \"$oldrev\", \"$ref\", \"$newrev_type\", \"$oldrev_type\")'" -done \ No newline at end of file + oldrev_type=$(git cat-file -t "$oldrev" 2> /dev/null) \ No newline at end of file diff --git a/bin/post-receive-hook_prod b/bin/post-receive-hook_prod deleted file mode 100644 index 6e9fb4bd8..000000000 --- a/bin/post-receive-hook_prod +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/bash - -# This file was placed here by rosa-team. It makes sure that your pushed commits will be processed properly. - -pwd=`pwd` -reponame=`basename $pwd .git` -owner=`basename \`dirname $pwd\`` - -while read oldrev newrev ref -do - newrev_type=$(git cat-file -t $newrev 2> /dev/null) - oldrev_type=$(git cat-file -t "$oldrev" 2> /dev/null) - - /bin/bash -l -c "cd /srv/rosa_build/current && RAILS_ENV=production bundle exec rails runner 'Project.delay.process_hook(\"$owner\", \"$reponame\", \"$newrev\", \"$oldrev\", \"$ref\", \"$newrev_type\", \"$oldrev_type\")'" > /dev/null 2>&1 -done \ No newline at end of file diff --git a/lib/tasks/hook.rake b/lib/tasks/hook.rake index 1eeae0774..baf1e458a 100644 --- a/lib/tasks/hook.rake +++ b/lib/tasks/hook.rake @@ -1,15 +1,28 @@ namespace :hook do desc "Inserting hook to all repos" task :install => :environment do - origin_hook = File.join(::Rails.root.to_s, 'bin', "post-receive-hook#{ENV['RAILS_ENV'] == 'production' ? '_prod' : '_dev'}") - say "process.. #{origin_hook}" + is_production = ENV['RAILS_ENV'] == 'production' + say "Generate temporary file..." + hook = File.join(::Rails.root.to_s, 'tmp', "post-receive-hook") + FileUtils.cp(File.join(::Rails.root.to_s, 'bin', "post-receive-hook.partial"), hook) + File.open(hook, 'a') do |f| + s = "\n /bin/bash -l -c \"cd #{is_production ? '/srv/rosa_build/current' : Rails.root.to_s} && \ + bundle exec rails runner 'Project.delay.process_hook(\"$owner\", \"$reponame\", \"$newrev\", \"$oldrev\", \"$ref\", \"$newrev_type\", \"$oldrev_type\")'\"" + s << " > /dev/null 2>&1" if is_production + s << "\ndone\n" + f.write(s) + end + + say "Install process.." count = 0 Project.all.each do |project| hook_file = File.join(project.path, 'hooks', 'post-receive') - FileUtils.cp(origin_hook, hook_file) + FileUtils.cp(hook, hook_file) count = count + 1 end - say "Done! Writing to #{count.to_s} repo(s)" + say "Writing to #{count.to_s} repo(s)" + say "Removing temporary file" + FileUtils.rm_rf(hook) end desc "remove git hook from all repos" @@ -20,4 +33,3 @@ namespace :hook do say "Done! Removing from #{count.to_s} repo(s)" end end -