-
Notifications
You must be signed in to change notification settings - Fork 1
/
flutter_utils.rb
58 lines (49 loc) · 1.5 KB
/
flutter_utils.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
require 'yaml'
module FlutterUtils
def self._config_path
return Dir.pwd + '/../../pubspec.yaml'
end
def self._load_pubspec
return YAML.load_file(_config_path())
end
def self._parse_version(pubspec)
version_str = pubspec['version']
sections = version_str.split('+')
if sections.length() != 2
raise "Malformed flutter version string #{version_str}"
end
return sections
end
# Returns build number e.g. 12
def self.version
pubspec = _load_pubspec()
sections = _parse_version(pubspec)
return sections[1].to_i
end
# Returns string version, e.g. 2.0.3
def self.version_name
pubspec = _load_pubspec()
sections = _parse_version(pubspec)
return sections[0]
end
def self.bump_version
pubspec = _load_pubspec()
sections = _parse_version(pubspec)
old_version_str = "#{sections[0]}+#{sections[1]}"
new_version = sections[1].to_i + 1
new_version_str = "2.0.#{new_version}+#{new_version}"
text = File.open(_config_path()).read()
if text.gsub!(old_version_str, new_version_str) == nil
raise "Error editing pubspec.yaml, could not replace #{old_version_str} with #{new_version_str}"
end
File.open(_config_path(), 'w') do |out|
out.write(text)
end
system("git", "commit", "-m", "Prepare to release #{new_version_str}",
_config_path(), exception: true)
return new_version
end
def self.create_tag(release)
system("git", "tag", "-a", "-f", "-m", "Version #{release}", release)
end
end