Class: Supply::Uploader

Inherits:
Object
  • Object
show all
Defined in:
lib/supply/uploader.rb

Instance Method Summary collapse

Instance Method Details

#perform_uploadObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/supply/uploader.rb', line 3

def perform_upload
  FastlaneCore::PrintTable.print_values(config: Supply.config, hide_keys: [:issuer], title: "Summary for supply #{Supply::VERSION}")

  client.begin_edit(package_name: Supply.config[:package_name])

  UI.user_error!("No local metadata found, make sure to run `supply init` to setup supply") unless  || Supply.config[:apk] || Supply.config[:apk_paths]

  if 
    UI.user_error!("Could not find folder #{}") unless File.directory? 

    all_languages.each do |language|
      next if language.start_with?('.') # e.g. . or .. or hidden folders
      UI.message("Preparing to upload for language '#{language}'...")

      listing = client.listing_for_language(language)

      (language, listing) unless Supply.config[:skip_upload_metadata]
      upload_images(language) unless Supply.config[:skip_upload_images]
      upload_screenshots(language) unless Supply.config[:skip_upload_screenshots]
      upload_changelogs(language) unless Supply.config[:skip_upload_metadata]
    end
  end

  upload_binaries unless Supply.config[:skip_upload_apk]

  UI.message("Uploading all changes to Google Play...")
  client.commit_current_edit!
  UI.success("Successfully finished the upload to Google Play")
end

#upload_binariesObject



91
92
93
94
95
96
97
98
99
100
101
# File 'lib/supply/uploader.rb', line 91

def upload_binaries
  apk_paths = [Supply.config[:apk]] unless (apk_paths = Supply.config[:apk_paths])

  apk_version_codes = []

  apk_paths.each do |apk_path|
    apk_version_codes.push(upload_binary_data(apk_path))
  end

  update_track(apk_version_codes)
end

#upload_changelog(language, apk_version_code) ⇒ Object



39
40
41
42
43
44
45
46
# File 'lib/supply/uploader.rb', line 39

def upload_changelog(language, apk_version_code)
  path = File.join(, language, Supply::CHANGELOGS_FOLDER_NAME, "#{apk_version_code}.txt")
  if File.exist?(path)
    UI.message("Updating changelog for code version '#{apk_version_code}' and language '#{language}'...")
    apk_listing = ApkListing.new(File.read(path, encoding: 'UTF-8'), language, apk_version_code)
    client.update_apk_listing_for_language(apk_listing)
  end
end

#upload_changelogs(language) ⇒ Object



33
34
35
36
37
# File 'lib/supply/uploader.rb', line 33

def upload_changelogs(language)
  client.apks_version_codes.each do |apk_version_code|
    upload_changelog(language, apk_version_code)
  end
end

#upload_images(language) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/supply/uploader.rb', line 61

def upload_images(language)
  Supply::IMAGES_TYPES.each do |image_type|
    search = File.join(, language, Supply::IMAGES_FOLDER_NAME, image_type) + ".#{IMAGE_FILE_EXTENSIONS}"
    path = Dir.glob(search, File::FNM_CASEFOLD).last
    next unless path

    UI.message("Uploading image file #{path}...")
    client.upload_image(image_path: File.expand_path(path),
                        image_type: image_type,
                          language: language)
  end
end

#upload_metadata(language, listing) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/supply/uploader.rb', line 48

def (language, listing)
  Supply::AVAILABLE_METADATA_FIELDS.each do |key|
    path = File.join(, language, "#{key}.txt")
    listing.send("#{key}=".to_sym, File.read(path, encoding: 'UTF-8')) if File.exist?(path)
  end
  begin
    listing.save
  rescue Encoding::InvalidByteSequenceError => ex
    message = (ex.message || '').capitalize
    UI.user_error!("Metadata must be UTF-8 encoded. #{message}")
  end
end

#upload_screenshots(language) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/supply/uploader.rb', line 74

def upload_screenshots(language)
  Supply::SCREENSHOT_TYPES.each do |screenshot_type|
    search = File.join(, language, Supply::IMAGES_FOLDER_NAME, screenshot_type, "*.#{IMAGE_FILE_EXTENSIONS}")
    paths = Dir.glob(search, File::FNM_CASEFOLD)
    next unless paths.count > 0

    client.clear_screenshots(image_type: screenshot_type, language: language)

    paths.sort.each do |path|
      UI.message("Uploading screenshot #{path}...")
      client.upload_image(image_path: File.expand_path(path),
                          image_type: screenshot_type,
                            language: language)
    end
  end
end