Class: Supply::Uploader

Inherits:
Object
  • Object
show all
Defined in:
supply/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
40
41
42
43
44
45
46
47
48
# File 'supply/lib/supply/uploader.rb', line 3

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

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

  verify_config!

  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

  apk_version_codes = []
  apk_version_codes.concat(upload_apks) unless Supply.config[:skip_upload_apk]
  apk_version_codes.concat(upload_bundles) unless Supply.config[:skip_upload_aab]
  upload_mapping(apk_version_codes)

  apk_version_codes.concat(Supply.config[:version_codes_to_retain]) if Supply.config[:version_codes_to_retain]

  # Only update tracks if we have version codes
  # Updating a track with empty version codes can completely clear out a track
  update_track(apk_version_codes) unless apk_version_codes.empty?

  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



65
66
67
68
69
70
71
# File 'supply/lib/supply/uploader.rb', line 65

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.0 and 1.0 to pass the validity check. So we are passing the default value 0.1
  client.update_track(Supply.config[:track], 0.1, nil) if Supply.config[:deactivate_on_promote]
  client.update_track(Supply.config[:track_promote_to], Supply.config[:rollout] || 0.1, version_codes)
end

#upload_apksObject



134
135
136
137
138
139
140
141
142
143
144
145
# File 'supply/lib/supply/uploader.rb', line 134

def upload_apks
  apk_paths = [Supply.config[:apk]] unless (apk_paths = Supply.config[:apk_paths])
  apk_paths.compact!

  apk_version_codes = []

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

  return apk_version_codes
end

#upload_bundlesObject



156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# File 'supply/lib/supply/uploader.rb', line 156

def upload_bundles
  aab_paths = [Supply.config[:aab]] unless (aab_paths = Supply.config[:aab_paths])
  return [] unless aab_paths
  aab_paths.compact!

  aab_version_codes = []

  aab_paths.each do |aab_path|
    UI.message("Preparing aab at path '#{aab_path}' for upload...")
    bundle_version_code = client.upload_bundle(aab_path)

    if 
      all_languages.each do |language|
        next if language.start_with?('.') # e.g. . or .. or hidden folders
        upload_changelog(language, bundle_version_code)
      end
    end

    aab_version_codes.push(bundle_version_code)
  end

  return aab_version_codes
end

#upload_changelog(language, version_code) ⇒ Object



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

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

#upload_changelogs(language) ⇒ Object



73
74
75
76
77
78
79
80
# File 'supply/lib/supply/uploader.rb', line 73

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

#upload_images(language) ⇒ Object



104
105
106
107
108
109
110
111
112
113
114
115
# File 'supply/lib/supply/uploader.rb', line 104

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_mapping(apk_version_codes) ⇒ Object



147
148
149
150
151
152
153
154
# File 'supply/lib/supply/uploader.rb', line 147

def upload_mapping(apk_version_codes)
  mapping_paths = [Supply.config[:mapping]] unless (mapping_paths = Supply.config[:mapping_paths])
  mapping_paths.zip(apk_version_codes).each do |mapping_path, version_code|
    if mapping_path
      client.upload_mapping(mapping_path, version_code)
    end
  end
end

#upload_metadata(language, listing) ⇒ Object



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

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



117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'supply/lib/supply/uploader.rb', line 117

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

#verify_config!Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'supply/lib/supply/uploader.rb', line 50

def verify_config!
  unless  || Supply.config[:apk] || Supply.config[:apk_paths] || Supply.config[:aab] || Supply.config[:aab_paths] || (Supply.config[:track] && Supply.config[:track_promote_to])
    UI.user_error!("No local metadata, apks, aab, or track to promote were found, make sure to run `fastlane supply init` to setup supply")
  end

  # Can't upload both at apk and aab at same time
  # Need to error out users when there both apks and aabs are detected
  apk_paths = [Supply.config[:apk], Supply.config[:apk_paths]].flatten.compact
  could_upload_apk = !apk_paths.empty? && !Supply.config[:skip_upload_apk]
  could_upload_aab = Supply.config[:aab] && !Supply.config[:skip_upload_aab]
  if could_upload_apk && could_upload_aab
    UI.user_error!("Cannot provide both apk(s) and aab - use `skip_upload_apk`, `skip_upload_aab`, or  make sure to remove any existing .apk or .aab files that are no longer needed")
  end
end