Module: Fastlane::Actions

Defined in:
lib/fastlane/actions/s3.rb,
lib/fastlane/actions/ipa.rb,
lib/fastlane/actions/pem.rb,
lib/fastlane/actions/say.rb,
lib/fastlane/actions/cert.rb,
lib/fastlane/actions/lcov.rb,
lib/fastlane/actions/puts.rb,
lib/fastlane/actions/sigh.rb,
lib/fastlane/actions/gcovr.rb,
lib/fastlane/actions/slack.rb,
lib/fastlane/actions/hockey.rb,
lib/fastlane/actions/import.rb,
lib/fastlane/actions/notify.rb,
lib/fastlane/actions/oclint.rb,
lib/fastlane/actions/prompt.rb,
lib/fastlane/actions/resign.rb,
lib/fastlane/actions/xctool.rb,
lib/fastlane/actions/deliver.rb,
lib/fastlane/actions/frameit.rb,
lib/fastlane/actions/hg_push.rb,
lib/fastlane/actions/hipchat.rb,
lib/fastlane/actions/mailgun.rb,
lib/fastlane/actions/produce.rb,
lib/fastlane/actions/team_id.rb,
lib/fastlane/actions/appstore.rb,
lib/fastlane/actions/chatwork.rb,
lib/fastlane/actions/dsym_zip.rb,
lib/fastlane/actions/git_pull.rb,
lib/fastlane/actions/snapshot.rb,
lib/fastlane/actions/testmunk.rb,
lib/fastlane/actions/typetalk.rb,
lib/fastlane/actions/team_name.rb,
lib/fastlane/actions/deploygate.rb,
lib/fastlane/actions/git_branch.rb,
lib/fastlane/actions/hg_add_tag.rb,
lib/fastlane/actions/testflight.rb,
lib/fastlane/actions/xcodebuild.rb,
lib/fastlane/actions/add_git_tag.rb,
lib/fastlane/actions/backup_file.rb,
lib/fastlane/actions/crashlytics.rb,
lib/fastlane/actions/lane_context.rb,
lib/fastlane/actions/last_git_tag.rb,
lib/fastlane/actions/restore_file.rb,
lib/fastlane/actions/xcode_select.rb,
lib/fastlane/actions/opt_out_usage.rb,
lib/fastlane/actions/set_changelog.rb,
lib/fastlane/actions/actions_helper.rb,
lib/fastlane/actions/reset_git_repo.rb,
lib/fastlane/actions/create_keychain.rb,
lib/fastlane/actions/delete_keychain.rb,
lib/fastlane/actions/update_fastlane.rb,
lib/fastlane/actions/backup_xcarchive.rb,
lib/fastlane/actions/default_platform.rb,
lib/fastlane/actions/fastlane_version.rb,
lib/fastlane/actions/install_carthage.rb,
lib/fastlane/actions/install_cocapods.rb,
lib/fastlane/actions/register_devices.rb,
lib/fastlane/actions/ensure_git_branch.rb,
lib/fastlane/actions/update_info_plist.rb,
lib/fastlane/actions/get_github_release.rb,
lib/fastlane/actions/import_certificate.rb,
lib/fastlane/actions/push_to_git_remote.rb,
lib/fastlane/actions/set_github_release.rb,
lib/fastlane/actions/commit_version_bump.rb,
lib/fastlane/actions/ensure_no_debug_code.rb,
lib/fastlane/actions/clean_build_artifacts.rb,
lib/fastlane/actions/hg_commit_version_bump.rb,
lib/fastlane/actions/hg_ensure_clean_status.rb,
lib/fastlane/actions/increment_build_number.rb,
lib/fastlane/actions/ensure_git_status_clean.rb,
lib/fastlane/actions/increment_version_number.rb,
lib/fastlane/actions/set_build_number_repository.rb,
lib/fastlane/actions/update_project_code_signing.rb,
lib/fastlane/actions/update_project_provisioning.rb,
lib/fastlane/actions/update_app_group_identifiers.rb

Defined Under Namespace

Modules: SharedValues Classes: AddGitTagAction, AppstoreAction, BackupFileAction, BackupXcarchiveAction, CarthageAction, CertAction, ChatworkAction, CleanBuildArtifactsAction, CocoapodsAction, CommitVersionBumpAction, CrashlyticsAction, CreateKeychainAction, DefaultPlatformAction, DeleteKeychainAction, DeliverAction, DeploygateAction, DsymZipAction, EnsureGitBranchAction, EnsureGitStatusCleanAction, EnsureNoDebugCodeAction, FastlaneVersionAction, FrameitAction, GcovrAction, GetGithubReleaseAction, GitBranchAction, GitPullAction, HgAddTagAction, HgCommitVersionBumpAction, HgEnsureCleanStatusAction, HgPushAction, HipchatAction, HockeyAction, ImportAction, ImportCertificateAction, IncrementBuildNumberAction, IncrementVersionNumberAction, IpaAction, LaneContextAction, LastGitTagAction, LcovAction, MailgunAction, NotifyAction, OclintAction, OptOutUsageAction, PemAction, ProduceAction, PromptAction, PushToGitRemoteAction, PutsAction, RegisterDevicesAction, ResetGitRepoAction, ResignAction, RestoreFileAction, S3Action, SayAction, SetBuildNumberRepositoryAction, SetChangelogAction, SetGithubReleaseAction, SighAction, SlackAction, SnapshotAction, TeamIdAction, TeamNameAction, TestflightAction, TestmunkAction, TypetalkAction, UpdateAppGroupIdentifiersAction, UpdateFastlaneAction, UpdateInfoPlistAction, UpdateProjectCodeSigningAction, UpdateProjectProvisioningAction, XcarchiveAction, XcbuildAction, XccleanAction, XcexportAction, XcodeSelectAction, XcodebuildAction, XctestAction, XctoolAction

Constant Summary collapse

S3_ARGS_MAP =
{
  ipa: '-f',
  dsym: '-d',
  access_key: '-a',
  secret_access_key: '-s',
  bucket: '-b',
  region: '-r',
  acl: '--acl',
  source: '--source-dir',
  path: '-P',
}
ARGS_MAP =
{
  workspace: '-w',
  project: '-p',
  configuration: '-c',
  scheme: '-s',
  clean: '--clean',
  archive: '--archive',
  destination: '-d',
  embed: '-m',
  identity: '-i',
  sdk: '--sdk',
  ipa: '--ipa',
  xcconfig: '--xcconfig',
  xcargs: '--xcargs'
}

Class Method Summary collapse

Class Method Details

.clear_lane_contextObject

Used in tests to get a clear lane before every test



46
47
48
# File 'lib/fastlane/actions/actions_helper.rb', line 46

def self.clear_lane_context
  @lane_context = nil
end

.execute_action(step_name) ⇒ Object

Pass a block which should be tracked. One block = one testcase

Parameters:

  • step_name (String)

    the name of the currently built code (e.g. snapshot, sigh, …) This might be nil, in which case the step is not printed out to the terminal



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
# File 'lib/fastlane/actions/actions_helper.rb', line 53

def self.execute_action(step_name)
  start = Time.now # before the raise block, since `start` is required in the ensure block
  raise 'No block given'.red unless block_given?

  error = nil
  exc = nil

  begin
    Helper.log_alert("Step: " + step_name) if step_name
    yield
  rescue => ex
    exc = ex
    error = caller.join("\n") + "\n\n" + ex.to_s
  end
ensure
  # This is also called, when the block has a return statement
  if step_name
    duration = Time.now - start

    executed_actions << {
      name: step_name,
      error: error,
      time: duration
    }
  end

  raise exc if exc
end

.executed_actionsObject



36
37
38
# File 'lib/fastlane/actions/actions_helper.rb', line 36

def self.executed_actions
  @executed_actions ||= []
end

.get_all_official_actionsObject

returns a list of official integrations



128
129
130
131
132
# File 'lib/fastlane/actions/actions_helper.rb', line 128

def self.get_all_official_actions
  Dir[File.expand_path '*.rb', File.dirname(__FILE__)].collect do |file|
    File.basename(file).gsub('.rb', '').to_sym
  end
end

.git_authorObject

Helper Methods



12
13
14
15
16
17
18
19
# File 'lib/fastlane/actions/actions_helper.rb', line 12

def self.git_author
  s = `git log --name-status HEAD^..HEAD`
  s = s.match(/Author:.*<(.*)>/)[1]
  return s if s.to_s.length > 0
  return nil
rescue
  return nil
end

.git_branchObject

Returns the current git branch - can be replaced using the environment variable ‘GIT_BRANCH`



28
29
30
31
32
33
# File 'lib/fastlane/actions/actions_helper.rb', line 28

def self.git_branch
  return ENV['GIT_BRANCH'] if ENV['GIT_BRANCH'].to_s.length > 0 # set by Jenkins
  s = `git rev-parse --abbrev-ref HEAD`
  return s.to_s.strip if s.to_s.length > 0
  nil
end

.lane_contextObject

The shared hash can be accessed by any action and contains information like the screenshots path or beta URL



41
42
43
# File 'lib/fastlane/actions/actions_helper.rb', line 41

def self.lane_context
  @lane_context ||= {}
end

.last_git_commitObject



21
22
23
24
25
# File 'lib/fastlane/actions/actions_helper.rb', line 21

def self.last_git_commit
  s = `git log -1 --pretty=%B`.strip
  return s if s.to_s.length > 0
  nil
end

.load_default_actionsObject



134
135
136
137
138
# File 'lib/fastlane/actions/actions_helper.rb', line 134

def self.load_default_actions
  Dir[File.expand_path '*.rb', File.dirname(__FILE__)].each do |file|
    require file
  end
end

.load_external_actions(path) ⇒ Object



140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'lib/fastlane/actions/actions_helper.rb', line 140

def self.load_external_actions(path)
  raise 'You need to pass a valid path' unless File.exist?(path)

  Dir[File.expand_path('*.rb', path)].each do |file|
    require file

    file_name = File.basename(file).gsub('.rb', '')

    class_name = file_name.fastlane_class + 'Action'
    class_ref = nil
    begin
      class_ref = Fastlane::Actions.const_get(class_name)

      if class_ref.respond_to?(:run)
        Helper.log.info "Successfully loaded custom action '#{file}'.".green
      else
        Helper.log.error "Could not find method 'run' in class #{class_name}.".red
        Helper.log.error 'For more information, check out the docs: https://github.com/KrauseFx/fastlane'
        raise "Plugin '#{file_name}' is damaged!"
      end
    rescue NameError => ex
      # Action not found
      Helper.log.error "Could not find '#{class_name}' class defined.".red
      Helper.log.error 'For more information, check out the docs: https://github.com/KrauseFx/fastlane'
      raise "Plugin '#{file_name}' is damaged!"
    end
  end
end

.sh(command, log: true) ⇒ Object

Execute a shell command This method will output the string and execute it Just an alias for sh_no_action

Parameters:

  • log (boolean) (defaults to: true)

    should fastlane print out the executed command



86
87
88
# File 'lib/fastlane/actions/actions_helper.rb', line 86

def self.sh(command, log: true)
  sh_no_action(command, log: log)
end

.sh_no_action(command, log: true) ⇒ Object



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
# File 'lib/fastlane/actions/actions_helper.rb', line 90

def self.sh_no_action(command, log: true)
  # Set the encoding first, the user might have set it wrong
  previous_encoding = [Encoding.default_external, Encoding.default_internal]
  Encoding.default_external = Encoding::UTF_8
  Encoding.default_internal = Encoding::UTF_8

  command = command.join(' ') if command.is_a?(Array) # since it's an array of one element when running from the Fastfile
  Helper.log.info ['[SHELL COMMAND]', command.yellow].join(': ') if log

  result = ''
  unless Helper.test?
    exit_status = nil
    status = IO.popen(command, err: [:child, :out]) do |io|
      io.each do |line|
        Helper.log.info ['[SHELL]', line.strip].join(': ')
        result << line
      end
      io.close
      exit_status = $?.to_i
    end

    if exit_status != 0
      # this will also append the output to the exception (for the Jenkins reports)
      raise "Exit status of command '#{command}' was #{exit_status} instead of 0. \n#{result}"
    end
  else
    result << command # only for the tests
  end

  result
rescue => ex
  raise ex
ensure
  Encoding.default_external = previous_encoding.first
  Encoding.default_internal = previous_encoding.last
end