Class: GithubSnapBuilder::SnapBuilder
- Inherits:
-
Object
- Object
- GithubSnapBuilder::SnapBuilder
- Defined in:
- lib/github_snap_builder/snap_builder.rb
Class Method Summary collapse
Instance Method Summary collapse
- #build ⇒ Object
-
#initialize(logger, base_url, head_url, commit_sha, build_type) ⇒ SnapBuilder
constructor
A new instance of SnapBuilder.
- #release(snap_path, token, channel) ⇒ Object
Constructor Details
#initialize(logger, base_url, head_url, commit_sha, build_type) ⇒ SnapBuilder
Returns a new instance of SnapBuilder.
12 13 14 15 16 17 18 19 |
# File 'lib/github_snap_builder/snap_builder.rb', line 12 def initialize(logger, base_url, head_url, commit_sha, build_type) @logger = logger @base_url = base_url @head_url = head_url @commit_sha = commit_sha @build_type = build_type @base = 'core16' end |
Class Method Details
.supported_build_types ⇒ Object
66 67 68 69 70 |
# File 'lib/github_snap_builder/snap_builder.rb', line 66 def self.supported_build_types Dir[File.join(__dir__, 'builder_implementations', '*.rb')].collect do |f| File.basename(f, File.extname(f)) end end |
Instance Method Details
#build ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/github_snap_builder/snap_builder.rb', line 21 def build Dir.mktmpdir do |tempdir| # First of all, clone the repository and get on the proper hash. Make # sure to include the base repo so `git describe` has meaning. repo = Rugged::Repository.clone_at(@base_url, tempdir) remote = repo.remotes.create('fork', @head_url) remote.fetch repo.checkout(@commit_sha, {strategy: :force}) # Before we can actually build the snap, we must first determine the # base to use. The default is "core". snapcraft_yaml = snapcraft_yaml_location(tempdir) @base = YAML.safe_load(File.read(snapcraft_yaml)).fetch("base", @base) if @base == "core" @base = "core16" end # Factor out any snaps that existed before we build the new one snaps_glob = File.join(tempdir, '*.snap') existing_snaps = Dir.glob(snaps_glob) # Now build the snap build_implementation.build(tempdir) # Grab the filename of the snap we just built new_snaps = Dir.glob(snaps_glob) - existing_snaps if new_snaps.empty? raise BuildFailedError elsif new_snaps.length > 1 raise TooManySnapsError, new_snaps end # The directory we're in right now will be removed shortly. Copy the # snap somewhere that will live forever, and hand it to the Snap class # (which will remove it when it's done with it). snap_file = Tempfile.create [@commit_sha, '.snap'] FileUtils.cp new_snaps[0], snap_file snap_file.path end end |
#release(snap_path, token, channel) ⇒ Object
62 63 64 |
# File 'lib/github_snap_builder/snap_builder.rb', line 62 def release(snap_path, token, channel) build_implementation.release(snap_path, token, channel) end |