模塊化很好,但若是須要同時修改多個Pod就比較繁瑣了。git
先在Example裏修改了多個Pod的code,再手動copy到各個Pod比較麻煩,還容易漏
如下ruby腳本一鍵完成api
須要先把各個Pod倉庫Clone下來並切換到對應的分支,分支不對 不會同步的ruby
TODO:
一、用腳本實現Clone和切換分支「easy」
二、經過gitlab api分析提交文件列表,在持續集成服務器執行同步Pod操做任務,並結果通知到提交者bash
# frozen_string_literal: true
require 'pathname'
# gem install git
require 'git'
require 'fileutils'
# 目錄結構以下
# ├── ABCPods1
# │ ├── ABCPods1
# │ │ └── Code.m
# │ └── ABCPods1.podspec
# ├── ABCPods2
# │ ├── ABCPods1
# │ │ └── Code.m
# │ └── ABCPods1.podspec
# ├── ABCPods3
# │ ├── ABCPods3
# │ │ └── Code.m
# │ └── ABCPods3.podspec
# └── Example
# └── Pods
# ├── ABCPods1
# │ └── Code.m
# ├── ABCPods2
# │ └── Code.m
# └── ABCPods3
# └── Code.m
# 在Example裏修改了多個模塊的code。再手動copy到各個Pod比較麻煩,還容易漏
# 如下腳本一鍵完成
# 須要先把各個Pod手動切換到對應的分支,分支不對 不會同步的
Git.configure do |config|
config.binary_path = '/usr/local/bin/git'
end
# 變量設置
pods_path = Pathname.new 'path/to/Example/Pods'
git_container = Pathname.new '/path/to/gitcontainer/'
start_filter = 'ABCPods'
filter_branch = 'test_branch_name'
# 找到文件夾列表
all_dir = pods_path.children.select { |e| e.basename.to_s.start_with?(start_filter) }
# 組裝數據
all_dir_map = all_dir.map { |e| [e, git_container + e.basename + e.basename] }
all_dir_map.each do |path_list|
# path_list 第一個是主工程的文件夾 第二個是Pod的代碼文件夾
dest_item = path_list.last
# next unless dest_item.basename.to_s.eql? 'ABCPods1' # use test
next unless FileTest.exist? dest_item.parent
g = Git.open dest_item.parent
next unless g.current_branch.eql? filter_branch
puts "#{path_list.first} copy to #{dest_item}"
FileUtils.rm_r(dest_item, force: true)
src = path_list.first + path_list.first.basename
dest = dest_item.parent
FileUtils.cp_r(src, dest)
# 打印出有修改的,根據日誌本身Review後提交
status_output = `git -C #{dest} status`
puts status_output unless status_output.include? 'working tree clean'
end
複製代碼