Class: Egads::Build

Inherits:
Group
  • Object
show all
Includes:
BuildHelpers, LocalHelpers, Thor::Actions
Defined in:
lib/egads/command/build.rb

Defined Under Namespace

Modules: BuildHelpers

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from BuildHelpers

#build_type, #can_build?, #error, #patch_path, #sha_is_checked_out?, #should_build?, #working_directory_is_clean?

Methods included from LocalHelpers

#sha, #short_sha, #tarball

Methods inherited from Group

exit_on_failure?

Instance Attribute Details

#build_shaObject

Returns the value of attribute build_sha.



12
13
14
# File 'lib/egads/command/build.rb', line 12

def build_sha
  @build_sha
end

Instance Method Details

#check_buildObject



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/egads/command/build.rb', line 14

def check_build
  say_status :rev, "#{rev} parsed to #{sha}"

  unless should_build?
    say_status :done, "#{build_type} tarball for #{sha} already exists. Pass --force to rebuild."
    exit 0
  end

  exit 1 unless can_build?
  say_status :build, "Making #{build_type} tarball for #{sha}", :yellow
end

#commit_extra_pathsObject



34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/egads/command/build.rb', line 34

def commit_extra_paths
  # Double-check that SHA hasn't changed since we started building
  exit 1 unless sha_is_checked_out?

  extra_paths = ["REVISION"]
  extra_paths += Config.build_extra_paths
  run_with_code("git add -f #{extra_paths * ' '} && git commit --no-verify -m '[egads seed] [ci skip]'")
  # Get the build SHA
  self.build_sha = run_with_code("git rev-parse --verify HEAD").strip
  run_with_code "git reset #{sha}" # Reset to original SHA

end

#make_tarballObject



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/egads/command/build.rb', line 47

def make_tarball
  if options[:seed]
    # Seed tarball
    run_with_code "git archive #{build_sha} --output #{tarball.local_tar_path}"
  else
    # Patch tarball
    seed_ref = "refs/remotes/origin/#{Config.seed_branch}"
    # NB: the seed tarball is named after the parent of seed tag
    seed_parent = run_with_code("git rev-parse --verify #{seed_ref}^").strip
    File.open('egads-seed', 'w') {|f| f << seed_parent + "\n" }
    patch_files = [patch_path, 'egads-seed']
    run_with_code "git diff --binary #{seed_ref} #{build_sha} > #{patch_path}"
    run_with_code "tar -zcf #{tarball.local_tar_path} #{patch_files * ' '}"
    patch_files.each {|f| File.delete(f) }
  end

end

#push_seedObject



73
74
75
76
77
# File 'lib/egads/command/build.rb', line 73

def push_seed
  if options[:seed]
    run_with_code "git push -f origin #{build_sha}:refs/heads/#{Config.seed_branch}"
  end
end

#run_after_build_hooksObject



65
66
67
# File 'lib/egads/command/build.rb', line 65

def run_after_build_hooks
  run_hooks_for(:build, :after)
end

#run_before_build_hooksObject



26
27
28
# File 'lib/egads/command/build.rb', line 26

def run_before_build_hooks
  run_hooks_for(:build, :before)
end

#uploadObject



69
70
71
# File 'lib/egads/command/build.rb', line 69

def upload
  invoke(Egads::Upload, [sha], force: options[:force], seed: options[:seed]) unless options['no-upload']
end

#write_revision_fileObject



30
31
32
# File 'lib/egads/command/build.rb', line 30

def write_revision_file
  File.open('REVISION', 'w') {|f| f << sha + "\n" }
end