github.com/git-lfs/git-lfs@v2.5.2+incompatible/script/packagecloud.rb (about)

     1  # Pushes all deb and rpm files from ./repos to PackageCloud.
     2  
     3  packagecloud_user = ENV["PACKAGECLOUD_USER"] || "github"
     4  packagecloud_token = ENV["PACKAGECLOUD_TOKEN"] || begin
     5    puts "PACKAGECLOUD_TOKEN env required"
     6    exit 1
     7  end
     8  
     9  require "json"
    10  
    11  packagecloud_ruby_minimum_version = "1.0.4"
    12  begin
    13    gem "packagecloud-ruby", ">=#{packagecloud_ruby_minimum_version}"
    14    require "packagecloud"
    15    puts "Using packagecloud-ruby:#{Gem.loaded_specs["packagecloud-ruby"].version}"
    16  rescue LoadError
    17    puts "Requires packagecloud-ruby >=#{packagecloud_ruby_minimum_version}"
    18    puts %(gem install packagecloud-ruby)
    19    exit 1
    20  end
    21  
    22  credentials = Packagecloud::Credentials.new(packagecloud_user, packagecloud_token)
    23  $client = Packagecloud::Client.new(credentials)
    24  
    25  # matches package directories built by docker to one or more packagecloud distros
    26  # https://packagecloud.io/docs#os_distro_version
    27  $distro_name_map = {
    28    "centos/5" => %w(
    29      el/5
    30    ),
    31    "centos/6" => %w(
    32      el/6
    33    ),
    34    "centos/7" => %w(
    35      el/7
    36      fedora/27
    37      fedora/28
    38      opensuse/42.3
    39      sles/11.4
    40      sles/12.3
    41    ),
    42    "debian/7" => %w(
    43      debian/wheezy
    44      ubuntu/precise
    45    ),
    46    "debian/8" => %w(
    47      debian/jessie
    48      linuxmint/rafaela
    49      linuxmint/rebecca
    50      linuxmint/rosa
    51      ubuntu/trusty
    52      ubuntu/vivid
    53      ubuntu/wily
    54    ),
    55    "debian/9" => %W(
    56      debian/stretch
    57      linuxmint/sarah
    58      linuxmint/serena
    59      linuxmint/sonya
    60      linuxmint/sylvia
    61      linuxmint/tara
    62      ubuntu/xenial
    63      ubuntu/yakkety
    64      ubuntu/zesty
    65      ubuntu/artful
    66      ubuntu/bionic
    67    ),
    68  }
    69  
    70  # caches distro id lookups
    71  $distro_id_map = {}
    72  
    73  def distro_names_for(filename)
    74    $distro_name_map.each do |pattern, distros|
    75      return distros if filename.include?(pattern)
    76    end
    77  
    78    raise "no distro for #{filename.inspect}"
    79  end
    80  
    81  package_files = Dir.glob("repos/**/*.rpm") + Dir.glob("repos/**/*.deb")
    82  package_files.each do |full_path|
    83    next if full_path =~ /repo-release/
    84    pkg = Packagecloud::Package.new(:file => full_path)
    85    distro_names = distro_names_for(full_path)
    86    distro_names.map do |distro_name|
    87      distro_id = $distro_id_map[distro_name] ||= $client.find_distribution_id(distro_name)
    88      if !distro_id
    89        raise "no distro id for #{distro_name.inspect}"
    90      end
    91  
    92      puts "pushing #{full_path} to #{$distro_id_map.key(distro_id).inspect}"
    93      result = $client.put_package("git-lfs", pkg, distro_id)
    94      result.succeeded || begin
    95        raise "packagecloud put_package failed, error: #{result.response}"
    96      end
    97    end
    98  end
    99  
   100  package_files.each do |full_path|
   101    next if full_path.include?("SRPM") || full_path.include?("i386") || full_path.include?("i686")
   102    next unless full_path =~ /\/git-lfs[-|_]\d/
   103    os, distro = case full_path
   104    when /debian\/7/ then ["Debian 7", "debian/wheezy"]
   105    when /debian\/8/ then ["Debian 8", "debian/jessie"]
   106    when /debian\/9/ then ["Debian 9", "debian/stretch"]
   107    when /centos\/5/ then ["RPM RHEL 5/CentOS 5", "el/5"]
   108    when /centos\/6/ then ["RPM RHEL 6/CentOS 6", "el/6"]
   109    when /centos\/7/ then ["RPM RHEL 7/CentOS 7", "el/7"]
   110    end
   111  
   112    next unless os
   113  
   114    puts "[#{os}](https://packagecloud.io/#{packagecloud_user}/git-lfs/packages/#{distro}/#{File.basename(full_path)}/download)"
   115  end