XKit iOS

XKit工程为应用客户端iOS的统一工程,涵盖RoomKit,PK直播,语聊房,IMUIKit,呼叫组件等工程。

工程目录

子工程目录规范

┌── ModuleName                    # 大模块名,单词首字母大写                
│   ├── README.md               # 大模块的介绍
│   ├── SubModule1              # 小模块,比如某个Kit,单词首字母大写
│   │   ├── README.md         # 小模块的介绍
│   │   ├── CHANGELOG.md      # 小模块的更新日志(非必要)
│   │   └── SourceCode            # 源代码
│   └── SubModule2              # 小模块,比如Kit匹配的Demo
│
└── NERoomKit

CI/CD流程

GitLab地址

提交

提交代码触发脚本,脚本地址

根据分支名决定对哪个工程进行编译,所以如有新工程则需要同步修改脚本中的相应位置

if (env.gitlabBranch =~ "roomkit") {
    echo "buildBranch feature/roomkit"
    sh "build_tools/common/ios/build.sh --app_name XKit --configuration ${params.configuration} --export_method ${params.export_method} --include_bitcode ${params.include_bitcode} --bundle_id com.netease.yunxin.app.roomkit --target RoomKitExample --scheme RoomKitExample --subTaskId ${params.subTaskId}"
} else if (env.gitlabBranch =~ "livekit") {
    echo "buildBranch feature/livekit"
    sh "build_tools/common/ios/build.sh --app_name XKit --configuration ${params.configuration} --export_method ${params.export_method} --include_bitcode ${params.include_bitcode} --bundle_id com.netease.NEOnlinePKDemo --target NEOnlinePKExample --scheme NEOnlinePKExample --subTaskId ${params.subTaskId}"
} else if (env.gitlabBranch =~ "karaoke") {
    echo "buildBranch feature/karaoke"
    sh "build_tools/common/ios/build.sh --app_name XKit --configuration ${params.configuration} --export_method ${params.export_method} --include_bitcode ${params.include_bitcode} --bundle_id com.netease.yunxin.app.karaoke --target NEKaraoke --scheme NEKaraoke --subTaskId ${params.subTaskId}"
} else if (env.gitlabBranch =~ "callkit") {
    echo "buildBranch callkit ci"
    sh "cd AllInOne/AllInOneExample &&  ../../build_tools/common/ios/build.sh --app_name AllInOneExample --configuration ${params.configuration} --export_method ${params.export_method} --include_bitcode ${params.include_bitcode} --bundle_id com.netease.NELiteAVDemo --target NLiteAVDemo --scheme NLiteAVDemo --subTaskId ${params.subTaskId}"
} else if (env.gitlabBranch =~ "voice_room" || env.gitlabBranch =~ "voiceroom") {
    echo "buildBranch voice_room ci"
    sh "build_tools/common/ios/build.sh --app_name XKit --configuration ${params.configuration} --export_method ${params.export_method} --include_bitcode ${params.include_bitcode} --bundle_id com.netease.yunxin.app.chatroom --target LiveAudioRoom --scheme LiveAudioRoom --subTaskId ${params.subTaskId}"
} else {
    echo "buildBranch feature/chatKit ci"
    sh "build_tools/common/ios/build.sh --app_name XKit --scheme IMUIKitExample --target IMUIKitExample --configuration ${params.configuration} --export_method ${params.export_method} --include_bitcode ${params.include_bitcode} --bundle_id com.netease.yunxin.app.im --target IMUIKitExample --scheme IMUIKitExample --subTaskId ${params.subTaskId}"
}

每次提交都会触发format与license检查命令,如不通过则会导致CI失败,所以建议提交前在本地进行format操作,命令如下:

brew install clang-format swiftformat shyaml
dart pub global activate --source git ssh://git@g.hz.netease.com:22222/yunxin-app/xkit-tools/tool.git
dart pub global run xkit_tools format --fail-on-change

关于license,XKit工程已经配置了宏定义在 XKit.xcworkspace/xcshareddata/IDETemplateMacros.plist,只要是新创建的文件都会自带license信息,但是直接拖入的文件仍然需要手动修改

Merge Request

MR的流程基本与普通提交一致,为了确保代码质量,MR中多了Lint的步骤

brew install swiftlint
gem install xcpretty
brew install infer
dart pub global activate --source git ssh://git@g.hz.netease.com:22222/yunxin-app/xkit-tools/tool.git
rm -f Podfile.lock
bundle exec pod install --repo-update
git fetch origin ${env.gitlabTargetBranch}
dart pub global run xkit_tools analyze --packages-for-branch

Lint的逻辑为扫描该次MR的修改文件的路径,对应到自定的包概念(即上面说的Common,NERoomKit等),以模块的Demo工程为入口,对模块分别进行OC与Swift的Lint检查,检查不过则无法合入代码。Lint与format的处理都通过另外一组命令来执行,有兴趣的同学可以参考XKit-Tools

如需让脚本忽略,则在xkit.yaml文件中进行ignore的配置,通常情况下,我们要保证所有模块都执行lint检查

packages:
  ios: [LiveAudioRoom,NEKaraoke,RoomKitExample]

ignore:
  ios: [XKit,Pods,NEOnlinePKExample,NEKaraokeKitTest,NEVoiceRoomKitTest,IMUIKitExample,NLiteAVDemo]

打包

目前打包的入口主要有两个,一个是通过overmind(实际通过Jenkins),另外一个是直接通过Jenkins。

Jenkins

字段 解释
buildBranch 打包分支
projectPath 需要打哪个工程的包
configuration debug还是release
export_method 签名方式
backup_dir 包上传地址
imVersion 指定IM版本,不指定则使用pod文件中默认的
rtcVersion 指定RTC版本,不指定则使用pod文件中默认的

最终产物会上传到 内部存储

根目录隐藏文件

文件名 作用
.swiftlint.yml swiftlint规则配置文件
.inferconfig oclint规则配置文件
.jazzy.yaml 用于用Swift编写的kit的文档导出
.clang-format OC代码format规则文件
.swiftformat Swift代码format规则文件