Example is a shell project. When the requirement involves the modification of multiple modules, I wrote a Ruby script to facilitate the submission of the code of each Pod
- Rule 1: The directory structure is as follows
- Rule 2: Commit logs to
PodSync:
At the beginning - The script can be configured on the continuous integration server by changing the value of work_path.
- TODO1: Execution status notification, because each Pod synchronizes after the commit changes, shell project should
pod update
- TODO2: Use the Gitlab Api to submit code directly without clone
├ ─ ─ Podfile ├ ─ ─ Podfile. Lock ├ ─ ─ the Pods │ ├ ─ ─ ABCPods1 │ │ └ ─ ─ Code1. M │ ├ ─ ─ ABCPods2 │ │ └ ─ ─ Code2. M │ ├ ─ ─ ABCPods3 │ │ └ ─ ─ Code3. M │ ├ ─ ─ Headers │ ├ ─ ─ the Local Podspecs │ ├ ─ ─ the Manifest. Lock │ ├ ─ ─ the Pods. Xcodeproj │ └ ─ ─ Target Support Files ├ ─ ─ Example │ ├── class.htm │ ├── class.htm. M ├── class.htm │ ├── class.htmCopy the code
ABCPods are created using pod Lib Create, and the directory structure is the same. ABCPods has the same name under ABCPods and the module code under ABCPods is similar:
├── exercises │ ├── exercises │ ├─ code1.mCopy the code
The Automatic synchronization Ruby script is as follows:
# frozen_string_literal: true
require 'pathname'
require 'git'
require 'fileutils'
work_path = Pathname.new '... /path/to/Example'
url_config = { 'ABCPods1'= >'http://example.com/ios_code/ABCPods1.git'.'ABCPods2'= >'http://example.com/ios_code/ABCPods2.git'.'ABCPods3'= >'http://example.com/ios_code/ABCPods3.git' }
Git.configure do |config|
config.binary_path = '/usr/local/bin/git'
end
g = Git.open work_path
current_branch = g.current_branch
puts "current_branch:#{current_branch}"
commits = g.log(2) # Get the last two commits
first_commit = commits.first
last_commit = commits.last
puts #{first_commit}
puts first_commit.message
puts Last commit ID: #{last_commit}
The # commit logging convention begins with PodSync:
unless first_commit.message.include? 'PodSync:'
puts 'Commit log without PodSync: start'
exit 0
end
if first_commit.parents.size > 1
puts 'This is a merge commit, cannot synchronize a merge commit'
exit 1
end
file_list = g.diff(first_commit, commits.last).name_status.map(&:first)
# Need to exclude some files such as Local Podspecs Manifest. Lock Headers
pod_file_list = file_list.select do |e|
next if e.end_with? 'Manifest.lock'
next if e.start_with? 'Pods/Local Podspecs'
next if e.start_with? 'Pods/Target Support Files'
next if e.start_with? 'Pods/Headers'
e.start_with? 'Pods/'
end
puts "pod_file_list#{pod_file_list}"
# convert to Pod name
pod_file_list_map = pod_file_list.map { |e| e.split('/')[1] }
# Remove duplicates to get the modified Pod array
pod_file_list_set = pod_file_list_map.uniq
puts pod_file_list_set
Dir.mktmpdir do |dir|
pod_file_list_set.each do |item|
begin
puts "Clone: #{url_config[item]}, dir #{item}, branch : #{current_branch}"
g = Git.clone(url_config[item], item, path: dir, branch: current_branch)
rescue StandardError => e
puts e
exit 1
end
src = work_path + 'Pods' + item + item
dest = Pathname.new(dir) + item + item
puts "#{src} copy to #{dest}"
FileUtils.rm_r(dest, force: true)
FileUtils.cp_r(src, dest.parent)
The # puts g.status. Changed state appears to be cached or command line correct
status_output = `git -C #{dest.parent} status`
puts status_output unless status_output.include? 'working tree clean'
# submit & Push
`git -C #{dest.parent} commit -a -m 'Over PodSync'`
`git -C #{dest.parent} push`
end
end
Copy the code