-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathFastfile
131 lines (106 loc) · 3.24 KB
/
Fastfile
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
def update_dart(new_version)
path = Dir['../lib/**/qonversion_internal.dart'].first
regex = /static const String _sdkVersion = ".*";/
result_value = "static const String _sdkVersion = \"#{new_version}\";"
update_file(path, regex, result_value)
end
def update_yaml(new_version)
path = "../pubspec.yaml"
regex = /version: .*/
result_value = "version: #{new_version}"
update_file(path, regex, result_value)
end
def update_file(path, regex, result_value)
file = File.read(path)
new_content = file.gsub(regex, result_value)
File.open(path, 'w') { |line| line.puts new_content }
end
def update_changelog(new_version)
changelog_update = "\#\# #{new_version}\n* // Update changelog here\n\n"
path = "../CHANGELOG.md"
file = File.read(path)
File.open(path, 'w') { |line|
line.puts changelog_update + file
}
end
def upgrade_sandwich_android(new_version)
path = "../android/build.gradle"
common_part = "implementation \"io.qonversion.sandwich:sandwich:"
regex = /#{common_part}.*"/
result_value = "#{common_part}#{new_version}\""
update_file(path, regex, result_value)
end
def upgrade_sandwich_apple(platform, new_version)
path = "../#{platform}/qonversion_flutter.podspec"
common_part = "s.dependency \"QonversionSandwich\", \""
regex = /#{common_part}.*"/
result_value = "#{common_part}#{new_version}\""
update_file(path, regex, result_value)
end
def update_file(path, regex, result_value)
file = File.read(path)
new_content = file.gsub(regex, result_value)
File.open(path, 'w') { |line| line.puts new_content }
end
def get_tag
tag = last_git_tag()
puts tag
result_tag = tag.scan(%r{\d{1,2}.\d{1,2}.\d{1,3}}).first
return result_tag
end
def calculate_minor_version(tag)
major, minor, patch = parse_versions(tag)
new_minor_version = minor.to_i.next.to_s
new_version = major + "." + new_minor_version + "." + "0"
return new_version
end
def calculate_patch_version(tag)
major, minor, patch = parse_versions(tag)
new_patch_version = patch.to_i.next.to_s
new_version = major + "." + minor + "." + new_patch_version
return new_version
end
def push_tag(tag)
system("git checkout develop")
system("git pull origin develop")
add_git_tag(tag: tag)
push_git_tags(tag: tag)
end
def parse_versions(tag)
split_version_array = tag.split(".", 3)
if split_version_array.length == 3
major = split_version_array[0]
minor = split_version_array[1]
patch = split_version_array[2]
return major, minor, patch
end
end
lane :patch do
tag = get_tag
new_version = calculate_patch_version(tag)
new_tag = "prerelease/" + new_version
push_tag(new_tag)
end
lane :minor do
tag = get_tag
new_version = calculate_minor_version(tag)
new_tag = "prerelease/" + new_version
push_tag(new_tag)
end
lane :bump do |options|
new_version = options[:version]
update_dart(new_version)
update_yaml(new_version)
update_changelog(new_version)
end
lane :upgrade_sandwich do |options|
new_version = options[:version]
upgrade_sandwich_android(new_version)
upgrade_sandwich_apple("ios", new_version)
upgrade_sandwich_apple("macos", new_version)
end
lane :provide_next_patch_version do
tag = get_tag
new_version = calculate_patch_version(tag)
sh("echo version=#{new_version} >> \"$GITHUB_ENV\"")
end