前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >fastlane结合Python 实现 iOS 自动化打包发送邮件通知

fastlane结合Python 实现 iOS 自动化打包发送邮件通知

作者头像
大话swift
发布2019-07-04 11:11:22
1.4K0
发布2019-07-04 11:11:22
举报
文章被收录于专栏:大话swift大话swift

fastlane环境安装的问题大家自行百度,一堆堆的软文咱们在此略过

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 结束

7 添加邮件自动发送功能

邮件发送我们使用的ruby调用shell实现Python发送邮件

ruby打包调整

# 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.xx.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]) 当然我们还缺少一个邮件发送之后的文件清理工作 finally: IPA_DIR = "/".join(os.path.abspath(os.path.dirname(os.getcwd())).split("/"))+"/fastlane/App" shutil.rmtree(IPA_DIR) #Python 删除文件夹(空的非空)的操作是不同的

本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2019-01-29,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 大话swift 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档