cocoapods-tag 0.0.2 → 0.0.5
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 +4 -4
- data/README.md +31 -0
- data/lib/cocoapods-tag/command/tag/auto.rb +37 -9
- data/lib/cocoapods-tag/gem_version.rb +1 -1
- data/lib/cocoapods-tag/tag.rb +64 -28
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8bcf6776d9aecce496fc5ee724891375b4244907a9cec5dc0cc68e0bec72e9b1
|
4
|
+
data.tar.gz: 47e3f0020ec0f2ebd1be45ae35fdf49f94d7f185a9f46b0186abd0681fe0fd2f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0dec037cdb109bb8396ff9871f3ca00b89c83da4f1574f1e2df71d65eecec348523205d93a206819bd7c39882fd4a991e8b65903b95892e9599bf2db6d39dec9
|
7
|
+
data.tar.gz: 3e8190ebe75421b767616c7590646f8679fce382cf87bd3546d703643d6144a400df0fe6878e5a83a09c36b43717affb12a3cdaec6a2fa19b1559d1eb61436a4
|
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
|
@@ -49,5 +69,16 @@ $ gem install cocoapods-tag
|
|
49
69
|
|
50
70
|
> 如有疑问,请使用`pod tag auto --help`查看帮助信息,里面有每个字段的解释
|
51
71
|
|
72
|
+
## 版本号
|
73
|
+
|
74
|
+
`CocoaPods`对版本号是有校验的,如果不符合规则当推送`podspec`到`spec repo`时会校验失败,具体校验正则如下:
|
75
|
+
|
76
|
+
```ruby
|
77
|
+
VERSION_PATTERN = '[0-9]+(?>\.[0-9a-zA-Z]+)*(-[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?'
|
78
|
+
ANCHORED_VERSION_PATTERN = /\A\s*(#{VERSION_PATTERN})?\s*\z/
|
79
|
+
```
|
52
80
|
|
81
|
+
大概解释一下就是:以`数字0-9`开头,中间可以包含`数字0-9`、`字母a-z A-Z`,特殊字符只能包含`.`和`-`,版本号前后可以有`0个或多个空格`
|
53
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
|
-
`
|
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
|
-
|
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" --
|
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('
|
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
|
-
['--
|
38
|
-
['--
|
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
|
-
@
|
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
|
-
|
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
|
|
data/lib/cocoapods-tag/tag.rb
CHANGED
@@ -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
|
@@ -23,16 +26,20 @@ module Pod
|
|
23
26
|
|
24
27
|
# 欢迎语
|
25
28
|
welcome_message
|
29
|
+
# 正则校验版本号
|
30
|
+
check_version
|
26
31
|
# 检查本地是否有 spec_repo
|
27
32
|
check_spec_repo if @spec_repo
|
28
33
|
# 检查 git repo
|
29
34
|
check_git_repo
|
30
35
|
# 加载 podspec
|
31
36
|
load_podspec
|
32
|
-
#
|
33
|
-
lint_podspec
|
37
|
+
# 修改前校验 podspec
|
38
|
+
lint_podspec("\n修改前校验`#{podspec}`\n")
|
34
39
|
# 修改 podspec
|
35
40
|
modify_podspec
|
41
|
+
# 修改后校验 podspec
|
42
|
+
lint_podspec("\n修改后校验`#{podspec}`\n")
|
36
43
|
# 推送 commit 到远端
|
37
44
|
git_commit_push
|
38
45
|
# 推送 tag 到远端
|
@@ -58,6 +65,19 @@ module Pod
|
|
58
65
|
print "\n🌺 恭喜你完成任务 🌺\n".green
|
59
66
|
end
|
60
67
|
|
68
|
+
# 正则校验版本号
|
69
|
+
def check_version
|
70
|
+
unless Pod::Vendor::Gem::Version.correct?(@version)
|
71
|
+
msg = <<-ERROR
|
72
|
+
版本号`#{@version}`格式不正确
|
73
|
+
版本号必须以数字`0-9`开头,可以包含数字`0-9`、字母`a-z A-Z`,特殊字符只能是`.`和`-`
|
74
|
+
具体请参考CocoaPods校验版本号的正则:
|
75
|
+
#{Pod::Vendor::Gem::Version::ANCHORED_VERSION_PATTERN}
|
76
|
+
ERROR
|
77
|
+
raise Informative, msg
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
61
81
|
# 检查本地 spec_repo
|
62
82
|
def check_spec_repo
|
63
83
|
print "检查本地spec仓库\n".yellow
|
@@ -69,7 +89,7 @@ module Pod
|
|
69
89
|
|
70
90
|
# 检查 git repo
|
71
91
|
def check_git_repo
|
72
|
-
|
92
|
+
print "检查本地git仓库\n".yellow
|
73
93
|
|
74
94
|
# 本地是否有 .git 目录
|
75
95
|
git_repo = File.join(Dir.pwd, GIT_REPO)
|
@@ -78,28 +98,44 @@ module Pod
|
|
78
98
|
# 是否与远端仓库关联
|
79
99
|
raise Informative, "本地git仓库没有与远端仓库关联,请先使用`git remote add`关联远端仓库" if remote.nil?
|
80
100
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
unless local_commit == remote_commit
|
87
|
-
msg = <<-MSG
|
88
|
-
本地git仓库没有与远端仓库同步,请先执行以下操作:
|
89
|
-
1.`git pull`或`git fetch + git rebase`拉取最新代码
|
90
|
-
2.`git push`推送本地仓库commit
|
91
|
-
MSG
|
92
|
-
raise Informative, msg
|
93
|
-
end
|
101
|
+
# 是否处于 detached 状态
|
102
|
+
raise Informative, "当前处于detached状态,请先切到分支再进行操作" if current_branch == "HEAD"
|
103
|
+
|
104
|
+
# # 是否有未提交的改动
|
105
|
+
# raise Informative, "本地有未提交的改动,请先提交或暂存" unless `git status --porcelain`.split("\n").empty?
|
94
106
|
|
95
|
-
|
96
|
-
|
97
|
-
|
107
|
+
# 检查本地是否已经有该 tag
|
108
|
+
print "\n检查本地仓库是否有tag:`#{@tag}`\n".yellow
|
109
|
+
raise Informative, "本地仓库已经存在tag:#{@tag}" if `git tag`.split("\n").include?(@tag)
|
98
110
|
|
111
|
+
unless @quick
|
99
112
|
# 判断远端是否已经有该 tag
|
100
113
|
print "\n检查远端仓库是否有tag:`#{@tag}`\n".yellow
|
101
114
|
tags = `git ls-remote --tags #{remote}`.split("\n").select { |tag| tag.include?("refs/tags/#{@tag}") }
|
102
|
-
raise Informative, "
|
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
|
103
139
|
end
|
104
140
|
|
105
141
|
end
|
@@ -142,18 +178,18 @@ module Pod
|
|
142
178
|
def modify_podspec_ruby(file)
|
143
179
|
org_source = @spec_hash['source']
|
144
180
|
des_source = "{ :git => '#{org_source['git']}', :tag => '#{@tag}' }"
|
145
|
-
File.open(file, 'r') do |f|
|
181
|
+
File.open(file, 'r:utf-8') do |f|
|
146
182
|
lines = []
|
147
183
|
f.each_line do |line|
|
148
184
|
if line =~ /(^\s*.+\.version\s*=\s*).*/
|
149
|
-
line = line.sub(/(^\s*.+\.version\s*=\s*).*/, "#{$1}'#{@
|
185
|
+
line = line.sub(/(^\s*.+\.version\s*=\s*).*/, "#{$1}'#{@version}'")
|
150
186
|
end
|
151
187
|
if line =~ /(^\s*.+\.source\s*=\s*).*/
|
152
188
|
line = line.sub(/(^\s*.+\.source\s*=\s*).*/, "#{$1}#{des_source}")
|
153
189
|
end
|
154
190
|
lines << line
|
155
191
|
end
|
156
|
-
File.open(file, 'w') do |f|
|
192
|
+
File.open(file, 'w:utf-8') do |f|
|
157
193
|
f.write(lines.join(""))
|
158
194
|
end
|
159
195
|
end
|
@@ -161,12 +197,12 @@ module Pod
|
|
161
197
|
|
162
198
|
# 修改 *.podspec.json
|
163
199
|
def modify_podspec_json(file)
|
164
|
-
@spec_hash['version'] = @
|
200
|
+
@spec_hash['version'] = @version
|
165
201
|
@spec_hash['source'] = {
|
166
202
|
'git'=> @spec_hash['source']['git'],
|
167
203
|
'tag'=> "#{@tag}"
|
168
204
|
}
|
169
|
-
File.open(file, 'w') do |f|
|
205
|
+
File.open(file, 'w:utf-8') do |f|
|
170
206
|
f.write(@spec_hash)
|
171
207
|
end
|
172
208
|
end
|
@@ -177,7 +213,7 @@ module Pod
|
|
177
213
|
begin
|
178
214
|
`git add #{podspec}`
|
179
215
|
`git commit -m "#{@commit_msg}"`
|
180
|
-
`git push #{remote} #{current_branch}`
|
216
|
+
`git push #{remote} #{current_branch}` unless @skip_push_commit
|
181
217
|
rescue Pod::StandardError => e
|
182
218
|
@error = e
|
183
219
|
print "推送commit到远端git仓库`#{remote}/#{current_branch}`失败:#{e}".red
|
@@ -230,7 +266,7 @@ module Pod
|
|
230
266
|
# 获取当前分支
|
231
267
|
def current_branch
|
232
268
|
@current_branch ||= begin
|
233
|
-
`git
|
269
|
+
`git rev-parse --abbrev-ref HEAD`.chomp
|
234
270
|
end
|
235
271
|
end
|
236
272
|
|
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.
|
4
|
+
version: 0.0.5
|
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-
|
11
|
+
date: 2022-04-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: cocoapods
|