Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ _None_

### New Features

_None_
- Make fastlane log actions as collapsible groups in Buildkite. [#638]

### Bug Fixes

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# frozen_string_literal: true

require 'fastlane'

# This monkey-patch adds Buildkite-aware logs to fastlane so it generates a collapsible log group in Buildkite for each action execution.
#
# @env `FASTLANE_DISABLE_ACTIONS_BUILDKITE_LOG_GROUPS`
# Set this variable to '1' to disable the auto-application of the monkey patch.

unless !ENV.key?('BUILDKITE') || FastlaneCore::Env.truthy?('FASTLANE_DISABLE_ACTIONS_BUILDKITE_LOG_GROUPS')
FastlaneCore::UI.verbose('Monkey-patching fastlane to add Buildkite-aware log groups for each action execution')

module Fastlane
module Actions
module SharedValues
# This differs from the existing `SharedValues::LANE_NAME`, which always contains the name of the **top-level** lane
CURRENTLY_RUNNING_LANE_NAME = :CURRENTLY_RUNNING_LANE_NAME
end

module BuildkiteLogActionsAsCollapsibleGroups
def execute_action(action_name, &)
unless %w[is_ci? is_ci].include?(action_name)
current_lane = lane_context[SharedValues::CURRENTLY_RUNNING_LANE_NAME]
lane_name_prefix = (current_lane || '').empty? ? '' : "[lane :#{current_lane}]"
puts "~~~ :fastlane: #{lane_name_prefix} #{action_name}"
end
super
end
end

class << self
prepend BuildkiteLogActionsAsCollapsibleGroups
end
end

class Runner
prepend(Module.new do
def current_lane=(lane_name)
super
Fastlane::Actions.lane_context[Fastlane::Actions::SharedValues::CURRENTLY_RUNNING_LANE_NAME] = lane_name
end
end)
end
end
end