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
32
33
34
35
36
37
38
39
# 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]

  promote_track if Supply.config[:track_promote_to]

  if Supply.config[:validate_only]
    UI.message("Validating all changes with Google Play...")
    client.validate_current_edit!
    UI.success("Successfully validated the upload to Google Play")
  else
    UI.message("Uploading all changes to Google Play...")
    client.commit_current_edit!
    UI.success("Successfully finished the upload to Google Play")
  end
end

#promote_trackObject



41
42
43
44
45
46
47
48
49
# File 'lib/supply/uploader.rb', line 41

def promote_track
  version_codes = client.track_version_codes(Supply.config[:track])
  # the actual value passed for the rollout argument does not matter because it will be ignored by the Google Play API
  # but it has to be between 0.05 and 0.5 to pass the validity check. So we are passing the default value 0.1
  client.update_track(Supply.config[:track], 0.1, nil)
  version_codes.each do |apk_version_code|
    client.update_track(Supply.config[:track_promote_to], Supply.config[:rollout], apk_version_code)
  end
end

#upload_binariesObject



109
110
111
112
113
114
115
116
117
118
119
# File 'lib/supply/uploader.rb', line 109

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



57
58
59
60
61
62
63
64
# File 'lib/supply/uploader.rb', line 57

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



51
52
53
54
55
# File 'lib/supply/uploader.rb', line 51

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



79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/supply/uploader.rb', line 79

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



66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/supply/uploader.rb', line 66

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



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/supply/uploader.rb', line 92

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