Skip to content

Commit 9206390

Browse files
authored
Merge pull request #20 from OpenVoxProject/standardize_tasks
Standardize rake tasks
2 parents 5041676 + 80403c9 commit 9206390

File tree

5 files changed

+24
-18
lines changed

5 files changed

+24
-18
lines changed

Rakefile

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,26 @@
11
require 'open3'
22

3-
def run_command(cmd, silent = false)
3+
RED = "\033[31m"
4+
GREEN = "\033[32m"
5+
RESET = "\033[0m"
6+
7+
def run_command(cmd, silent: true, print_command: false, report_status: false)
8+
puts "#{GREEN}Running #{cmd}#{RESET}" if print_command
49
output = ''
510
Open3.popen2e(cmd) do |_stdin, stdout_stderr, thread|
611
stdout_stderr.each do |line|
712
puts line unless silent
813
output += line
914
end
1015
exitcode = thread.value.exitstatus
11-
abort "Command failed!" unless exitcode.zero?
16+
unless exitcode.zero?
17+
err = "#{RED}Command failed! Command: #{cmd}, Exit code: #{exitcode}"
18+
# Print details if we were running silent
19+
err += "\nOutput:\n#{output}" if silent
20+
err += RESET
21+
abort err
22+
end
23+
puts "#{GREEN}Command finished with status #{exitcode}#{RESET}" if report_status
1224
end
1325
output.chomp
1426
end

tasks/build.rake

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,6 @@ namespace :vox do
1919

2020
FileUtils.rm_rf('C:/ProgramFiles64Folder') if platform =~ /^windows-/
2121

22-
puts "Running #{cmd}"
23-
exitcode = nil
24-
Open3.popen2e(cmd) do |_stdin, stdout_stderr, thread|
25-
stdout_stderr.each { |line| puts line }
26-
exitcode = thread.value.exitstatus
27-
puts "Command finished with status #{exitcode}"
28-
end
29-
exit exitcode
22+
run_command(cmd, silent: false, print_command: true, report_status: true)
3023
end
3124
end

tasks/promote.rake

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace :vox do
88
abort "Could not find configs/components/#{component}.json" unless File.exist?("configs/components/#{component}.json")
99
abort 'You must provide a ref.' if ref.nil? || ref.empty?
1010

11-
if ['puppet-runtime','pxp-agent'].include?(component)
11+
if ['puppet-runtime', 'pxp-agent'].include?(component)
1212
munged = ref.gsub('-', '.')
1313
data = <<~DATA
1414
{"location":"https://s3.osuosl.org/openvox-artifacts/#{component}/#{ref}/","version":"#{munged}"}
@@ -26,7 +26,9 @@ namespace :vox do
2626
run_command("git add configs/components/#{component}.json")
2727
puts 'Creating commit'
2828
run_command("git commit -m 'Promote #{component} #{ref}'")
29-
puts 'Pushing to origin'
30-
run_command("git push origin #{branch}")
29+
if ENV['NOPUSH'].nil?
30+
puts 'Pushing to origin'
31+
run_command("git push origin #{branch}")
32+
end
3133
end
3234
end

tasks/tag.rake

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ namespace :vox do
2424

2525
run_command("git tag -a #{version} -m '#{version}'")
2626

27-
unless !ENV['NOPUSH'].nil?
28-
puts "Pushing #{version} to origin"
29-
run_command("git push origin #{version}")
27+
if ENV['NOPUSH'].nil?
28+
puts "Pushing to origin"
29+
run_command("git push origin && git push origin #{version}")
3030
end
3131
end
3232
end

tasks/upload.rake

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ namespace :vox do
3434

3535
path = "s3://#{bucket}/#{component}/#{args[:tag]}"
3636
files.each do |f|
37-
puts "Uploading #{File.basename(f)}"
38-
run_command("#{s3} cp #{f} #{path}/#{File.basename(f)}")
37+
run_command("#{s3} cp #{f} #{path}/#{File.basename(f)}", silent: false)
3938
end
4039
end
4140
end

0 commit comments

Comments
 (0)