fix fastlane for PR build (#2804)

This commit is contained in:
Saturnino Abril
2019-05-22 00:43:48 +08:00
committed by GitHub
parent 1b876fe85d
commit 7fe198aade
2 changed files with 40 additions and 27 deletions

View File

@@ -200,7 +200,7 @@ unsigned-ios: stop pre-build check-style ## Build an unsigned version of the iOS
@cd ios/ && xcodebuild -workspace Mattermost.xcworkspace/ -scheme Mattermost -sdk iphoneos -configuration Release -parallelizeTargets -resultBundlePath ../build-ios/result -derivedDataPath ../build-ios/ CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO
@cd build-ios/ && mkdir -p Payload && cp -R Build/Products/Release-iphoneos/Mattermost.app Payload/ && zip -r Mattermost-unsigned.ipa Payload/
@mv build-ios/Mattermost-unsigned.ipa .
@cd fastlane && bundle exec fastlane upload_file_to_s3 filename:Mattermost-unsigned.ipa os_type:iOS
@cd fastlane && bundle exec fastlane upload_file_to_s3 file:Mattermost-unsigned.ipa os_type:iOS
@rm -rf build-ios/
$(call stop_packager)
@@ -213,7 +213,7 @@ ios-sim-x86_64: stop pre-build check-style ## Build an unsigned x86_64 version o
@cd build-ios/Build/Products/Release-iphonesimulator/ && zip -r Mattermost-simulator-x86_64.app.zip Mattermost.app/
@mv build-ios/Build/Products/Release-iphonesimulator/Mattermost-simulator-x86_64.app.zip .
@rm -rf build-ios/
@cd fastlane && bundle exec fastlane upload_file_to_s3 filename:Mattermost-simulator-x86_64.app.zip os_type:iOS
@cd fastlane && bundle exec fastlane upload_file_to_s3 file:Mattermost-simulator-x86_64.app.zip os_type:iOS
$(call stop_packager)
unsigned-android: stop pre-build check-style prepare-android-build ## Build an unsigned version of the Android app
@@ -221,7 +221,7 @@ unsigned-android: stop pre-build check-style prepare-android-build ## Build an u
@echo "Building unsigned Android app"
@cd fastlane && NODE_ENV=production bundle exec fastlane android unsigned
@mv android/app/build/outputs/apk/unsigned/app-unsigned-unsigned.apk ./Mattermost-unsigned.apk
@cd fastlane && bundle exec fastlane upload_file_to_s3 filename:Mattermost-unsigned.apk os_type:Android
@cd fastlane && bundle exec fastlane upload_file_to_s3 file:Mattermost-unsigned.apk os_type:Android
$(call stop_packager)
test: | pre-run check-style ## Runs tests

View File

@@ -7,6 +7,7 @@ fastlane_require 'json'
skip_docs
configured = false
is_build_pr = false
# Executes before anything else use to setup the script
before_all do |lane, options|
@@ -14,6 +15,7 @@ before_all do |lane, options|
pr = options[:pr]
UI.success("Building #{pr}")
ENV['BRANCH_TO_BUILD'] = pr
is_build_pr = true
end
# Raises an error is git is not clean
@@ -347,6 +349,7 @@ platform :ios do
def build_ios()
app_name = ENV['APP_NAME'] || 'Mattermost Beta'
app_name_sub = app_name.gsub(" ", "_")
config_mode = ENV['BUILD_FOR_RELEASE'] == 'true' ? 'Release' : 'Debug'
method = ENV['IOS_BUILD_EXPORT_METHOD'].nil? || ENV['IOS_BUILD_EXPORT_METHOD'].empty? ? 'ad-hoc' : ENV['IOS_BUILD_EXPORT_METHOD']
@@ -357,7 +360,7 @@ platform :ios do
workspace: './ios/Mattermost.xcworkspace',
export_method: method,
skip_profile_detection: true,
output_name: "#{app_name}.ipa",
output_name: "#{app_name_sub}.ipa",
export_options: {
signingStyle: 'manual',
iCloudContainerEnvironment: 'Production'
@@ -511,10 +514,11 @@ platform :android do
def move_apk_to_root
app_name = ENV['APP_NAME'] || 'Mattermost Beta'
app_name_sub = app_name.gsub(" ", "_")
apk_path = lane_context[SharedValues::GRADLE_APK_OUTPUT_PATH]
unless apk_path.nil?
sh "mv #{apk_path} \"../#{app_name}.apk\""
sh "mv #{apk_path} \"../#{app_name_sub}.apk\""
end
end
@@ -584,6 +588,9 @@ def submit_to_store
apk_path = lane_context[SharedValues::GRADLE_APK_OUTPUT_PATH]
ipa_path = lane_context[SharedValues::IPA_OUTPUT_PATH]
app_name = ENV['APP_NAME'] || 'Mattermost Beta'
app_name_sub = app_name.gsub(" ", "_")
s3_region = ENV['AWS_REGION']
s3_bucket = ENV['AWS_BUCKET_NAME']
@@ -600,7 +607,7 @@ def submit_to_store
build_number = android_get_version_code(gradle_file: './android/app/build.gradle')
s3_folder = "#{ENV['AWS_FOLDER_NAME']}/#{version_number}/#{build_number}"
public_link = "https://#{s3_bucket}/#{s3_folder}/Mattermost.apk"
public_link = "https://#{s3_bucket}/#{s3_folder}/#{app_name_sub}}.apk"
# Send a build message to Mattermost
pretext = '#### New Android released ready to be published'
@@ -633,7 +640,7 @@ def submit_to_store
build_number = get_build_number(xcodeproj: './ios/Mattermost.xcodeproj')
s3_folder = "#{ENV['AWS_FOLDER_NAME']}/#{version_number}/#{build_number}"
public_link = "https://#{s3_bucket}/#{s3_folder}/Mattermost.ipa"
public_link = "https://#{s3_bucket}/#{s3_folder}/#{app_name_sub}.ipa"
# Send a build message to Mattermost
pretext = '#### New iOS released ready to be published'
@@ -680,36 +687,37 @@ end
desc 'Upload file to s3'
lane :upload_file_to_s3 do |options|
os_type = options[:os_type]
filename = options[:filename]
filename_plist = ""
file = options[:file]
file_plist = ""
if filename.nil? || filename.empty?
UI.message("Filename empty")
if file.nil? || file.empty?
app_name = ENV['APP_NAME'] || 'Mattermost Beta'
filename = app_name.gsub(" ", "_")
if os_type == 'Android'
filename = "#{app_name}.apk"
file = "#{filename}.apk"
elsif os_type == 'iOS'
filename = "#{app_name}.ipa"
filename_plist = "#{app_name}.plist"
file = "#{filename}.ipa"
file_plist = "#{filename}.plist"
end
end
build_folder_path = Dir[File.expand_path('..')].first
file_path = "#{build_folder_path}/#{filename}"
file_path = "#{build_folder_path}/#{file}"
unless ENV['AWS_BUCKET_NAME'].nil? || ENV['AWS_BUCKET_NAME'].empty? || ENV['AWS_REGION'].nil? || ENV['AWS_REGION'].empty? || file_path.nil?
s3_region = ENV['AWS_REGION']
s3_bucket = ENV['AWS_BUCKET_NAME']
s3_folder = ''
if ENV['BRANCH_TO_BUILD'] == 'pr'
if is_build_pr
s3_folder = "#{ENV['AWS_FOLDER_NAME']}/#{ENV['BRANCH_TO_BUILD']}"
else
if os_type == 'Android'
version_number = android_get_version_name(gradle_file: './android/app/build.gradle')
build_number = android_get_version_code(gradle_file: './android/app/build.gradle')
else
elsif os_type == 'iOS'
version_number = get_version_number(xcodeproj: './ios/Mattermost.xcodeproj', target: 'Mattermost')
build_number = get_build_number(xcodeproj: './ios/Mattermost.xcodeproj')
end
@@ -718,25 +726,30 @@ lane :upload_file_to_s3 do |options|
end
s3 = Aws::S3::Resource.new(region: s3_region)
file_obj = s3.bucket(s3_bucket).object("#{s3_folder}/#{filename}")
file_obj = s3.bucket(s3_bucket).object("#{s3_folder}/#{file}")
file_obj.upload_file("#{file_path}")
if ENV['BRANCH_TO_BUILD'] == 'pr'
plist_template = File.read('plist.erb')
plist_body = ERB.new(plist_template).result(binding)
if is_build_pr
if os_type == 'Android'
install_url = "https://#{s3_bucket}/#{s3_folder}/#{file}"
elsif os_type == 'iOS'
current_build_number = get_build_number(xcodeproj: './ios/Mattermost.xcodeproj')
plist_template = File.read('plist.erb')
plist_body = ERB.new(plist_template).result(binding)
plist_obj = s3.bucket(s3_bucket).object("#{s3_folder}/#{filename_plist}")
plist_obj.put(body: plist_body)
plist_obj = s3.bucket(s3_bucket).object("#{s3_folder}/#{file_plist}")
plist_obj.put(body: plist_body)
ios_plist_install_url = "itms-services://?action=download-manifest&url=https://#{s3_bucket}/#{s3_folder}/#{filename}.plist"
install_url = "itms-services://?action=download-manifest&url=https://#{s3_bucket}/#{s3_folder}/#{file_plist}"
end
qa_build_message({
:os_type => os_type,
:install_url => ios_plist_install_url
:install_url => install_url
})
end
UI.success("S3 bucket @#{s3_bucket}, object @#{s3_folder}/#{filename}")
UI.success("S3 public path: https://#{s3_bucket}/#{s3_folder}/#{filename}")
UI.success("S3 bucket @#{s3_bucket}, object @#{s3_folder}/#{file}")
UI.success("S3 public path: https://#{s3_bucket}/#{s3_folder}/#{file}")
end
end