Class: Berkflow::ThorTasks

Inherits:
Thor
  • Object
show all
Defined in:
lib/berkflow/thor_tasks.rb

Constant Summary collapse

REGEX =
/(git\@github.com\:|https\:\/\/github.com\/)(.+).git/.freeze

Instance Method Summary collapse

Instance Method Details

#releaseObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/berkflow/thor_tasks.rb', line 24

def release
  cookbook = Ridley::Chef::Cookbook.from_path(File.dirname(options[:berksfile]))
  begin
    say "Creating GitHub release (#{cookbook.version})"
    release = github_client.create_release(repository, cookbook.version)
  rescue Octokit::UnprocessableEntity
    say "Release already exists, skipping..."
    release = github_client.releases(repository).find { |release| release[:tag_name] == cookbook.version }
  end

  berksfile = Berkshelf::Berksfile.from_file(options[:berksfile])
  pkg_dir   = File.join(File.dirname(File.expand_path(berksfile.filepath)), "pkg")
  out_file  = File.join(pkg_dir, "cookbooks-#{Time.now.to_i}.tar.gz")
  FileUtils.mkdir_p(pkg_dir)
  berksfile.package(out_file)

  begin
    say "Uploading #{File.basename(out_file)} to GitHub..."
    github_client.upload_asset(release[:url], out_file, name: "cookbooks.tar.gz", content_type: "application/x-tar")
  rescue Errno::EPIPE; end
end