lib/faastruby/cli/commands/function/build.rb in faastruby-0.4.18 vs lib/faastruby/cli/commands/function/build.rb in faastruby-0.5.0
- old
+ new
@@ -1,25 +1,29 @@
module FaaStRuby
module Command
module Function
+ require 'faastruby/cli/commands/function/base_command'
+ require 'faastruby/cli/package'
class Build < FunctionBaseCommand
-
- def self.build(source, output_file, quiet = false)
- spinner = spin("Building package...")
+ def self.build(source, output_file, function_name, quiet = false)
+ # msg = "[#{function_name}] Building package..."
+ # quiet ? puts(msg) : spinner = spin(msg)
FaaStRuby::Package.new(source, output_file).build
- spinner.stop('Done!')
+ # quiet ? puts("[#{function_name}] Package created.") : spinner.stop('Done!')
puts "+ f #{output_file}".green unless quiet
end
def initialize(args)
@args = args
load_yaml
+ @yaml_config['before_build'] ||= []
@function_name = @yaml_config['name']
@abort_when_tests_fail = @yaml_config['abort_build_when_tests_fail']
parse_options
@options['source'] ||= '.'
- @options['output_file'] ||= "#{@function_name}.zip"
+ @package_file = Tempfile.new('package')
+ @options['output_file'] ||= @package_file.path
end
def ruby_runtime?
@yaml_config['runtime'].nil? || @yaml_config['runtime'].match(/^ruby/)
end
@@ -35,12 +39,14 @@
if crystal_runtime?
FaaStRuby::CLI.error('Please fix the problems above and try again') unless shards_install
end
tests_passed = run_tests
FaaStRuby::CLI.error("Build aborted because tests failed and you have 'abort_build_when_tests_fail: true' in 'faastruby.yml'") unless tests_passed || !@abort_when_tests_fail
- puts "Warning: Ignoring failed tests because you have 'abort_build_when_tests_fail: false' in 'faastruby.yml'".yellow if !tests_passed && !@abort_when_tests_fail
+ puts "[#{@function_name}] Warning: Ignoring failed tests because you have 'abort_build_when_tests_fail: false' in 'faastruby.yml'".yellow if !tests_passed && !@abort_when_tests_fail
build(@options['source'], @options['output_file'])
+ @package_file.close
+ @package_file.unlink
end
def self.help
"build".light_cyan + " [-s, --source SOURCE_DIR] [-o, --output-file OUTPUT_FILE]"
end
@@ -50,30 +56,31 @@
end
private
def build(source, output_file)
- spinner = spin("Running 'before_deploy' tasks...")
- @yaml_config['before_deploy']&.each do |command|
+ spinner = spin("[#{@function_name}] Running 'before_build' tasks...")
+ @yaml_config['before_build']&.each do |command|
puts `#{command}`
end
spinner.stop(' Done!')
- self.class.build(source, output_file)
+ self.class.build(source, output_file, @function_name)
end
def shards_install
- puts '[build] Verifying dependencies'
return true unless File.file?('shard.yml')
+ puts "[#{@function_name}] [build] Verifying dependencies"
system('shards check') || system('shards install')
end
def bundle_install
- puts '[build] Verifying dependencies'
return true unless File.file?('Gemfile')
+ puts "[#{@function_name}] [build] Verifying dependencies"
system('bundle check') || system('bundle install')
end
def run_tests
+ require 'faastruby/cli/commands/function/test'
FaaStRuby::Command::Function::Test.new(true).run(do_not_exit: true)
end
def parse_options
@options = {}