Compare commits

...

3 Commits

Author SHA1 Message Date
DashaGitHub 8502c4879b Added bange for icon 2019-09-24 11:29:29 +03:00
Даша e28259b1ed Added options in screenshots lane 2019-09-19 09:25:21 +03:00
Даша 9fbd031196 Add script for download screenshots 2019-06-10 10:33:55 +03:00
2 changed files with 121 additions and 0 deletions

View File

@ -0,0 +1,98 @@
require 'net/http'
require 'rest-client'
require 'json'
require 'fileutils'
require 'docopt'
def screenshots(token, file, folder)
baseUrl = 'https://api.figma.com/v1/'
filesUrl = 'files/'
imageUrl = 'images/'
figmaToken = token;
figmaFile = file;
imagesFolder = folder;
imagesFormat = "png"
####################################################
puts '🌿 Start.'
####################################################
####################################################
puts '🌿 Get all nodes for file...'
####################################################
# 2. Get all nodes for file with screenshots
response = RestClient::Request.new(
:method => :get,
:url => baseUrl + filesUrl + figmaFile,
:headers => {
'X-FIGMA-TOKEN': figmaToken
},
:verify_ssl => false
).execute
results = JSON.parse(response.to_str)
####################################################
puts '🌿 Get url for image...'
####################################################
# 3. Create dictionary with url screenshots
screenshotPage = String.new
pages = results['document']['children']
for tempPage in pages
if tempPage['name'] == 'Screenshots' then
screenshotPage = tempPage
break
end
end
screenshotIds = String.new
screenshotFrames = Hash.new
groups = screenshotPage['children']
for tempGroup in groups
if tempGroup['type'] == 'GROUP' then
groupName = tempGroup['name']
nodes = tempGroup['children']
for tempNode in nodes
if tempNode['type'] == 'FRAME' then
screenshotFrames[tempNode['id']] = '/' + groupName + '/' + tempNode['name']
screenshotIds += tempNode['id'] + ','
end
end
end
end
# 4. Get url for images
response = RestClient::Request.new(
:method => :get,
:url => baseUrl+imageUrl+figmaFile,
:headers => {
'X-FIGMA-TOKEN': figmaToken,
:params => {:ids => screenshotIds[0..-2], :scale => 3, :format => imagesFormat},
},
:verify_ssl => false
).execute
results = JSON.parse(response.to_str)
####################################################
puts '🌿 Download images...'
####################################################
# 5. Download images in folders
imagesUrl = results['images']
imagesUrl.each do |key, value|
data = RestClient.get(value).body
folder = (imagesFolder + screenshotFrames[key]).chop
FileUtils.mkdir_p folder
File.write(imagesFolder + screenshotFrames[key] + '.' + imagesFormat, data, mode: 'wb')
end
####################################################
puts '🌿 Finish. Hooray!'
####################################################
end

View File

@ -1,3 +1,5 @@
import '../build-scripts/xcode/aux_scripts/screenshots.rb'
$appName = File.basename(Dir['../*.xcworkspace'].first, '.*') $appName = File.basename(Dir['../*.xcworkspace'].first, '.*')
private_lane :installDependencies do |options| private_lane :installDependencies do |options|
@ -45,6 +47,13 @@ private_lane :uploadToFabric do |options|
) )
end end
lane :exportStoreScreenshots do |options|
figmaToken = options[:figmaToken]
figmaFile = options[:figmaFile]
imagesFolder = File.expand_path "../fastlane/screenshots"
screenshots(figmaToken, figmaFile, imagesFolder)
end
private_lane :uploadToAppStore do |options| private_lane :uploadToAppStore do |options|
upload_to_app_store( upload_to_app_store(
username: options[:username] || options[:apple_id], username: options[:username] || options[:apple_id],
@ -85,6 +94,7 @@ private_lane :buildConfiguration do |options|
options[:workspace] = "./#{appName}.xcworkspace" options[:workspace] = "./#{appName}.xcworkspace"
installDependencies(options) installDependencies(options)
addBadge(options)
if !(options[:uploadToFabric] || options[:uploadToAppStore]) if !(options[:uploadToFabric] || options[:uploadToAppStore])
options = merge_options_with_config_file(options) options = merge_options_with_config_file(options)
@ -107,12 +117,14 @@ private_lane :buildConfiguration do |options|
if options[:uploadToAppStore] if options[:uploadToAppStore]
options[:compileBitcode] = options[:compileBitcode].nil? ? true : options[:compileBitcode] options[:compileBitcode] = options[:compileBitcode].nil? ? true : options[:compileBitcode]
options[:include_symbols] = options[:include_symbols].nil? ? true : options[:include_symbols] options[:include_symbols] = options[:include_symbols].nil? ? true : options[:include_symbols]
options = options.merge(get_screenshots_options())
options = options.merge(make_options_for_lane_name("AppStore")) options = options.merge(make_options_for_lane_name("AppStore"))
options = merge_options_with_config_file(options) options = merge_options_with_config_file(options)
syncCodeSigning(options) syncCodeSigning(options)
buildArchive(options) buildArchive(options)
exportStoreScreenshots(options)
uploadToAppStore(options) uploadToAppStore(options)
end end
end end
@ -174,6 +186,12 @@ lane :syncCodeSigning do |options|
) )
end end
lane :addBadge do |options|
versionNumber = options[:versionNumber]
buildNumber = options[:buildNumber]
add_badge(shield: "#{versionNumber}-#{buildNumber}-blue", dark: false)
end
private_lane :openKeychain do |options| private_lane :openKeychain do |options|
if is_ci? if is_ci?
# workaround to avoid duplication problem # workaround to avoid duplication problem
@ -213,6 +231,11 @@ def get_keychain_options(options)
return {:keychain_name => keychain_name, :keychain_password => keychain_password} return {:keychain_name => keychain_name, :keychain_password => keychain_password}
end end
def get_screenshots_options()
figmaTokenAndFileOptions = load_options_from("screenshots.yaml")
return figmaTokenAndFileOptions
end
def configuration_type_from_lane_name(lane_name) def configuration_type_from_lane_name(lane_name)
case case
when lane_name.start_with?("Enterprise") when lane_name.start_with?("Enterprise")