| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
packagecloud_user = ENV["PACKAGECLOUD_USER"] || "github" |
| 5 |
packagecloud_token = ENV["PACKAGECLOUD_TOKEN"] || begin |
| 6 |
puts "PACKAGECLOUD_TOKEN env required" |
| 7 |
exit 1 |
| 8 |
end |
| 9 |
|
| 10 |
require "json" |
| 11 |
require_relative 'lib/distro' |
| 12 |
|
| 13 |
packagecloud_ruby_minimum_version = "1.0.4" |
| 14 |
begin |
| 15 |
gem "packagecloud-ruby", ">=#{packagecloud_ruby_minimum_version}" |
| 16 |
require "packagecloud" |
| 17 |
puts "Using packagecloud-ruby:#{Gem.loaded_specs["packagecloud-ruby"].version}" |
| 18 |
rescue LoadError |
| 19 |
puts "Requires packagecloud-ruby >=#{packagecloud_ruby_minimum_version}" |
| 20 |
puts %(gem install packagecloud-ruby) |
| 21 |
exit 1 |
| 22 |
end |
| 23 |
|
| 24 |
credentials = Packagecloud::Credentials.new(packagecloud_user, packagecloud_token) |
| 25 |
$client = Packagecloud::Client.new(credentials) |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
$distro_name_map = DistroMap.new.distro_name_map |
| 30 |
|
| 31 |
|
| 32 |
$distro_id_map = {} |
| 33 |
|
| 34 |
def distro_names_for(filename) |
| 35 |
$distro_name_map.each do |pattern, distros| |
| 36 |
return distros if filename.include?(pattern) |
| 37 |
end |
| 38 |
|
| 39 |
raise "no distro for #{filename.inspect}" |
| 40 |
end |
| 41 |
|
| 42 |
package_files = Dir.glob("repos/**/*.rpm") + Dir.glob("repos/**/*.deb") |
| 43 |
package_files.each do |full_path| |
| 44 |
next if full_path =~ /repo-release/ |
| 45 |
pkg = Packagecloud::Package.new(:file => full_path) |
| 46 |
distro_names = distro_names_for(full_path) |
| 47 |
distro_names.map do |distro_name| |
| 48 |
distro_id = $distro_id_map[distro_name] ||= $client.find_distribution_id(distro_name) |
| 49 |
if !distro_id |
| 50 |
raise "no distro id for #{distro_name.inspect}" |
| 51 |
end |
| 52 |
|
| 53 |
puts "pushing #{full_path} to #{$distro_id_map.key(distro_id).inspect}" |
| 54 |
result = $client.put_package("git-lfs", pkg, distro_id) |
| 55 |
result.succeeded || begin |
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
if result.response != '{"filename":["has already been taken"]}' |
| 61 |
raise "packagecloud put_package failed, error: #{result.response}" |
| 62 |
end |
| 63 |
end |
| 64 |
end |
| 65 |
end |