1.前言
iOS开发肯定对pod私有库不陌生,大部分App组件化都是通过pod私有库完成的。当有多个pod私有库、快速迭代的时候,升级就成为了一个麻烦的事情。
pod私有库升级涉及到了两个git仓库,spec repo 和 lib repo ,每次我们修改完代码,需要验证,修改.podspec文件版本号,然后推送到spce仓库。
我希望代码修改完成,提交后打上tag,能够自动生成一个新的版本供app使用。我们借助github action完成自动化操作
1 .pod私有库可以参考这篇文章
2.如果你没使用过github action, 并不影响你使用。本文会从头开始带你一步步完成整个流程。在有空的时候可以对github action进行一个全面的了解,链接
3. 若你现在已经有了spec仓库和lib仓库,可以忽略前面的创建步骤,直接看第4步为项目添加github action
2. 创建spec repo
在github上新建一个仓库,勾选`Initialize this repository with a README`。创建完成后暂时不用进行其他操作
3. 创建lib repo
1. 运行命令 pod lib create ninja-kit ,根据提示创建好lib工程。
Cloning `https://github.com/CocoaPods/pod-template.git` into `ninja-kit`.
Configuring ninja-kit template.
! Before you can create a new library we need to setup your git credentials.
What is your email?
> your email
! Setting your email in git to 356485255@qq.com
git config user.email "356485255@qq.com"
------------------------------
To get you started we need to ask a few questions, this should only take a minute.
If this is your first time we recommend running through with the guide:
- https://guides.cocoapods.org/making/using-pod-lib-create.html
( hold cmd and double click links to open in a browser. )
What platform do you want to use?? [ iOS / macOS ]
> iOS
What language do you want to use?? [ Swift / ObjC ]
> Objc
Would you like to include a demo application with your library? [ Yes / No ]
> NO
Which testing frameworks will you use? [ Specta / Kiwi / None ]
> None
Would you like to do view based testing? [ Yes / No ]
> NO
What is your class prefix?
> NJ
Running pod install on your new library.
2. 同时在github上新建一个仓库,作为lib的remote
git remote add origin https://github.com/wlixcc/ninja-kit.git 3. 验证spec,确保你的spec文件验证通过。 这是第一次创建lib仓库,很多配置可能需要你修改spec文件
pod lib lint *.podspec 4. 为lib项目添加github action
1. 在pod lib项目下创建.github 及 workflows文件夹。然后创建main.yml 。
你也可以从这里直接copy
main.yml内容如下,你根据注释修改spec_repo_url以及spec_file_path
name: 'update pob lib'
#在有新的tag的时候触发action
on:
create:
tags:
- v*
jobs:
pod_lib_update:
runs-on: macos-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: pod lib update
uses: wlixcc/pod-lib-update-action@1.0.0
with:
# spec仓库路径,确保有仓库的访问权限
spec_repo_url: https://wlixcc:${{secrets.ACCESS_TOKEN}}@github.com/wlixcc/ninja-specs.git
# podspec的相对路径, 这里表示仓库根目录下 'ninja-kit.podspec' 文件
spec_file_path: /ninja-kit.podspec其中${{secrets.ACCESS_TOKEN}},若不了解可以参考这里
完成之后我们提交代码,并打上tag 0.1.0 推送到remote5. 查看运行结果
- 来到github仓库,点击
action,我们可以看到运行结果
2. 在spec repo下,我们可以看到action已经为我们自动添加了一个版本
6. 总结
1. 在你的pod私有库中添加action,修改main.yml
2. 提交代码
3. 打tag并推送
4. 查看运行结果
注意此action只对spec的版本号进行调整并推送到spec仓库中,若你的spec文件有其他修改,仍需要手动修改。
x.项目链接
1. action
2.pod lib