Class: Fastlane::Actions::GetLastCircleciBuildNumberAction

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

Class Method Summary collapse

Class Method Details

.authorsObject



54
55
56
# File 'lib/fastlane/plugin/get_last_circleci_build_number/actions/get_last_circleci_build_number_action.rb', line 54

def self.authors
  ["Dawid van der Hoven"]
end

.available_optionsObject



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/fastlane/plugin/get_last_circleci_build_number/actions/get_last_circleci_build_number_action.rb', line 68

def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :api_token,
                            env_name: "CIRCLECI_TOKEN",
                         description: "API Token for Circle CI",
                                type: String,
                            optional: true),
    FastlaneCore::ConfigItem.new(key: :user_name,
                            env_name: "CIRCLECI_USER_NAME",
                         description: "user name for Circle CI",
                                type: String,
                            optional: true),
    FastlaneCore::ConfigItem.new(key: :repository,
                            env_name: "CIRCLECI_REPOSITORY",
                         description: "repository for Circle CI",
                                type: String,
                            optional: true)
  ]
end

.configure(params) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/fastlane/plugin/get_last_circleci_build_number/actions/get_last_circleci_build_number_action.rb', line 25

def self.configure(params)
     @token = params[:api_token].nil? ? ENV['CIRCLECI_TOKEN'] : params[:api_token]
     @user = params[:user_name].nil? ? ENV['CIRCLECI_USER_NAME'] : params[:user_name]
     @repository = params[:repository].nil? ? ENV['CIRCLECI_REPOSITORY'] : params[:repository]

     CircleCi.configure do |config|
       config.token = @token
     end

     UI.user_error! "Set CIRCLECI_TOKEN" if @token.nil? || @token.empty?
     UI.user_error! "Set CIRCLECI_USER_NAME" if @user.nil? || @user.empty?
     UI.user_error! "Set CIRCLECI_REPOSITORY" if @repository.nil? || @repository.empty?
     UI.message "Access to #{@user}/#{@repository}"
end

.descriptionObject



50
51
52
# File 'lib/fastlane/plugin/get_last_circleci_build_number/actions/get_last_circleci_build_number_action.rb', line 50

def self.description
  "fetches the last build number from circleci."
end

.detailsObject



64
65
66
# File 'lib/fastlane/plugin/get_last_circleci_build_number/actions/get_last_circleci_build_number_action.rb', line 64

def self.details
  "Fetches that last build number from circleci using the circleci gem, useful for local builds when the project uses the circleci build number as the version build number."
end

.getObject



40
41
42
43
44
45
46
47
48
# File 'lib/fastlane/plugin/get_last_circleci_build_number/actions/get_last_circleci_build_number_action.rb', line 40

def self.get
  project = CircleCi::Project.new @user, @repository
  res = project.recent_builds limit: 1
  build_num = res.body.map do |e|
    e['build_num']
  end

  Actions.lane_context[SharedValues::GET_LAST_CIRCLECI_BUILD_NUMBER] = build_num[0]
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


88
89
90
# File 'lib/fastlane/plugin/get_last_circleci_build_number/actions/get_last_circleci_build_number_action.rb', line 88

def self.is_supported?(platform)
  [:ios, :mac, :android].include?(platform)
end

.outputObject



58
59
60
61
62
# File 'lib/fastlane/plugin/get_last_circleci_build_number/actions/get_last_circleci_build_number_action.rb', line 58

def self.output
  [
    ['LAST_CIRCLE_CI_BUILD_NUMBER', 'Last Build Number']
  ]
end

.run(params) ⇒ Object



10
11
12
13
14
15
# File 'lib/fastlane/plugin/get_last_circleci_build_number/actions/get_last_circleci_build_number_action.rb', line 10

def self.run(params)
     Actions.verify_gem!('circleci')
     require 'circleci'
     configure(params)
     get
end

.token(params) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/fastlane/plugin/get_last_circleci_build_number/actions/get_last_circleci_build_number_action.rb', line 17

def self.token(params)
     token = params[:api_token].nil? ? ENV['CIRCLECI_TOKEN'] : params[:api_token]
     CircleCi.configure do |config|
       config.token = token
     end
     token
end