Class: Fastlane::Actions::UpdateFastlaneAction
Overview
Makes sure fastlane tools are up-to-date when running fastlane
Constant Summary
collapse
- ALL_TOOLS =
["fastlane"]
Fastlane::Action::AVAILABLE_CATEGORIES, Fastlane::Action::RETURN_TYPES
Class Method Summary
collapse
action_name, author, deprecated_notes, lane_context, method_missing, other_action, output, return_type, return_value, sample_return_value, shell_out_should_use_bundle_exec?, step_text
Class Method Details
106
107
108
|
# File 'fastlane/lib/fastlane/actions/update_fastlane.rb', line 106
def self.all_installed_tools
Gem::Specification.select { |s| ALL_TOOLS.include?(s.name) }.map(&:name).uniq
end
|
.authors ⇒ Object
155
156
157
|
# File 'fastlane/lib/fastlane/actions/update_fastlane.rb', line 155
def self.authors
["milch", "KrauseFx"]
end
|
.available_options ⇒ Object
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
|
# File 'fastlane/lib/fastlane/actions/update_fastlane.rb', line 135
def self.available_options
[
FastlaneCore::ConfigItem.new(key: :nightly,
env_name: "FL_UPDATE_FASTLANE_NIGHTLY",
description: "Opt-in to install and use nightly fastlane builds",
is_string: false,
default_value: false),
FastlaneCore::ConfigItem.new(key: :no_update,
env_name: "FL_NO_UPDATE",
description: "Don't update during this run. This is used internally",
is_string: false,
default_value: false),
FastlaneCore::ConfigItem.new(key: :tools,
env_name: "FL_TOOLS_TO_UPDATE",
description: "Comma separated list of fastlane tools to update (e.g. `fastlane,deliver,sigh`)",
deprecated: true,
optional: true)
]
end
|
.category ⇒ Object
172
173
174
|
# File 'fastlane/lib/fastlane/actions/update_fastlane.rb', line 172
def self.category
:misc
end
|
.description ⇒ Object
110
111
112
|
# File 'fastlane/lib/fastlane/actions/update_fastlane.rb', line 110
def self.description
"Makes sure fastlane-tools are up-to-date when running fastlane"
end
|
.details ⇒ Object
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
|
# File 'fastlane/lib/fastlane/actions/update_fastlane.rb', line 114
def self.details
sample = <<-SAMPLE.markdown_sample
```bash
export GEM_HOME=~/.gems
export PATH=$PATH:~/.gems/bin
```
SAMPLE
[
"This action will update fastlane to the most recent version - major version updates will not be performed automatically, as they might include breaking changes. If an update was performed, fastlane will be restarted before the run continues.",
"",
"If you are using rbenv or rvm, everything should be good to go. However, if you are using the system's default ruby, some additional setup is needed for this action to work correctly. In short, fastlane needs to be able to access your gem library without running in `sudo` mode.",
"",
"The simplest possible fix for this is putting the following lines into your `~/.bashrc` or `~/.zshrc` file:".markdown_preserve_newlines,
sample,
"After the above changes, restart your terminal, then run `mkdir $GEM_HOME` to create the new gem directory. After this, you're good to go!",
"",
"Recommended usage of the `update_fastlane` action is at the top inside of the `before_all` block, before running any other action."
].join("\n")
end
|
.example_code ⇒ Object
163
164
165
166
167
168
169
170
|
# File 'fastlane/lib/fastlane/actions/update_fastlane.rb', line 163
def self.example_code
[
'before_all do
update_fastlane
# ...
end'
]
end
|
.is_supported?(platform) ⇒ Boolean
159
160
161
|
# File 'fastlane/lib/fastlane/actions/update_fastlane.rb', line 159
def self.is_supported?(platform)
true
end
|
.run(options) ⇒ Object
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
|
# File 'fastlane/lib/fastlane/actions/update_fastlane.rb', line 10
def self.run(options)
return if options[:no_update]
tools_to_update = options[:tools].split(',') unless options[:tools].nil?
tools_to_update ||= all_installed_tools
if tools_to_update.count == 0
UI.error("No tools specified or couldn't find any installed fastlane.tools")
return
end
UI.message("Looking for updates for #{tools_to_update.join(', ')}...")
updater = Gem::CommandManager.instance[:update]
updater.options[:prerelease] = true if options[:nightly]
cleaner = Gem::CommandManager.instance[:cleanup]
gem_dir = ENV['GEM_HOME'] || Gem.dir
sudo_needed = !File.writable?(gem_dir)
if sudo_needed
UI.important("It seems that your Gem directory is not writable by your current user.")
UI.important("fastlane would need sudo rights to update itself, however, running 'sudo fastlane' is not recommended.")
UI.important("If you still want to use this action, please read the documentation on how to set this up:")
UI.important("https://docs.fastlane.tools/actions/#update_fastlane")
return
end
unless updater.respond_to?(:highest_installed_gems)
UI.important("The update_fastlane action requires rubygems version 2.1.0 or greater.")
UI.important("Please update your version of ruby gems before proceeding.")
UI.command "gem install rubygems-update"
UI.command "update_rubygems"
UI.command "gem update --system"
return
end
highest_versions = updater.highest_installed_gems.keep_if { |key| tools_to_update.include?(key) }
update_needed = updater.which_to_update(highest_versions, tools_to_update)
if update_needed.count == 0
UI.success("Nothing to update ✅")
show_information_about_nightly_builds unless options[:nightly]
return
end
Gem::DefaultUserInteraction.ui = Gem::SilentUI.new
update_needed.each do |tool_info|
tool = tool_info[0]
gem_version = tool_info[1]
local_version = Gem::Version.new(highest_versions[tool].version)
latest_official_version = FastlaneCore::UpdateChecker.fetch_latest(tool)
if options[:nightly]
UI.message("Updating #{tool} from #{local_version.to_s.yellow} to nightly build #{gem_version.to_s.yellow}... (last official release #{latest_official_version.to_s.yellow}) 🚀")
else
UI.message("Updating #{tool} from #{local_version.to_s.yellow} to #{latest_official_version.to_s.yellow}... 🚀")
end
requirement_version = options[:nightly] ? gem_version : local_version.approximate_recommendation
updater.update_gem(tool, Gem::Requirement.new(requirement_version))
UI.success("Finished updating #{tool}")
end
UI.message("Cleaning up old versions...")
cleaner.options[:args] = tools_to_update
cleaner.execute
if options[:nightly]
UI.success("Thanks for using fastlane's nightly builds! This makes it easier for everyone to detect regressions earlier.")
UI.success("Please submit an issue on GitHub if anything behaves differently than it should 🍪")
else
show_information_about_nightly_builds
end
UI.message("fastlane.tools successfully updated! I will now restart myself... 😴")
exec("FL_NO_UPDATE=true #{$PROGRAM_NAME} #{ARGV.join(' ')}")
end
|
95
96
97
98
99
100
101
102
103
104
|
# File 'fastlane/lib/fastlane/actions/update_fastlane.rb', line 95
def self.show_information_about_nightly_builds
UI.message("")
UI.message("Please help us test early releases of fastlane by opting into nightly builds 🌃")
UI.message("Just replace your `update_fastlane` call with")
UI.message("")
UI.command_output("update_fastlane(nightly: true)")
UI.message("")
UI.message("Nightly builds are reviewed and tested just like the public releases 🚂")
UI.message("")
end
|