Class: DPL::Provider::Packagecloud
- Inherits:
-
DPL::Provider
- Object
- DPL::Provider
- DPL::Provider::Packagecloud
- Defined in:
- lib/dpl/provider/packagecloud.rb
Instance Method Summary collapse
- #check_auth ⇒ Object
- #dist_required?(filename) ⇒ Boolean
- #error_if_dist_required(filename) ⇒ Object
- #get_distro(query) ⇒ Object
- #get_source_files_for(orig_filename) ⇒ Object
- #is_source_package?(filename) ⇒ Boolean
- #is_supported_package?(filename) ⇒ Boolean
- #needs_key? ⇒ Boolean
- #push_app ⇒ Object
- #setup_auth ⇒ Object
Instance Method Details
#check_auth ⇒ Object
6 7 8 9 10 11 12 13 |
# File 'lib/dpl/provider/packagecloud.rb', line 6 def check_auth setup_auth begin @client = ::Packagecloud::Client.new(@creds, "travis-ci") rescue ::Packagecloud::UnauthenticatedException error "Could not authenticate to https://packagecloud.io, please check credentials" end end |
#dist_required?(filename) ⇒ Boolean
46 47 48 49 50 51 52 |
# File 'lib/dpl/provider/packagecloud.rb', line 46 def dist_required?(filename) ext = File.extname(filename).gsub!('.','') if ext.nil? error "filename: #{filename} has no extension!" end ["rpm", "deb", "dsc", "whl", "egg", "egg-info", "gz", "zip", "tar", "bz2", "z", "tgz"].include?(ext.downcase) end |
#error_if_dist_required(filename) ⇒ Object
54 55 56 57 58 |
# File 'lib/dpl/provider/packagecloud.rb', line 54 def error_if_dist_required(filename) if dist_required?(filename) && @dist.nil? error "Distribution needed for rpm, deb, python, and dsc packages, example --dist='ubuntu/breezy'" end end |
#get_distro(query) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/dpl/provider/packagecloud.rb', line 28 def get_distro(query) distro = nil begin distro = @client.find_distribution_id(query) rescue ArgumentError => exception error "Error: #{exception.}" end if distro.nil? error "Could not find distribution named #{query}" end distro end |
#get_source_files_for(orig_filename) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/dpl/provider/packagecloud.rb', line 65 def get_source_files_for(orig_filename) source_files = {} glob_args = ["**/*"] package = ::Packagecloud::Package.new(:file => orig_filename) result = @client.package_contents(@repo, package, get_distro(@dist)) if result.succeeded package_contents_files = result.response["files"].map { |x| x["filename"] } Dir.chdir(.fetch(:local_dir, Dir.pwd)) do Dir.glob(*glob_args) do |filename| unless File.directory?(filename) basename = File.basename(filename) if package_contents_files.include?(basename) log "Found source fragment: #{basename} for #{orig_filename}" source_files = source_files.merge({basename => open(filename)}) end end end end else error "Error: #{result.response}" end source_files end |
#is_source_package?(filename) ⇒ Boolean
60 61 62 63 |
# File 'lib/dpl/provider/packagecloud.rb', line 60 def is_source_package?(filename) ext = File.extname(filename).gsub!('.','') ext == 'dsc' end |
#is_supported_package?(filename) ⇒ Boolean
41 42 43 44 |
# File 'lib/dpl/provider/packagecloud.rb', line 41 def is_supported_package?(filename) ext = File.extname(filename).gsub!('.','') ::Packagecloud::SUPPORTED_EXTENSIONS.include?(ext) end |
#needs_key? ⇒ Boolean
15 16 17 |
# File 'lib/dpl/provider/packagecloud.rb', line 15 def needs_key? false end |
#push_app ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/dpl/provider/packagecloud.rb', line 89 def push_app forced = .fetch(:force, nil) packages = [] glob_args = Array(.fetch(:package_glob, '**/*')) Dir.chdir(.fetch(:local_dir, Dir.pwd)) do Dir.glob(*glob_args) do |filename| unless File.directory?(filename) if is_supported_package?(filename) log "Detected supported package: #{filename}" error_if_dist_required(filename) if is_source_package?(filename) log "Processing source package: #{filename}" source_files = get_source_files_for(filename) packages << ::Packagecloud::Package.new(:file => filename, :source_files => source_files) else packages << ::Packagecloud::Package.new(:file => filename) end end end end end packages.each do |package| if forced log "Deleting package: #{package.filename}" distro, distro_release = @dist.split("/") result = @client.delete_package(@repo, distro, distro_release, package.filename) if result.succeeded log "Successfully deleted #{package.filename} on #{@dist}" else error "Error #{result.response}" end end log "Pushing package: #{package.filename}" if dist_required?(package.filename) result = @client.put_package(@repo, package, get_distro(@dist)) else result = @client.put_package(@repo, package) end if result.succeeded log "Successfully pushed #{package.filename} to #{@username}/#{@repo}" else error "Error #{result.response}" end end if packages.empty? error "Error: No supported packages found! Perhaps try skip_cleanup: true" end end |
#setup_auth ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'lib/dpl/provider/packagecloud.rb', line 19 def setup_auth @username = option(:username) @token = option(:token) @repo = option(:repository) @dist = option(:dist) if [:dist] @creds = ::Packagecloud::Credentials.new(@username, @token) log "Logging into https://packagecloud.io with #{@username}:#{@token[-4..-1].rjust(20, '*')}" end |