This repository has been archived by the owner on Dec 3, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
release.rb
85 lines (69 loc) · 2.44 KB
/
release.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/usr/bin/ruby
require 'optparse'
$podspec_version_regex = /\.version\s*=\s*(["'])(.+)(?=\1)/
$podspec_name = 'SwiftyPlayer.podspec'
def run_cmd(cmd)
puts cmd
system cmd
raise "cmd failed, #{cmd}" unless $?.exitstatus == 0
end
def options_setting
options = {all: true}
OptionParser.new do |opts|
opts.banner = "Usage: release.rb [version]"
opts.separator "发布新版 SwiftyPlayer"
opts.separator "Options:"
# options (switch - true/false)
opts.on("-a", "--all", "是否发布 cocoapods carthage 和 SPM") do |a|
options[:all] = a
end
end.parse!
return options[:all]
end
def get_version
version = ARGV[0]
throw '版本号没传' if version.nil?
pattern = /(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?/
throw '版本号不符合语义化' unless pattern.match?(version)
podspec_content = File.read(File.join($podspec_name))
local_version = $podspec_version_regex.match(podspec_content).captures[1]
throw "传入的版本号比本地的小,local: #{local_version}" unless version > local_version
return version
end
def change_podspec_version version
podspec_content = File.read(File.join($podspec_name))
File.open($podspec_name, "w") do |file|
file.puts podspec_content.gsub($podspec_version_regex) { |m|
m.gsub($2, version)
}
end
end
def main
version = get_version
auto_release = options_setting
release_branch = "release/v#{version}"
run_cmd "git checkout -b #{release_branch}"
# Update podspec version
change_podspec_version version
run_cmd "git add #{$podspec_name}"
run_cmd "git commit -m 'Bump version to #{release_branch}'"
run_cmd "git checkout main"
run_cmd "git pull"
run_cmd "git merge --no-ff #{release_branch} -m 'Merge branch '#{release_branch}' into main'"
run_cmd "git push"
run_cmd "git tag -a #{version} -m 'Bump version'"
run_cmd "git push origin #{version}"
run_cmd "git checkout develop"
run_cmd "git merge --no-ff #{release_branch} -m 'Merge branch '#{release_branch}' into develop'"
run_cmd "git push"
run_cmd "git branch -D #{release_branch}"
if auto_release
puts "\n\n"
puts "---------- Cocoapods ----------"
run_cmd "pod spec lint #{$podspec_name}"
run_cmd "pod trunk push #{$podspec_name}"
end
puts "\n\n"
puts '👏👏👏👏👏👏 -Done- 👏👏👏👏👏👏'
end
main