Class: Moonshot::BuildMechanism::Script
- Inherits:
-
Object
- Object
- Moonshot::BuildMechanism::Script
- Includes:
- DoctorHelper, ResourcesHelper, Open3
- 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.
26 27 28 29 |
# File 'lib/moonshot/build_mechanism/script.rb', line 26 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.
24 25 26 |
# File 'lib/moonshot/build_mechanism/script.rb', line 24 def output_file @output_file end |
Instance Method Details
#build_hook(version) ⇒ Object
35 36 37 38 39 40 41 42 43 |
# File 'lib/moonshot/build_mechanism/script.rb', line 35 def build_hook(version) env = { 'VERSION' => version, 'OUTPUT_FILE' => @output_file } ilog.start_threaded "Running Script: #{@script}" do |s| run_script(s, env:) end end |
#post_build_hook(_version) ⇒ Object
45 46 47 48 49 |
# File 'lib/moonshot/build_mechanism/script.rb', line 45 def post_build_hook(_version) unless File.exist?(@output_file) # rubocop:disable Style/GuardClause raise 'Build command did not produce output file!' end end |
#pre_build_hook(_version) ⇒ Object
31 32 33 |
# File 'lib/moonshot/build_mechanism/script.rb', line 31 def pre_build_hook(_version) File.delete(@output_file) if File.exist?(@output_file) end |