Class: Fastlane::Actions::XamversionAction

Inherits:
Action
  • Object
show all
Defined in:
lib/fastlane/plugin/xamversion/actions/xamversion_action.rb

Class Method Summary collapse

Class Method Details

.authorsObject



135
136
137
# File 'lib/fastlane/plugin/xamversion/actions/xamversion_action.rb', line 135

def self.authors
  ["Jake Barnby"]
end

.available_optionsObject



148
149
150
# File 'lib/fastlane/plugin/xamversion/actions/xamversion_action.rb', line 148

def self.available_options
  ::Xamversion::Options.available_options
end

.descriptionObject



131
132
133
# File 'lib/fastlane/plugin/xamversion/actions/xamversion_action.rb', line 131

def self.description
  "Read and manipulate Android and iOS app versions."
end

.detailsObject



143
144
145
146
# File 'lib/fastlane/plugin/xamversion/actions/xamversion_action.rb', line 143

def self.details
  # Optional:
  "Allows you to read, set, increment and interactively bump Android and iOS app versions (following SemVer) and build numbers."
end

.do_version_bump_interactive(current_version) ⇒ Object



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
# File 'lib/fastlane/plugin/xamversion/actions/xamversion_action.rb', line 48

def self.do_version_bump_interactive(current_version)
  bump_type = UI.select("Version bump type: ", ["Patch", "Minor", "Major"]).downcase
  type_name = case bump_type
              when "patch"
                "bugfixes"
              when "minor"
                "features"
              when "major"
                "non-backwards compatible changes"
  end

  semver_version = Mixlib::Versioning.parse(current_version)

  increment = UI.input("How many new #{type_name} were added since last release?")

  if /\A\d+\Z/.match?(increment)
    increment = increment.to_i
  else
    UI.user_error!("Not a valid integer!")
  end

  puts "Increment: #{increment}"

  current_count = semver_version.instance_variable_get("@#{bump_type}")
  puts "Current count: #{current_count}"

  semver_version.instance_variable_set("@#{bump_type}", current_count + increment)
  puts "Semver: #{semver_version.to_semver_string}"
  semver_version.to_semver_string
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


152
153
154
# File 'lib/fastlane/plugin/xamversion/actions/xamversion_action.rb', line 152

def self.is_supported?(platform)
  true
end

.return_valueObject



139
140
141
# File 'lib/fastlane/plugin/xamversion/actions/xamversion_action.rb', line 139

def self.return_value
  "Hash containing the latest version and build."
end

.run(values) ⇒ Object



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
# File 'lib/fastlane/plugin/xamversion/actions/xamversion_action.rb', line 11

def self.run(values)
  values[:platform] = CsProj::Platform.from_lane_context(Actions.lane_context)

  CsProj.config = values.values

  current_version, current_build = set_version(
    values[:version],
    values[:build],
    values[:plist_path],
    values[:manifest_path]
  )

  if values[:bump] &&
      !values[:version] &&
      !values[:build] &&
      !values[:readonly]
    updated_version = do_version_bump_interactive(current_version)

    puts "Update version: #{updated_version}"
    new_version, new_build = set_version(
      updated_version || current_version,
      (current_build.to_i + 1).to_s,
      values[:plist_path],
      values[:manifest_path]
    )
  end

  UI.important "Current Version is:"
  UI.message "  Version: #{new_version || current_version} #{"(was #{current_version})" if !new_version.nil? && new_version != current_version}"
  UI.message "  Build: #{new_build || current_build} #{"(was #{current_build})" if !new_build.nil? && new_build != current_build}"

  {
    version: new_version,
    build: new_build
  }
end

.set_manifest_version(version, build, manifest_path = nil) ⇒ Object



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/fastlane/plugin/xamversion/actions/xamversion_action.rb', line 107

def self.set_manifest_version(version, build, manifest_path = nil)
  manifest_path ||= CsProj.config[:manifest_path]

  f1 = File.open(manifest_path)
  doc = Nokogiri::XML(f1)
  f1.close

  attrs = doc.xpath("//manifest")[0]

  version ||= attrs["android:versionName"]
  build ||= attrs["android:versionCode"]

  if version || build
    attrs["android:versionName"] = version if version
    attrs["android:versionCode"] = build if build

    File.open(manifest_path, "w") do |f2|
      f2.print(doc.to_xml)
    end
  end

  [version, build]
end

.set_plist_version(version, build, plist_path = nil) ⇒ Object



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/fastlane/plugin/xamversion/actions/xamversion_action.rb', line 87

def self.set_plist_version(version, build, plist_path = nil)
  plist_path ||= CsProj.config[:plist_path]
  version ||= other_action.get_info_plist_value(path: plist_path, key: "CFBundleShortVersionString")
  build ||= other_action.get_info_plist_value(path: plist_path, key: "CFBundleVersion")

  other_action.set_info_plist_value(
    path: plist_path,
    key: "CFBundleShortVersionString",
    value: version
  )

  other_action.set_info_plist_value(
    path: plist_path,
    key: "CFBundleVersion",
    value: build
  )

  [version, build]
end

.set_version(version, build, plist_path = nil, manifest_path = nil) ⇒ Object



79
80
81
82
83
84
85
# File 'lib/fastlane/plugin/xamversion/actions/xamversion_action.rb', line 79

def self.set_version(version, build, plist_path = nil, manifest_path = nil)
  if CsProj.project.ios? || CsProj.project.osx?
    set_plist_version(version, build, plist_path)
  elsif CsProj.project.android?
    set_manifest_version(version, build, manifest_path)
  end
end