cocoapods-tag 0.0.3 → 0.0.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 69b23947908cd9859abaa7dd628fca94b271c16653bc5c101061486fcb3cecff
4
- data.tar.gz: ec017bb88326f01e4a5bf5481ea0b6b07caebb6c94b1233405b4e990dd422e44
3
+ metadata.gz: 750b94770c7e64be7c2fec845a40ec5f131b3bf37d401a25d5707e943e61eb18
4
+ data.tar.gz: 71f223370e85b4711acfcdd347b1ba4534f39eabf35828e8b1d6116887b0da86
5
5
  SHA512:
6
- metadata.gz: 4a2b28788338735f7bf6a7e27142ea590db539412a86b00cc41412eced1101c38a2eb6b5af36a78ebc687f92ff304ae3ffd80622384546bf39b90ce62aa2d1b3
7
- data.tar.gz: 59b0deeb4eacffc8e158016decc44b8379bcb16915af963be0a2654030a2470c37874bcf9608f9b3c101a256cb570e7967fe75b0dd2e0a308ba17f634cabbb07
6
+ metadata.gz: '099976d089ecaea62b573739b974970f1d3f590a880abede27ebcde14b7cb50ceb41d1fa4b223c20d5d7a91f6f107646a1941b47332def8788bc26c23edee383'
7
+ data.tar.gz: 8b6c5f648ae71bf9a59470f28c18f375f954c067f5fc07047268425d371b4291c19571fab2a026c7ab13f444fbd717dfe5a5a0573fc7328589537b14f7aad93c
data/README.md CHANGED
@@ -41,6 +41,26 @@ $ gem install cocoapods-tag
41
41
  $ pod tag 0.1.7 "修改podspec版本号为0.1.7" "版本0.1.7" --spec-repo=xxx --quick
42
42
  ```
43
43
 
44
+ * 指定tag推送到的远端仓库(可以通过`git remote -v`查看)
45
+
46
+ ```shell
47
+ $ pod tag 0.1.7 "修改podspec版本号为0.1.7" "版本0.1.7" --remote=origin
48
+ ```
49
+
50
+ * 指定工作目录(插件执行的目录)
51
+
52
+ ```shell
53
+ $ pod tag 0.1.7 "修改podspec版本号为0.1.7" --work-dir=xxx
54
+ ```
55
+
56
+ * 为tag添加前后缀 **(前后缀与版本号中间会自动用`-`分隔,不需要手动添加)**
57
+
58
+ 以下面这行命令为例,`podspec`中的`version`为`0.1.7`,`source`字段中的`tag`为`mtxx-0.1.7-beta1`,最终推送到远端仓库的`tag`也是`mtxx-0.1.7-beta1`
59
+
60
+ ```shell
61
+ $ pod tag 0.1.7 "修改podspec版本号为0.1.7" --prefix="mtxx" --suffix="beta1"
62
+ ```
63
+
44
64
  * 单独推送`podspec`到指定`spec repo`
45
65
 
46
66
  ```shell
@@ -60,3 +80,5 @@ ANCHORED_VERSION_PATTERN = /\A\s*(#{VERSION_PATTERN})?\s*\z/
60
80
 
61
81
  大概解释一下就是:以`数字0-9`开头,中间可以包含`数字0-9`、`字母a-z A-Z`,特殊字符只能包含`.`和`-`,版本号前后可以有`0个或多个空格`
62
82
 
83
+ > 1. `cocoapods-tag`已经对版本号做了正则校验,不符合上面正则的版本号是无法通过的,这里写出来主要是为了提醒大家注意版本号的规范
84
+ > 2. 不建议版本号前后加空格
@@ -11,11 +11,11 @@ module Pod
11
11
  self.description = <<-DESC
12
12
  #{self.summary}
13
13
 
14
- `TAG`: tag号【必填】\n
14
+ `VERSION`: podspec中的version字段,如果没有prefix和suffix,version与tag一样【必填】\n
15
15
  `COMMIT_MSG`: commit信息【必填】\n
16
16
  `TAG_MSG`: tag信息【可选,默认为"v[tag号]",比如:tag是"0.0.1",则tag信息是"v0.0.1"】\n
17
17
 
18
- eg:\n
18
+ e.g.\n
19
19
  1.使用默认tag信息\n
20
20
  pod tag 0.1.7 "修改podspec版本号为0.1.7"\n
21
21
  2.使用自定义tag信息\n
@@ -23,33 +23,61 @@ pod tag 0.1.7 "修改podspec版本号为0.1.7" "版本0.1.7"\n
23
23
  3.推送podspec到spec repo\n
24
24
  pod tag 0.1.7 "修改podspec版本号为0.1.7" "版本0.1.7" --spec-repo=xxx\n
25
25
  4.跳过耗时校验\n
26
- pod tag 0.1.7 "修改podspec版本号为0.1.7" "版本0.1.7" --spec-repo=xxx --quick
26
+ pod tag 0.1.7 "修改podspec版本号为0.1.7" "版本0.1.7" --quick\n
27
+ 5.指定工作目录\n
28
+ pod tag 0.1.7 "修改podspec版本号为0.1.7" --work-dir=xxx\n
29
+ 6.为tag指定前后缀\n
30
+ pod tag 0.1.7 "修改podspec版本号为0.1.7" --prefix="xxx" --suffix="xxx"\n
31
+ 7.指定tag推送到的远端仓库\n
32
+ pod tag 0.1.7 "修改podspec版本号为0.1.7" --remote=xxx
27
33
  DESC
28
34
 
29
35
  self.arguments = [
30
- CLAide::Argument.new('TAG', true ),
36
+ CLAide::Argument.new('VERSION', true ),
31
37
  CLAide::Argument.new('COMMIT_MSG', true),
32
38
  CLAide::Argument.new('TAG_MSG', false)
33
39
  ]
34
40
 
35
41
  def self.options
36
42
  [
37
- ['--spec-repo=SPECREPO', 'podspec 推送到的 spec repo ,可以通过`pod repo list`查看'],
38
- ['--quick', '跳过一些耗时校验,如:远端仓库是否已经有该 tag ']
43
+ ['--quick', '跳过一些耗时校验,如:远端仓库是否已经有该tag'],
44
+ ['--skip-push-commit', '跳过推送commit到对应分支'],
45
+ ['--remote=REMOTE', '指定tag推送到的远端仓库,可以通过`git remote -v`查看'],
46
+ ['--spec-repo=SPECREPO', 'podspec推送到的repo,可以通过`pod repo list`查看'],
47
+ ['--work-dir=WORKDIR', '执行命令的工作区'],
48
+ ['--prefix=PREFIX', 'tag前缀'],
49
+ ['--suffix=SUFFIX', 'tag后缀']
39
50
  ].concat(super)
40
51
  end
41
52
 
42
53
  def initialize(argv)
43
- @tag = argv.shift_argument
54
+ @version = argv.shift_argument
44
55
  @commit_msg = argv.shift_argument
45
56
  @tag_msg = argv.shift_argument
46
- @spec_repo = argv.option('spec-repo', nil)
47
57
  @quick = argv.flag?('quick', false)
58
+ @skip_push_commit = argv.flag?('skip-push-commit', false)
59
+ @remote = argv.option('remote', false)
60
+ @spec_repo = argv.option('spec-repo', nil)
61
+ @work_dir = argv.option('work-dir', nil)
62
+ @prefix = argv.option('prefix', nil)
63
+ @suffix = argv.option('suffix', nil)
64
+ @tag = @version
65
+ unless @prefix.nil?
66
+ @tag = "#{@prefix}-#{@tag}"
67
+ end
68
+ unless @suffix.nil?
69
+ @tag = "#{@tag}-#{@suffix}"
70
+ end
48
71
  super
49
72
  end
50
73
 
51
74
  def run
52
- tag = Pod::Tag.new(@tag, @commit_msg, @tag_msg, @spec_repo, @quick)
75
+ # 传入了工作目录
76
+ unless @work_dir.nil?
77
+ raise Informative, "不存在工作目录`#{@work_dir}`" unless File.exist?(@work_dir)
78
+ Dir.chdir(@work_dir)
79
+ end
80
+ tag = Pod::Tag.new(@version, @tag, @commit_msg, @tag_msg, @spec_repo, @quick, @remote, @skip_push_commit)
53
81
  tag.create
54
82
  end
55
83
 
@@ -0,0 +1,77 @@
1
+
2
+ module Pod
3
+ class Command
4
+ class Tag < Command
5
+ class RepoList < Tag
6
+ include Pod
7
+
8
+ self.summary = '打印本地的 podspec 仓库'
9
+
10
+ self.description = <<-DESC
11
+ #{self.summary}
12
+ DESC
13
+
14
+ def self.options
15
+ [
16
+ ['--format=FORMAT', '输出结果格式化,可选项为`json/yml(yaml)/plain`'],
17
+ ].concat(super)
18
+ end
19
+
20
+ def initialize(argv)
21
+ @format = argv.option('format', 'plain')
22
+ super
23
+ end
24
+
25
+ def run
26
+ @sources = config.sources_manager.all
27
+ if @format == 'json'
28
+ print_json
29
+ elsif @format == 'yml' || @format == 'yaml'
30
+ print_yml
31
+ else
32
+ print_plain
33
+ end
34
+ end
35
+
36
+ private
37
+
38
+ def print_json
39
+ require 'json'
40
+ UI.puts JSON.pretty_generate(sources)
41
+ end
42
+
43
+ def print_yml
44
+ require 'yaml'
45
+ UI.puts sources.to_yaml
46
+ end
47
+
48
+ def print_plain
49
+ list = Pod::Command::Repo::List.new(CLAide::ARGV.new([]))
50
+ list.validate!
51
+ list.run
52
+ end
53
+
54
+ def sources
55
+ result = []
56
+ @sources.each do |source|
57
+ type = source.type
58
+ if source.is_a?(Pod::CDNSource)
59
+ type = 'CDN'
60
+ elsif source.git?
61
+ type = 'git'
62
+ end
63
+ source_hash = {
64
+ 'name' => source.name,
65
+ 'url' => source.url,
66
+ 'path' => source.repo.to_s,
67
+ 'type' => type
68
+ }
69
+ result << source_hash
70
+ end
71
+ result
72
+ end
73
+
74
+ end
75
+ end
76
+ end
77
+ end
@@ -1,6 +1,7 @@
1
1
  require 'cocoapods-tag/command/tag/auto'
2
2
  # require 'cocoapods-tag/command/tag/create'
3
3
  require 'cocoapods-tag/command/tag/spec_push'
4
+ require 'cocoapods-tag/command/tag/repo_list'
4
5
 
5
6
  module Pod
6
7
  class Command
@@ -1,3 +1,3 @@
1
1
  module CocoapodsTag
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.6"
3
3
  end
@@ -8,12 +8,15 @@ module Pod
8
8
  GIT_REPO = ".git".freeze
9
9
  PODSPEC_EXT = %w[podspec podspec.json].freeze
10
10
 
11
- def initialize(tag, commit_msg, tag_msg, spec_repo = nil, quick = false)
11
+ def initialize(version, tag, commit_msg, tag_msg, spec_repo = nil, quick = false, remote_name = nil, skip_push_commit = false )
12
+ @version = version || raise(Informative, "缺少必填参数`version`")
12
13
  @tag = tag || raise(Informative, "缺少必填参数`tag`")
13
14
  @commit_msg = commit_msg || raise(Informative, "缺少必填参数`commit_msg`")
14
15
  @tag_msg = tag_msg || "v#{@tag}"
15
16
  @spec_repo = spec_repo
16
17
  @quick = quick
18
+ @remote = remote_name
19
+ @skip_push_commit = skip_push_commit
17
20
  end
18
21
 
19
22
  public
@@ -64,9 +67,9 @@ module Pod
64
67
 
65
68
  # 正则校验版本号
66
69
  def check_version
67
- unless Pod::Vendor::Gem::Version.correct?(@tag)
70
+ unless Pod::Vendor::Gem::Version.correct?(@version)
68
71
  msg = <<-ERROR
69
- 版本号格式不正确
72
+ 版本号`#{@version}`格式不正确
70
73
  版本号必须以数字`0-9`开头,可以包含数字`0-9`、字母`a-z A-Z`,特殊字符只能是`.`和`-`
71
74
  具体请参考CocoaPods校验版本号的正则:
72
75
  #{Pod::Vendor::Gem::Version::ANCHORED_VERSION_PATTERN}
@@ -86,7 +89,7 @@ module Pod
86
89
 
87
90
  # 检查 git repo
88
91
  def check_git_repo
89
- # print "检查本地git仓库:\n".yellow
92
+ print "检查本地git仓库\n".yellow
90
93
 
91
94
  # 本地是否有 .git 目录
92
95
  git_repo = File.join(Dir.pwd, GIT_REPO)
@@ -95,28 +98,44 @@ module Pod
95
98
  # 是否与远端仓库关联
96
99
  raise Informative, "本地git仓库没有与远端仓库关联,请先使用`git remote add`关联远端仓库" if remote.nil?
97
100
 
98
- unless @quick
99
- # 校验本地 git 是否与远端仓库同步
100
- print "\n检查本地git仓库是否与远端仓库同步\n".yellow
101
- local_commit = `git rev-parse #{remote}/HEAD`.chomp
102
- remote_commit = `git ls-remote --head #{remote} #{current_branch}`.split("\t")[0]
103
- unless local_commit == remote_commit
104
- msg = <<-MSG
105
- 本地git仓库没有与远端仓库同步,请先执行以下操作:
106
- 1.`git pull`或`git fetch + git rebase`拉取最新代码
107
- 2.`git push`推送本地仓库commit
108
- MSG
109
- raise Informative, msg
110
- end
101
+ # 是否处于 detached 状态
102
+ raise Informative, "当前处于detached状态,请先切到分支再进行操作" if current_branch == "HEAD"
111
103
 
112
- # 检查本地是否已经有该 tag
113
- print "\n检查本地仓库是否有tag:`#{@tag}`\n".yellow
114
- raise Informative, "本地已经存在 tag:#{@tag}" if `git tag`.split("\n").include?(@tag)
104
+ # # 是否有未提交的改动
105
+ # raise Informative, "本地有未提交的改动,请先提交或暂存" unless `git status --porcelain`.split("\n").empty?
115
106
 
107
+ # 检查本地是否已经有该 tag
108
+ print "\n检查本地仓库是否有tag:`#{@tag}`\n".yellow
109
+ raise Informative, "本地仓库已经存在tag:#{@tag}" if `git tag`.split("\n").include?(@tag)
110
+
111
+ unless @quick
116
112
  # 判断远端是否已经有该 tag
117
113
  print "\n检查远端仓库是否有tag:`#{@tag}`\n".yellow
118
114
  tags = `git ls-remote --tags #{remote}`.split("\n").select { |tag| tag.include?("refs/tags/#{@tag}") }
119
- raise Informative, "远端仓库已经有该 tag:#{@tag}" unless tags.empty?
115
+ raise Informative, "远端仓库已经有tag:#{@tag}" unless tags.empty?
116
+
117
+ # 校验本地 git 是否与远端仓库同步
118
+ print "\n检查本地git仓库是否与远端仓库同步\n".yellow
119
+ `git fetch #{remote}`
120
+ remote_br = `git rev-parse --abbrev-ref #{current_branch}@{u}`
121
+ unless remote_br == ''
122
+ remote_commit_count = `git rev-list --right-only --count #{current_branch}...#{remote_br}`.chomp.to_i
123
+ local_commit_count = `git rev-list --left-only --count #{current_branch}...#{remote_br}`.chomp.to_i
124
+ # 本地落后远端
125
+ unless remote_commit_count == 0
126
+ msg = <<-MSG
127
+ 本地git仓库落后于远端仓库`#{remote_commit_count}`个提交
128
+ 请先执行`git pull`或`git fetch #{remote} + git rebase #{remote_br}`拉取最新代码
129
+ MSG
130
+ raise Informative, msg
131
+ end
132
+
133
+ # 本地有未 push 的 commit
134
+ unless local_commit_count == 0
135
+ msg = "本地git仓库有`#{local_commit_count}`个commit未提交,请先执行`git push`提交"
136
+ raise Informative, msg
137
+ end
138
+ end
120
139
  end
121
140
 
122
141
  end
@@ -138,6 +157,10 @@ module Pod
138
157
  if source['git'] && source['git'].strip == ''
139
158
  raise Informative, "source中git字段不能为空"
140
159
  end
160
+ # git字段只能是ssh
161
+ if source['git'] && source['git'] =~ /^(http|https)/
162
+ raise Informative, "source中git字段不能是http或https,只能是ssh"
163
+ end
141
164
  end
142
165
 
143
166
  # 修改podspec
@@ -159,31 +182,31 @@ module Pod
159
182
  def modify_podspec_ruby(file)
160
183
  org_source = @spec_hash['source']
161
184
  des_source = "{ :git => '#{org_source['git']}', :tag => '#{@tag}' }"
162
- File.open(file, 'r') do |f|
163
- lines = []
185
+ lines = []
186
+ File.open(file, 'r:utf-8') do |f|
164
187
  f.each_line do |line|
165
188
  if line =~ /(^\s*.+\.version\s*=\s*).*/
166
- line = line.sub(/(^\s*.+\.version\s*=\s*).*/, "#{$1}'#{@tag}'")
189
+ line = line.sub(/(^\s*.+\.version\s*=\s*).*/, "#{$1}'#{@version}'")
167
190
  end
168
191
  if line =~ /(^\s*.+\.source\s*=\s*).*/
169
192
  line = line.sub(/(^\s*.+\.source\s*=\s*).*/, "#{$1}#{des_source}")
170
193
  end
171
194
  lines << line
172
195
  end
173
- File.open(file, 'w') do |f|
174
- f.write(lines.join(""))
175
- end
196
+ end
197
+ File.open(file, 'w:utf-8') do |f|
198
+ f.write(lines.join(""))
176
199
  end
177
200
  end
178
201
 
179
202
  # 修改 *.podspec.json
180
203
  def modify_podspec_json(file)
181
- @spec_hash['version'] = @tag
204
+ @spec_hash['version'] = @version
182
205
  @spec_hash['source'] = {
183
206
  'git'=> @spec_hash['source']['git'],
184
207
  'tag'=> "#{@tag}"
185
208
  }
186
- File.open(file, 'w') do |f|
209
+ File.open(file, 'w:utf-8') do |f|
187
210
  f.write(@spec_hash)
188
211
  end
189
212
  end
@@ -194,7 +217,7 @@ module Pod
194
217
  begin
195
218
  `git add #{podspec}`
196
219
  `git commit -m "#{@commit_msg}"`
197
- `git push #{remote} #{current_branch}`
220
+ `git push #{remote} #{current_branch}` unless @skip_push_commit
198
221
  rescue Pod::StandardError => e
199
222
  @error = e
200
223
  print "推送commit到远端git仓库`#{remote}/#{current_branch}`失败:#{e}".red
@@ -247,7 +270,7 @@ module Pod
247
270
  # 获取当前分支
248
271
  def current_branch
249
272
  @current_branch ||= begin
250
- `git branch`.split(' ')[1]
273
+ `git rev-parse --abbrev-ref HEAD`.chomp
251
274
  end
252
275
  end
253
276
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cocoapods-tag
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jensen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-04-08 00:00:00.000000000 Z
11
+ date: 2022-05-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cocoapods
@@ -66,6 +66,7 @@ files:
66
66
  - lib/cocoapods-tag/command/tag.rb
67
67
  - lib/cocoapods-tag/command/tag/auto.rb
68
68
  - lib/cocoapods-tag/command/tag/create.rb
69
+ - lib/cocoapods-tag/command/tag/repo_list.rb
69
70
  - lib/cocoapods-tag/command/tag/spec_push.rb
70
71
  - lib/cocoapods-tag/gem_version.rb
71
72
  - lib/cocoapods-tag/helper/asker.rb