Class: Moonshot::BuildMechanism::Script
- Inherits:
-
Object
- Object
- Moonshot::BuildMechanism::Script
- Includes:
- DoctorHelper, ResourcesHelper
- Defined in:
- lib/moonshot/build_mechanism/script.rb
Overview
Compile a release artifact using a shell script.
The output file will be deleted before the script is run, and is expected to exist after the script exits. Any non-zero exit status will be consider a build failure, and any output will be displayed to the user.
Creating a new Script BuildMechanism looks like this:
class MyReleaseTool < Moonshot::CLI
include Moonshot::BuildMechanism
self.build_mechanism = Script.new('script/build.sh')
end
Instance Attribute Summary collapse
-
#output_file ⇒ Object
readonly
Returns the value of attribute output_file.
Attributes included from ResourcesHelper
Instance Method Summary collapse
- #build_hook(version) ⇒ Object
-
#initialize(script, output_file: 'output.tar.gz') ⇒ Script
constructor
A new instance of Script.
- #post_build_hook(_version) ⇒ Object
- #pre_build_hook(_version) ⇒ Object
Methods included from DoctorHelper
Constructor Details
#initialize(script, output_file: 'output.tar.gz') ⇒ Script
Returns a new instance of Script.
23 24 25 26 |
# File 'lib/moonshot/build_mechanism/script.rb', line 23 def initialize(script, output_file: 'output.tar.gz') @script = script @output_file = output_file end |
Instance Attribute Details
#output_file ⇒ Object (readonly)
Returns the value of attribute output_file.
21 22 23 |
# File 'lib/moonshot/build_mechanism/script.rb', line 21 def output_file @output_file end |
Instance Method Details
#build_hook(version) ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'lib/moonshot/build_mechanism/script.rb', line 32 def build_hook(version) env = { 'VERSION' => version, 'OUTPUT_FILE' => @output_file } ilog.start_threaded "Running Script: #{@script}" do |s| run_script(s, env: env) end end |
#post_build_hook(_version) ⇒ Object
42 43 44 45 46 |
# File 'lib/moonshot/build_mechanism/script.rb', line 42 def post_build_hook(_version) unless File.exist?(@output_file) # rubocop:disable GuardClause raise 'Build command did not produce output file!' end end |
#pre_build_hook(_version) ⇒ Object
28 29 30 |
# File 'lib/moonshot/build_mechanism/script.rb', line 28 def pre_build_hook(_version) File.delete(@output_file) if File.exist?(@output_file) end |