iOS fastlane自动打包

2018-12-22  本文已影响3人  搞好关系

1 cd 项目根目录

fastlane init

2 选择自定义
3 配置文件

# This file contains the fastlane.tools configuration
# You can find the documentation at https://docs.fastlane.tools
#
# For a list of all available actions, check out
#
#     https://docs.fastlane.tools/actions
#
# For a list of all available plugins, check out
#
#     https://docs.fastlane.tools/plugins/available-plugins
#

# Uncomment the line if you want fastlane to automatically update itself
# update_fastlane

default_platform(:ios)


#targets = ['ElbC', 'ElbT', 'ElbF']
targets = ['ElbALL', 'ElbC', 'ElbC online', 'ElbF', 'ElbF online', 'ElbT', 'ElbT online']


ALL_DIR = Time.now.strftime("%Y-%m-%d %H:%M:%S")


platform :ios do
  

desc "ElbT 测试版本"
  lane :ElbT do 
    gym(scheme:"ElbT",
        export_method:"enterprise",
        output_directory:"~/Desktop/App/ElbT/",#文件路径
    output_name:"ElbT--#{ALL_DIR}.ipa"

         )
    end
lane :all do
targets.each do |t|
    gym(scheme:t,
        export_method:"enterprise",
        output_directory:"~/Desktop/App/All/#{ALL_DIR}/",#文件路径
    output_name:"#{t}--#{ALL_DIR}.ipa"
         )
end
end
end

4 执行
终端切换至项目下的fastlane


目录预览

4.1 文件介绍
Appfile内部是个人开发者账号的配置
Fastfile 定义的是一个个的lane,执行不同的打包操作

操作实例
单个打包 ElbT
fastlane ElbT

一键打包所有
fastlane all

5 打包过程


终端执行过程截图
打包成功
部分打包结果截图

6 结束


结果汇总

更新打包完成邮件自动发送

# This file contains the fastlane.tools configuration
# You can find the documentation at https://docs.fastlane.tools
#
# For a list of all available actions, check out
#
#     https://docs.fastlane.tools/actions
#
# For a list of all available plugins, check out
#
#     https://docs.fastlane.tools/plugins/available-plugins
#

# Uncomment the line if you want fastlane to automatically update itself
# update_fastlane

default_platform(:ios)


#targets = ['ElbC', 'ElbT', 'ElbF']
targets = ['ElbALL', 'ElbC', 'ElbC online', 'ElbF', 'ElbF online', 'ElbT', 'ElbT online']


ALL_DIR = Time.now.strftime("%Y-%m-%d-%H-%M-%S")


platform :ios do
  

desc "App打包功能"
  lane :App do
  #删除之前
      # exec "rm -rf rm -rf App"

puts "请按照顺序选择(从0开始):"
for index in 0 .. targets.length - 1 do
    item = targets[index]
    puts "#{index} #{item}\n"
end
$name = STDIN.gets
$name = $name.chomp
puts $name
$name = $name.to_i #转换为数字
while $name <0 || $name > targets.length do
    puts "请按照顺序选择(从0开始):#{targets}"
    $name = STDIN.gets
    $name = $name.chomp
    puts $name
    $name = $name.to_i
end

scheme = targets[$name] #选择的scheme
dest = "#{scheme}--#{ALL_DIR}.ipa"
current_dir = "./fastlane/"
local_dir = "App/ElbT/"
dest_dir = "#{current_dir}#{local_dir}"


#用户上传的文件
file_path = "'./#{local_dir}#{dest}'"
# puts file_path

    gym(scheme:scheme,
       export_method:"enterprise",
        output_directory: dest_dir,#文件路径
    output_name:dest)

puts "输入您的邮箱:\n"
$email_name = STDIN.gets
$email_name = $email_name.chomp

puts "您输入的邮箱是:#{$email_name}\n"

puts "输入您的邮箱密码:\n"
$email_password = STDIN.gets
$email_password = $email_password.chomp
puts "您输入的密码是:#{$email_password}\n"

$command = "python semail.py #{$email_name} #{$email_password} #{file_path}"
puts " 即将发送邮件 ~> #{$command}"
puts "发送请输入:1\n"
$commit = STDIN.gets
$commit = $commit.chomp
if $commit.to_i == 1 then
    #发送邮件
    exec "#{$command}"
    # 执行本地清理删除
        exec "rm -rf rm -rf App"


end
  end
end

对应发送邮件Python脚本

#!/usr/bin/python
# -*- coding: UTF-8 -*-
import smtplib
import sys
from email import encoders
from email.mime.base import MIMEBase
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText


def sendEmail(user, password, filepath, debugLevel=1, subject="App打包更新提醒(系统脚本打包,请勿回复)",
              body="iOS App安装包更新,请大家根据需要进行查收"):
    fromaddr = user
    toaddr = [ "xx@gcx.com" ]  # 接收邮件人员列表
    ccaddr = ["xx@gcx.com"] #抄送的领导列表

 
    msg = MIMEMultipart()
    msg['From'] = fromaddr
    msg['To'] = ",".join(toaddr)
    msg["Cc"] = ",".join(ccaddr)
    # 邮件主题
    msg['Subject'] = subject
    # 邮件正文
    body = body
    attachment = open(filepath, 'rb')
    part = MIMEBase('application', 'octet-stream')
    # 这也可以: part = MIMEBase('application', 'pdf')
    part.set_payload((attachment).read())
    encoders.encode_base64(part)
    part.add_header('Content-Disposition', 'attachment', filename=filepath.split("/")[-1])

    msg.attach(part)

    msg.attach(MIMEText(body, 'plain'))

    try:
        s = smtplib.SMTP_SSL("smtp.gener-tech.com", 465)
        s.login(user, password)
        s.set_debuglevel(debugLevel)
        s.sendmail(fromaddr, toaddr, msg.as_string())
        s.close()

    except Exception as e:
        print 'Exception: send email failed', e

if __name__ == '__main__':
    print sys.argv
    sendEmail(user=sys.argv[1], password=sys.argv[2], filepath=sys.argv[3])

文件配置结构:

文件目录外

打包之后确认

是否发送邮件

文件邮件发送

文件发送预览

查收结果

接受结果
上一篇 下一篇

猜你喜欢

热点阅读