ios_double_source 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: ca9b1f74c057eb6bfcd917c159c2ac7190143fe963eec25e6325b8feaafcea71
4
+ data.tar.gz: 47e0c87b8039e5abbdaab7b922710da4538e9c49b692a0b0ca4173102e58da26
5
+ SHA512:
6
+ metadata.gz: 797252c7cb0656e39f1e3a9add7863dc233f5c2d4bc27e8aca46633dc8c8be9541925c9f2a58a89a313a4e59e053570ae2ff2a420339193d87ab56d81178b90a
7
+ data.tar.gz: 57c40a5873220df278b33cbfc77648edf72084b80171ee85d401cb5ff5fea91a8654bf66c2d2308216f6aded4c64b07a963c2c025cd437e9838eed000e3ab883
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2025 WANGSHUAIPENG
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # IosDoubleSource
2
+
3
+ TODO: Delete this and the text below, and describe your gem
4
+
5
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/ios_double_source`. To experiment with that code, run `bin/console` for an interactive prompt.
6
+
7
+ ## Installation
8
+
9
+ TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
10
+
11
+ Install the gem and add to the application's Gemfile by executing:
12
+
13
+ $ bundle add UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
14
+
15
+ If bundler is not being used to manage dependencies, install the gem by executing:
16
+
17
+ $ gem install UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Development
24
+
25
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
26
+
27
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
28
+
29
+ ## Contributing
30
+
31
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/ios_double_source. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/ios_double_source/blob/main/CODE_OF_CONDUCT.md).
32
+
33
+ ## License
34
+
35
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
36
+
37
+ ## Code of Conduct
38
+
39
+ Everyone interacting in the IosDoubleSource project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/ios_double_source/blob/main/CODE_OF_CONDUCT.md).
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "ios_double_source"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,162 @@
1
+ # frozen_string_literal: true
2
+ require_relative 'config'
3
+ require_relative 'build_item'
4
+ require_relative 'gitlab_helper'
5
+ require_relative 'repo_xcode'
6
+ require_relative 'repo_xcode_package'
7
+ require_relative 'repo_xcode_shell'
8
+ require_relative 'repo_cocoapods'
9
+ require_relative 'repo_module'
10
+ require_relative 'repo_module_source'
11
+ require_relative 'repo_module_binary'
12
+ require_relative 'cost'
13
+ require_relative 'push'
14
+ require_relative 'github_helper'
15
+ require_relative 'github_fork'
16
+ module Build
17
+ class AutoBuild
18
+ attr_accessor :config
19
+ attr_accessor :build_item
20
+ attr_accessor :repo_xcode_package
21
+ attr_accessor :repo_xcode_shell
22
+ attr_accessor :repo_cocoapods_source
23
+ attr_accessor :repo_cocoapods_binary
24
+ attr_accessor :repo_module_source
25
+ attr_accessor :repo_module_binary
26
+ attr_accessor :gitlab_helper
27
+ attr_accessor :log
28
+ attr_accessor :pusher
29
+ attr_accessor :build_binary
30
+ def initialize(config, repo_xcode_package, repo_cocoapods_source, repo_cocoapods_binary)
31
+ @log = Log.new
32
+ @pusher = Push.instance
33
+ @config = config
34
+ @gitlab_helper = GitLabHelper.instance
35
+ @repo_xcode_package = repo_xcode_package
36
+ @repo_cocoapods_source = repo_cocoapods_source
37
+ @repo_cocoapods_binary = repo_cocoapods_binary
38
+ end
39
+ def run(repo_xcode_shell, repo_module_source, repo_module_binary, build_item, sender = nil)
40
+ @repo_xcode_shell = repo_xcode_shell
41
+ @repo_module_source = repo_module_source
42
+ @repo_module_binary = repo_module_binary
43
+ @build_item = build_item
44
+ @pusher.setup(sender, repo_module_source, repo_xcode_shell)
45
+ bind
46
+ analyzer
47
+ special_analyzer
48
+ clone_code
49
+ module_source_update
50
+ auto_build_update
51
+ xcode_package_update
52
+ re_pull
53
+ module_binary_update
54
+ cocoapods_update
55
+ merge_master
56
+ push_product
57
+ publish_shell
58
+ push_message_log
59
+ end
60
+ def bind
61
+ @repo_xcode_shell.gitlab_helper = gitlab_helper
62
+ @repo_xcode_package.gitlab_helper = gitlab_helper
63
+ @repo_cocoapods_source.gitlab_helper = gitlab_helper
64
+ @repo_cocoapods_binary.gitlab_helper = gitlab_helper
65
+ @repo_module_source.gitlab_helper = gitlab_helper
66
+ @repo_module_binary.gitlab_helper = gitlab_helper
67
+ @repo_xcode_shell.pusher = pusher
68
+ @repo_xcode_package.pusher = pusher
69
+ @repo_cocoapods_source.pusher = pusher
70
+ @repo_cocoapods_binary.pusher = pusher
71
+ @repo_module_source.pusher = pusher
72
+ @repo_module_binary.pusher = pusher
73
+ @gitlab_helper.pusher = pusher
74
+ end
75
+ def analyzer
76
+ puts "\n🚗🚗🚗 开始 组件:#{repo_module_source.pod_name} 版本:#{repo_module_source.pod_version} 分支/tag:#{repo_module_source.branch}"
77
+ puts "snapshot: #{self.build_item.snapshot}"
78
+ puts "real_device: #{self.build_item.real_device}"
79
+ puts "simulator: #{self.build_item.simulator}"
80
+ puts "force_cover: #{self.build_item.force_cover}"
81
+ puts "publish_shell: #{self.build_item.publish_shell}"
82
+ puts "merge_master: #{self.build_item.merge_master}"
83
+ end
84
+ def special_analyzer
85
+ self.build_item.special_setup(repo_module_source.pod_name)
86
+ end
87
+ def clone_code
88
+ puts "\n⏩ clone仓库"
89
+ repo_cocoapods_source.git_clone(true)
90
+ repo_cocoapods_binary.git_clone(true)
91
+ if repo_module_source.third
92
+ github_helper = GithubHelper.instance
93
+ if self.build_item.fork
94
+ github_forker = GithubFork.instance
95
+ github_forker.setup(config.module_github_path,repo_module_source.pod_name, github_helper.github_url, repo_module_source.ssh_url)
96
+ github_forker.fork_if_need(repo_cocoapods_source, repo_cocoapods_binary)
97
+ end
98
+ end
99
+ source_only_head = !self.build_item.merge_master
100
+ repo_module_source.git_clone(source_only_head)
101
+ gitlab_helper.create_project_if_need(repo_module_source.pod_name, repo_module_binary.http_url, private:false , description:repo_module_source.http_url)
102
+ repo_module_binary.git_clone(true)
103
+ repo_xcode_package.git_clone(true)
104
+ repo_xcode_shell.git_clone(true)
105
+ log.record_time("clone代码")
106
+ end
107
+ def module_source_update
108
+ repo_module_source.force_cover_validate(repo_cocoapods_source)
109
+ repo_module_source.update_podspec
110
+ repo_module_source.update_binary
111
+ end
112
+ def auto_build_update
113
+ @build_binary = repo_module_source.build_binary
114
+ end
115
+ def xcode_package_update
116
+ repo_xcode_package.copy_yaml_from_repo(repo_xcode_shell)
117
+ repo_xcode_package.generate_local_yaml(repo_module_source)
118
+ repo_xcode_package.pod_update
119
+ log.record_time("pod update")
120
+ repo_xcode_package.archive(repo_module_source)
121
+ log.record_time("构建打包")
122
+ end
123
+ def re_pull
124
+ puts "\n⏩ 重新拉取仓库"
125
+ repo_cocoapods_binary.git_pull
126
+ repo_cocoapods_source.git_pull
127
+ repo_module_binary.git_pull
128
+ end
129
+ def module_binary_update
130
+ build_binary ? repo_module_binary.clear : nil
131
+ build_binary ? repo_module_binary.copy_framework(repo_xcode_package, repo_module_source) : nil
132
+ build_binary ? repo_module_binary.copy_resources(repo_xcode_package, repo_module_source): nil
133
+ build_binary ? repo_module_binary.copy_podspec(repo_xcode_package, repo_module_source) :nil
134
+ end
135
+ def cocoapods_update
136
+ build_binary ? repo_cocoapods_binary.copy_podspec(repo_module_binary) : nil
137
+ repo_cocoapods_source.copy_podspec(repo_module_source)
138
+ end
139
+ def merge_master
140
+ gitlab_helper.merge_branch(repo_module_source, "master")
141
+ end
142
+ def push_product
143
+ if build_binary
144
+ repo_module_binary.push_code
145
+ repo_module_binary.git_tag
146
+ repo_cocoapods_binary.push_code
147
+ end
148
+ repo_module_source.git_tag
149
+ repo_cocoapods_source.push_code
150
+ repo_module_source.lock_branch_if_need
151
+ log.record_time("提交产物")
152
+ end
153
+ def publish_shell
154
+ repo_xcode_shell.publish_shell(repo_module_source)
155
+ end
156
+ def push_message_log
157
+ log.end_record_time("🕓 整体")
158
+ pusher.push("【✅组件版本发布成功】", "耗时: #{log.cost_time}秒 包大小: #{repo_module_binary.size_format}")
159
+ log.print_cost
160
+ end
161
+ end
162
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+ require_relative 'push'
3
+ module Build
4
+ class BuildItem
5
+ attr_accessor :snapshot
6
+ attr_accessor :real_device
7
+ attr_accessor :simulator
8
+ attr_accessor :merge_master
9
+ attr_accessor :force_cover
10
+ attr_accessor :publish_shell
11
+ attr_accessor :fork
12
+ attr_accessor :pusher
13
+ def initialize(snapshot, real_device, simulator, merge_master, force_cover, publish_shell, fork = false)
14
+ @snapshot = snapshot.to_s.downcase == "true"
15
+ @real_device = real_device.to_s.downcase == "true"
16
+ @simulator = simulator.to_s.downcase == "true"
17
+ @merge_master = merge_master.to_s.downcase == "true"
18
+ @force_cover = force_cover.to_s.downcase == "true"
19
+ @publish_shell = publish_shell.to_s.downcase == "true"
20
+ @fork = fork.to_s.downcase == "true"
21
+ @pusher = Push.instance
22
+ validate
23
+ end
24
+ def validate
25
+ if merge_master and snapshot
26
+ error = "SNAPSHOT包发布不能同时选择合并到master分支, 请检查参数"
27
+ pusher.push("❌ 打包失败", error)
28
+ Process.exit(-1)
29
+ end
30
+ end
31
+ def special_setup(pod_name)
32
+ if pod_name == "MUCDebugPlugins"
33
+ @real_device = false
34
+ @simulator = false
35
+ puts "⚠️ 特殊处理:#{pod_name} real_device重设为false simulator重设为false"
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+ module Build
3
+ class Commit
4
+ attr_accessor :commit_id
5
+ attr_accessor :committer
6
+ attr_accessor :commit_mail
7
+ attr_accessor :commit_msg
8
+ attr_accessor :commit_time
9
+ end
10
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+ require 'singleton'
3
+ module Build
4
+ class Config
5
+ include Singleton
6
+ attr_accessor :jenkins_url
7
+ def initialize
8
+ super
9
+ init_workspace
10
+ end
11
+ def work_dir
12
+ FileUtils.pwd + "/TempCode"
13
+ end
14
+ def xcode_package_path
15
+ "#{work_dir}/XcodePackage"
16
+ end
17
+ def cocoapods_source_path
18
+ "#{work_dir}/CocoapodsSource"
19
+ end
20
+ def cocoapods_binary_path
21
+ "#{work_dir}/CocoapodsBinary"
22
+ end
23
+ def xcode_shell_path
24
+ "#{work_dir}/XcodeShell"
25
+ end
26
+ def module_source_path
27
+ "#{work_dir}/ModuleSource"
28
+ end
29
+ def module_binary_path
30
+ "#{work_dir}/ModuleBinary"
31
+ end
32
+ def podspec_github_path
33
+ "#{work_dir}/PodspecGithub"
34
+ end
35
+ def module_github_path
36
+ "#{work_dir}/ModuleGithub"
37
+ end
38
+ def init_workspace
39
+ puts "⏩ 准备工作目录:#{work_dir}"
40
+ FileUtils.rm_rf(work_dir)
41
+ Dir.mkdir(work_dir)
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+ module Build
3
+ class Cost
4
+ attr_accessor :duration
5
+ attr_accessor :description
6
+ def initialize(description, duration)
7
+ @description = description
8
+ @duration= duration
9
+ end
10
+ end
11
+ class Log
12
+ attr_accessor :cost_array
13
+ attr_accessor :last_time
14
+ attr_accessor :start_time
15
+ attr_accessor :cost_time
16
+ def initialize
17
+ @cost_array = Array.new
18
+ @start_time = Time.now.getutc.to_i
19
+ @last_time = Time.now.getutc.to_i
20
+ end
21
+ def record_time(description)
22
+ current_time = Time.now.getutc.to_i
23
+ duration = current_time - last_time
24
+ cost = Cost.new(description, duration)
25
+ cost_array << cost
26
+ @last_time = current_time
27
+ end
28
+ def end_record_time(description)
29
+ current_time = Time.now.getutc.to_i
30
+ duration = current_time - start_time
31
+ @cost_time = duration
32
+ cost = Cost.new(description, duration)
33
+ cost_array << cost
34
+ @last_time = current_time
35
+ end
36
+ def print_cost
37
+ puts "\n⏩ 打印各阶段耗时:"
38
+ cost_array.each do |cost|
39
+ puts "-> #{cost.description}耗时: #{cost.duration}秒"
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,94 @@
1
+ # frozen_string_literal: true
2
+ require_relative 'push'
3
+ module Build
4
+ class GitHelper
5
+ def GitHelper.clone(path, url, branch = nil, only_head)
6
+ unless Dir.exist?(path)
7
+ Dir.mkdir(path)
8
+ end
9
+ branch = (branch and branch != "") ? "--branch #{branch} ": " "
10
+ head = only_head == true ? "--single-branch --depth 1 " : " "
11
+ command = "/usr/bin/git clone #{url} #{branch}#{head}#{path}"
12
+ GitHelper.execute(path, command, true)
13
+ end
14
+ def GitHelper.status(path)
15
+ current = Dir.pwd
16
+ Dir.chdir(path)
17
+ puts "-> 获取代码状态(#{File.basename(path)}): git status"
18
+ res = %x(git status)
19
+ if res.include? 'nothing to commit, working tree clean'
20
+ puts "当前无变更"
21
+ return false
22
+ end
23
+ Dir.chdir(current)
24
+ true
25
+ end
26
+ def GitHelper.add_stag(path)
27
+ command = "git add ."
28
+ GitHelper.execute(path, command, true)
29
+ end
30
+ def GitHelper.commit(path, commit_msg = nil)
31
+ commit_msg = commit_msg ? commit_msg : "#ignore_scan# none message"
32
+ command = "git commit -m \"#{commit_msg}\""
33
+ GitHelper.execute(path, command, true)
34
+ end
35
+ def GitHelper.pull(path)
36
+ command = "git pull"
37
+ GitHelper.execute(path, command, true)
38
+ end
39
+ def GitHelper.push(path, branch)
40
+ command = "git push origin #{branch}"
41
+ GitHelper.execute(path, command, true)
42
+ end
43
+ def GitHelper.push_f(path, branch)
44
+ command = "git push origin -f #{branch}"
45
+ GitHelper.execute(path, command, true)
46
+ end
47
+ def GitHelper.reset_hard(path)
48
+ command = "git reset --hard"
49
+ GitHelper.execute(path, command, true)
50
+ end
51
+ def GitHelper.fetch(path)
52
+ command = "git fetch"
53
+ GitHelper.execute(path, command, true)
54
+ end
55
+ def GitHelper.checkout(path, checkout_branch)
56
+ command = "git checkout #{checkout_branch}"
57
+ GitHelper.execute(path, command, true)
58
+ end
59
+ def GitHelper.tag_delete_local(path, tag)
60
+ command = "git tag -d #{tag}"
61
+ GitHelper.execute(path, command, false)
62
+ end
63
+ def GitHelper.tag_delete_origin(path, tag)
64
+ command = "git push origin :refs/tags/#{tag}"
65
+ GitHelper.execute(path, command, true)
66
+ end
67
+ def GitHelper.tag_local(path, tag)
68
+ command = "git tag #{tag}"
69
+ GitHelper.execute(path, command, true)
70
+ end
71
+ def GitHelper.tag_origin(path, tag)
72
+ command = "git push origin #{tag}"
73
+ GitHelper.execute(path, command, true)
74
+ end
75
+ def GitHelper.push_tags(path)
76
+ command = "git push origin --tags"
77
+ GitHelper.execute(path, command, true)
78
+ end
79
+ private
80
+ def GitHelper.execute(path, command, can_raise)
81
+ current = Dir.pwd
82
+ Dir.chdir(path)
83
+ puts "-> git命令(#{File.basename(path)}):#{command}"
84
+ res = system command
85
+ if can_raise and not res
86
+ pusher = Push.instance
87
+ error = "失败: #{command}"
88
+ pusher.push("❌ 失败", error)
89
+ Process.exit(-1)
90
+ end
91
+ Dir.chdir(current)
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,74 @@
1
+ # frozen_string_literal: true
2
+ require_relative 'repo'
3
+ require_relative 'config'
4
+ require_relative 'gitlab_helper'
5
+ require 'git'
6
+ require 'singleton'
7
+ module Build
8
+ class GithubFork
9
+ include Singleton
10
+ attr_accessor :path
11
+ attr_accessor :pod_name
12
+ attr_accessor :github_url
13
+ attr_accessor :source_repo_url
14
+ attr_accessor :repo
15
+ def setup(path, pod_name, github_url, source_repo_url)
16
+ self.path = path
17
+ self.pod_name = pod_name
18
+ self.github_url = github_url
19
+ self.source_repo_url = source_repo_url
20
+ end
21
+ def fork_if_need(repo_cocoapods_source, repo_cocoapods_binary)
22
+ download_github
23
+ check_can_fork(repo_cocoapods_source)
24
+ check_can_fork(repo_cocoapods_binary)
25
+ create_if_need
26
+ upload_gitlab
27
+ end
28
+ def download_github
29
+ repo_path = Pathname(path)
30
+ fast_github_url = self.github_url.start_with?("http") ? self.github_url.gsub("github.com", "kkgithub.com") : self.github_url.gsub
31
+ puts "\n⏩ fork源码(#{File.basename(self.path)})"
32
+ puts "下载源码文件(#{fast_github_url})..."
33
+ Git.clone(fast_github_url, repo_path)
34
+ puts "完毕"
35
+ puts "-> 检出所有分支"
36
+ self.repo = Git.open(repo_path)
37
+ self.repo.branches.each do |branch|
38
+ self.repo.branch(branch.name).checkout
39
+ end
40
+ self.repo.config('remote.origin.url', self.source_repo_url)
41
+ end
42
+ def check_can_fork(repo_cocoapods)
43
+ versions = repo_cocoapods.pod_name_versions(self.pod_name)
44
+ unless versions
45
+ return
46
+ end
47
+ repo_versions = []
48
+ self.repo.tags.each do |tag|
49
+ repo_versions << tag.name
50
+ end
51
+ un_contain_array = []
52
+ versions.each do |version|
53
+ unless repo_versions.include?(version)
54
+ un_contain_array << version
55
+ end
56
+ end
57
+ if un_contain_array.length > 0
58
+ error = "fork失败,已打包的版本#{un_contain_array}不在新的代码仓库中,请手动处理后再打包。"
59
+ puts error
60
+ Process.exit(-1)
61
+ end
62
+ end
63
+ def create_if_need
64
+ gitlab_helper = GitLabHelper.instance
65
+ gitlab_helper.create_project_if_need(self.pod_name, self.source_repo_url.ssh_to_http, private:false, description:self.github_url)
66
+ end
67
+ def upload_gitlab
68
+ puts "-> 推送并覆盖所有分支和标签(#{self.source_repo_url})"
69
+ self.repo.push('origin', {:all => true, :force => true})
70
+ self.repo.push('origin', {:tags => true, :force => true})
71
+ puts "完毕"
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,97 @@
1
+ # frozen_string_literal: true
2
+ require 'digest'
3
+ require 'json'
4
+ require_relative 'util/request'
5
+ require_relative 'push'
6
+ require 'singleton'
7
+ module Build
8
+ class GithubHelper
9
+ include Singleton
10
+ attr_accessor :path
11
+ attr_accessor :pod_name
12
+ attr_accessor :pod_version
13
+ attr_accessor :third
14
+ attr_accessor :pusher
15
+ attr_accessor :github_tag
16
+ attr_accessor :github_url
17
+ attr_accessor :github_ssh_url
18
+ attr_accessor :podspec_content
19
+ def request_podspec(path, pod_name, pod_version)
20
+ @path = path
21
+ @pod_name = pod_name
22
+ @pod_version = pod_version
23
+ @pusher = Push.instance
24
+ download_podspec
25
+ analyzer_tag
26
+ end
27
+ private
28
+ def download_podspec
29
+ puts "\n⏩ (#{File.basename(self.path)})从github上下载podspec文件"
30
+ unless Dir.exist?(self.path)
31
+ Dir.mkdir(self.path)
32
+ end
33
+ podspec_json_path = "#{self.path}/#{pod_name}.podspec.json"
34
+ pod_name_md5 = Digest::MD5.hexdigest(pod_name)
35
+ pod_name_md5_0 = pod_name_md5[0..0]
36
+ pod_name_md5_1 = pod_name_md5[1..1]
37
+ pod_name_md5_2 = pod_name_md5[2..2]
38
+ split_path = "#{pod_name_md5_0}/#{pod_name_md5_1}/#{pod_name_md5_2}"
39
+ podspec_json_url = "https://raw.gitmirror.com/CocoaPods/Specs/master/Specs/#{split_path}/#{pod_name}/#{pod_version}/#{pod_name}.podspec.json"
40
+ puts "->组件md5裁切:#{split_path}"
41
+ puts "->所有版本地址:https://kkgithub.com/CocoaPods/Specs/tree/master/Specs/#{split_path}/#{pod_name}"
42
+ puts "->当前版本地址: #{podspec_json_url}"
43
+ url = URI(podspec_json_url)
44
+ response = Net::HTTP.get_response(url)
45
+ begin
46
+ podspec_content = JSON.parse(response.body)
47
+ rescue => exception
48
+ puts exception
49
+ puts "❌ 请检查网络或参数是否正确"
50
+ Process.exit(-1)
51
+ end
52
+ res_pod_name = podspec_content["name"]
53
+ unless res_pod_name == pod_name
54
+ error = "获取到的podspec的名字#{res_pod_name}!= #{pod_name}"
55
+ pusher.push("❌ 打包失败", error)
56
+ Process.exit(-1)
57
+ end
58
+ podspec_content.delete("license")
59
+ podspec_content.delete("module_map")
60
+ unless podspec_content.has_key?("swift_version")
61
+ podspec_content.delete("static_framework")
62
+ end
63
+ @podspec_content = podspec_content
64
+ new_file = File.new(podspec_json_path, "w+")
65
+ if new_file
66
+ new_file.syswrite(JSON.pretty_generate(podspec_content))
67
+ end
68
+ end
69
+ def analyzer_tag
70
+ source = podspec_content["source"]
71
+ unless source
72
+ error = "podspec指定的 source字段为空"
73
+ pusher.push("❌ 解析失败", error)
74
+ Process.exit(-1)
75
+ end
76
+ @github_url = source["git"]
77
+ @github_tag = if source["tag"]
78
+ source["tag"]
79
+ else
80
+ source["branch"] ? source["branch"] : source["commit"]
81
+ end
82
+ unless @github_url
83
+ error = "podspec文件未使用source[git],暂未支持"
84
+ pusher.push("❌ 失败", error)
85
+ Process.exit(-1)
86
+ end
87
+ unless @github_tag
88
+ error = "podspec未使用source[tag] source[branch] source[commit], 暂未支持"
89
+ pusher.push("❌ 解析失败", error)
90
+ Process.exit(-1)
91
+ end
92
+ @github_ssh_url = @github_url.http_to_ssh
93
+ puts "->当前版本源码地址: #{@github_url }"
94
+ puts "->当前版本源码tag: #{@github_tag}"
95
+ end
96
+ end
97
+ end