summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorRémy Coutable <remy@rymai.me>2016-11-24 14:19:09 +0100
committerRémy Coutable <remy@rymai.me>2016-11-30 10:35:17 +0100
commita9c250eaddf758f99ac8c868dc86f4df0cc157f4 (patch)
tree8a6e338529341e89ca407ab865f9185028c5610d /lib
parentfbbf177e3b604bebce3b10f8eea8920ff5606fca (diff)
downloadgitlab-ce-a9c250eaddf758f99ac8c868dc86f4df0cc157f4.tar.gz
Add #run_command! to task helpers to raise a TaskFailedError if status is not 0
Signed-off-by: Rémy Coutable <remy@rymai.me>
Diffstat (limited to 'lib')
-rw-r--r--lib/tasks/gitlab/task_helpers.rake36
-rw-r--r--lib/tasks/gitlab/workhorse.rake2
2 files changed, 28 insertions, 10 deletions
diff --git a/lib/tasks/gitlab/task_helpers.rake b/lib/tasks/gitlab/task_helpers.rake
index 85c3a3a9b0f..c0759b96602 100644
--- a/lib/tasks/gitlab/task_helpers.rake
+++ b/lib/tasks/gitlab/task_helpers.rake
@@ -1,4 +1,5 @@
module Gitlab
+ class TaskFailedError < StandardError; end
class TaskAbortedByUserError < StandardError; end
end
@@ -81,6 +82,18 @@ namespace :gitlab do
'' # if the command does not exist, return an empty string
end
+ # Runs the given command and raise a Gitlab::TaskFailedError exception if
+ # the command does not exit with 0
+ #
+ # Returns the output of the command otherwise
+ def run_command!(command)
+ output, status = Gitlab::Popen.popen(command)
+
+ raise Gitlab::TaskFailedError unless status.zero?
+
+ output
+ end
+
def uid_for(user_name)
run_command(%W(id -u #{user_name})).chomp.to_i
end
@@ -145,11 +158,11 @@ namespace :gitlab do
def checkout_or_clone_tag(tag:, repo:, target_dir:)
if Dir.exist?(target_dir)
Dir.chdir(target_dir) do
- run_command(%W[#{Gitlab.config.git.bin_path} fetch --tags --quiet])
- run_command(%W[#{Gitlab.config.git.bin_path} checkout --quiet #{tag}])
+ run_command!(%W[#{Gitlab.config.git.bin_path} fetch --tags --quiet])
+ run_command!(%W[#{Gitlab.config.git.bin_path} checkout --quiet #{tag}])
end
else
- run_command(%W[#{Gitlab.config.git.bin_path} clone -- #{repo} #{target_dir}])
+ run_command!(%W[#{Gitlab.config.git.bin_path} clone -- #{repo} #{target_dir}])
end
# Make sure we're on the right tag
@@ -161,13 +174,18 @@ namespace :gitlab do
end
def reset_to_tag(tag_wanted)
- tag, status = Gitlab::Popen.popen(%W[#{Gitlab.config.git.bin_path} describe -- #{tag_wanted}])
+ tag =
+ begin
+ run_command!(%W[#{Gitlab.config.git.bin_path} describe -- #{tag_wanted}])
+ rescue Gitlab::TaskFailedError
+ run_command!(%W[#{Gitlab.config.git.bin_path} fetch origin])
+ run_command!(%W[#{Gitlab.config.git.bin_path} describe -- origin/#{tag_wanted}])
+ end
- unless status.zero?
- run_command(%W(#{Gitlab.config.git.bin_path} fetch origin))
- tag = run_command(%W[#{Gitlab.config.git.bin_path} describe -- origin/#{tag_wanted}])
+ if tag
+ run_command!(%W[#{Gitlab.config.git.bin_path} reset --hard #{tag.strip}])
+ else
+ raise Gitlab::TaskFailedError
end
-
- run_command(%W[#{Gitlab.config.git.bin_path} reset --hard #{tag.strip}])
end
end
diff --git a/lib/tasks/gitlab/workhorse.rake b/lib/tasks/gitlab/workhorse.rake
index 5964cb83b89..563744dd0c7 100644
--- a/lib/tasks/gitlab/workhorse.rake
+++ b/lib/tasks/gitlab/workhorse.rake
@@ -16,7 +16,7 @@ namespace :gitlab do
command = status.zero? ? 'gmake' : 'make'
Dir.chdir(args.dir) do
- run_command([command])
+ run_command!([command])
end
end
end