Class: Fastlane::Actions::BuildkitePipelineUploadAction

Inherits:
Action
  • Object
show all
Defined in:
lib/fastlane/plugin/wpmreleasetoolkit/actions/common/buildkite_pipeline_upload_action.rb

Constant Summary collapse

DEFAULT_ENV_FILE =
File.join('.buildkite', 'shared-pipeline-vars').freeze

Class Method Summary collapse

Class Method Details

.authorsObject



54
55
56
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/common/buildkite_pipeline_upload_action.rb', line 54

def self.authors
  ['Automattic']
end

.available_optionsObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/common/buildkite_pipeline_upload_action.rb', line 30

def self.available_options
  [
    FastlaneCore::ConfigItem.new(
      key: :pipeline_file,
      description: 'The path to the YAML pipeline file to upload',
      optional: false,
      type: String
    ),
    FastlaneCore::ConfigItem.new(
      key: :env_file,
      description: 'The path to a bash file to be sourced before uploading the pipeline',
      optional: true,
      default_value: DEFAULT_ENV_FILE,
      type: String
    ),
    FastlaneCore::ConfigItem.new(
      key: :environment,
      description: 'Environment variables to load when running `pipeline upload`, to allow for variable substitution in the YAML pipeline',
      type: Hash,
      default_value: {}
    ),
  ]
end

.descriptionObject



25
26
27
28
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/common/buildkite_pipeline_upload_action.rb', line 25

def self.description
  # https://buildkite.com/docs/agent/v3/cli-pipeline#uploading-pipelines
  'Uploads a pipeline to Buildkite, adding all its steps to the current build'
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/common/buildkite_pipeline_upload_action.rb', line 58

def self.is_supported?(platform)
  true
end

.run(params) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/common/buildkite_pipeline_upload_action.rb', line 6

def self.run(params)
  pipeline_file = params[:pipeline_file]
  env_file = params[:env_file]
  environment = params[:environment]

  UI.user_error!("Pipeline file not found: #{pipeline_file}") unless File.exist?(pipeline_file)
  UI.user_error!('This action can only be called from a Buildkite CI build') unless ENV['BUILDKITE'] == 'true'

  UI.message "Adding steps from `#{pipeline_file}` to the current build"

  if env_file && File.exist?(env_file)
    UI.message(" - Sourcing environment file beforehand: #{env_file}")

    sh(environment, "source #{env_file.shellescape} && buildkite-agent pipeline upload #{pipeline_file.shellescape}")
  else
    sh(environment, 'buildkite-agent', 'pipeline', 'upload', pipeline_file)
  end
end