Optimize fastlane snapshot by more than 50%
Published in
1 min readFeb 9, 2020
Snapshot is a great tool for generating screenshots. However when you want to generate for so many devices and languages, it becomes a very long build process.
For example in this case:
lane :generate_screenshots do |options|
scheme = "GenerateScreenshots-UITests"
path = "~/Library/Developer/Xcode/DerivedData/AppDevelopment"
devices = [
"iPhone X",
"iPhone Xs Max"
]
snapshot(
devices: devices,
derived_data_path: path,
languages: [
"en-US",
"nb-NO"
],
output_directory: "fastlane/screenshots",
scheme: scheme
)
end
Snapshot will call this method 4 times!
set -o pipefail && xcodebuild -scheme GenerateScreenshots-UITests -project ./My.xcodeproj -derivedDataPath '~/Library/Developer/Xcode/DerivedData/' -destination 'platform=iOS Simulator,name=iPhone Xs Max,OS=12.4' FASTLANE_SNAPSHOT=YES clean build test
That means your server builds your app 4 times and runs the tests 4 times
Our proposed solution is to build one time and test 4 times.
lane :generate_screenshots do |options|
scheme = "GenerateScreenshots-UITests"
path = "~/Library/Developer/Xcode/DerivedData/AppDevelopment"
xcversion
devices = [
"iPhone X",
"iPhone Xs Max"
]# building before running tests is faster because snapshot is building for each device
run_tests(
build_for_testing: true,
code_coverage: false,
derived_data_path: path,
devices: devices,
scheme: scheme
)
screenshots_output_directory = "fastlane/screenshots"
snapshot(
devices: devices,
derived_data_path: path,
languages: [
"en-US",
"nb-NO"
],
output_directory: screenshots_output_directory,
scheme: scheme,
test_without_building: true
)
end
For this example, 18 min was reduced to 9 min.