Class: Fastlane::Actions::CommonGitlabFastfileAction

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

Class Method Summary collapse

Class Method Details

.authorsObject



40
41
42
# File 'lib/fastlane/plugin/common_fastfile/actions/common_gitlab_fastfile_action.rb', line 40

def self.authors
  ["Pawel Szymanski"]
end

.available_optionsObject



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/fastlane/plugin/common_fastfile/actions/common_gitlab_fastfile_action.rb', line 53

def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :file,
                         description: "Path to the file within repository",
                            optional: false,
                           is_string: true,
                                type: String),
    FastlaneCore::ConfigItem.new(key: :version,
                         description: "Version of the file [branch, tag, commit]",
                            optional: false,
                           is_string: true,
                                type: String),
    FastlaneCore::ConfigItem.new(key: :repository,
                         description: "Gitlab repository ID, e.g. 26259886 or group/subgroup/repository",
                            optional: true,
                           is_string: true,
                                type: String),
  ]
end

.descriptionObject



36
37
38
# File 'lib/fastlane/plugin/common_fastfile/actions/common_gitlab_fastfile_action.rb', line 36

def self.description
  "Gets the requested file, saves it into ./fastlane/imports and return the path"
end

.detailsObject



48
49
50
51
# File 'lib/fastlane/plugin/common_fastfile/actions/common_gitlab_fastfile_action.rb', line 48

def self.details
  # Optional:
  "Gets the requested file, saves it into ./fastlane/imports and return the path"
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


73
74
75
# File 'lib/fastlane/plugin/common_fastfile/actions/common_gitlab_fastfile_action.rb', line 73

def self.is_supported?(platform)
  true
end

.return_valueObject



44
45
46
# File 'lib/fastlane/plugin/common_fastfile/actions/common_gitlab_fastfile_action.rb', line 44

def self.return_value
  "The path to a file within ./fastlane/imports with requested common fastfile"
end

.run(params) ⇒ Object



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

def self.run(params)
  require 'fileutils'
  require 'gitlab'

  begin
    if not file = params[:file] then raise StandardError.new "Cannot import due to missing 'file' value. Please provide the path to your file from ios-lib-scripts." end
    if not version = params[:version] then raise StandardError.new "Cannot import due to missing 'version' value. Please provide the [branch | tag | commit] for '#{file}'" end
    if not repository = params[:repository] || ENV['GITLAB_FASTFILES_REPOSITORY'] then raise StandardError.new "Cannot import due to missing 'repository' value. Please provide the Gitlab project ID or name or set 'GITLAB_FASTFILES_REPOSITORY' variable" end
  
    import_filename = "#{version.gsub(/[^0-9a-zA-Z-]/i, '_')}/#{file}"
    import_relative_path = "#{FastlaneCore::FastlaneFolder.path}imports/#{import_filename}"
    import_path = File.expand_path(import_relative_path)
    puts "Requested by: #{Thread.current.backtrace.find { |e| e.end_with?("in `parsing_binding'") }.gsub(/:\d*:in `parsing_binding'/i, '')}"
    puts " Downloading: #{file} [#{version}] from #{repository}"
    content = Gitlab.repo_file_contents(repository, file, version) 
    FileUtils.mkdir_p File.dirname(import_path)
    File.write(import_path, content)
    puts "    Saved in: #{import_relative_path}"          
    import_path
  rescue StandardError => e
    UI.important "Please check:
- if you have 'GITLAB_API_ENDPOINT' set, usually 'https://gitlab.com/api/v4'
- if you have 'GITLAB_API_PRIVATE_TOKEN' set, usually you can use 'https://gitlab.com/-/profile/personal_access_tokens' to set up one
- if you have 'GITLAB_FASTFILES_REPOSITORY' set with a Gitlab project ID or name, e.g. 'group/subgroup/repository'
Consider adding them to your .bash_profile, .zshrc or other shell configuration file"
    UI.user_error!("[common_fastfile] Download failure with:\n#{e}")
  end
end