Skip to content

Commit

Permalink
[actions] support for slather --ymlfile option (#21613)
Browse files Browse the repository at this point in the history
  • Loading branch information
jarrodlombardo-EventBase committed Nov 12, 2023
1 parent 5017060 commit cc19214
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 23 deletions.
21 changes: 17 additions & 4 deletions fastlane/lib/fastlane/actions/slather.rb
Expand Up @@ -35,7 +35,8 @@ class SlatherAction < Action
binary_basename: '--binary-basename',
arch: '--arch',
source_files: '--source-files',
decimals: '--decimals'
decimals: '--decimals',
ymlfile: '--ymlfile'
}.freeze

def self.run(params)
Expand All @@ -51,8 +52,8 @@ def self.run(params)
sh(command)
end

def self.has_config_file
File.file?('.slather.yml')
def self.has_config_file?(params)
params[:ymlfile] ? File.file?(params[:ymlfile]) : File.file?('.slather.yml')
end

def self.slather_version
Expand All @@ -64,12 +65,20 @@ def self.configuration_available?
Gem::Version.new('2.4.1') <= Gem::Version.new(slather_version)
end

def self.ymlfile_available?
Gem::Version.new('2.8.0') <= Gem::Version.new(slather_version)
end

def self.validate_params!(params)
if params[:configuration]
UI.user_error!('configuration option is available since version 2.4.1') unless configuration_available?
end

if params[:proj] || has_config_file
if params[:ymlfile]
UI.user_error!('ymlfile option is available since version 2.8.0') unless ymlfile_available?
end

if params[:proj] || has_config_file?(params)
true
else
UI.user_error!("You have to provide a project with `:proj` or use a .slather.yml")
Expand Down Expand Up @@ -285,6 +294,10 @@ def self.available_options
description: "The amount of decimals to use for % coverage reporting",
skip_type_validation: true, # allow Integer, String
default_value: false,
optional: true),
FastlaneCore::ConfigItem.new(key: :ymlfile,
env_name: "FL_SLATHER_YMLFILE",
description: "Relative path to a file used in place of '.slather.yml'",
optional: true)
]
end
Expand Down
96 changes: 79 additions & 17 deletions fastlane/spec/actions_specs/slather_spec.rb
Expand Up @@ -3,7 +3,7 @@
describe "Slather Integration" do
let(:action) { Fastlane::Actions::SlatherAction }
it "works with all parameters" do
allow(Fastlane::Actions::SlatherAction).to receive(:slather_version).and_return(Gem::Version.create('2.4.1'))
allow(Fastlane::Actions::SlatherAction).to receive(:slather_version).and_return(Gem::Version.create('2.8.0'))
source_files = "*.swift"
result = Fastlane::FastFile.new.parse("lane :test do
slather({
Expand Down Expand Up @@ -37,7 +37,8 @@
workspace: 'foo.xcworkspace',
arch: 'arm64',
source_files: '#{source_files}',
decimals: '2'
decimals: '2',
ymlfile: 'foo.yml'
})
end").runner.execute(:test)

Expand Down Expand Up @@ -71,13 +72,15 @@
--binary-basename YourFramework
--arch arm64
--source-files #{source_files.shellescape}
--decimals 2 foo.xcodeproj".gsub(/\s+/, ' ')
--decimals 2
--ymlfile foo.yml
foo.xcodeproj".gsub(/\s+/, ' ')
expect(result).to eq(expected)
end

it "works with bundle" do
allow(FastlaneCore::FastlaneFolder).to receive(:path).and_return(nil)
allow(Fastlane::Actions::SlatherAction).to receive(:slather_version).and_return(Gem::Version.create('2.4.1'))
allow(Fastlane::Actions::SlatherAction).to receive(:slather_version).and_return(Gem::Version.create('2.8.0'))
result = Fastlane::FastFile.new.parse("lane :test do
slather({
use_bundle_exec: true,
Expand Down Expand Up @@ -105,7 +108,8 @@
proj: 'foo.xcodeproj',
binary_basename: ['YourApp', 'YourFramework'],
binary_file: 'you',
workspace: 'foo.xcworkspace'
workspace: 'foo.xcworkspace',
ymlfile: 'foo.yml'
})
end").runner.execute(:test)

Expand Down Expand Up @@ -134,7 +138,9 @@
--workspace foo.xcworkspace
--binary-file you
--binary-basename YourApp
--binary-basename YourFramework foo.xcodeproj'.gsub(/\s+/, ' ')
--binary-basename YourFramework
--ymlfile foo.yml
foo.xcodeproj'.gsub(/\s+/, ' ')
expect(result).to eq(expected)
end

Expand Down Expand Up @@ -168,12 +174,14 @@
end

it "works with spaces in paths" do
allow(Fastlane::Actions::SlatherAction).to receive(:slather_version).and_return(Gem::Version.create('2.8.0'))
build_dir = "build dir"
source_dir = "source dir"
output_dir = "output dir"
ignore = "nothing to ignore"
scheme = "Foo App"
proj = "foo bar.xcodeproj"
ymlfile = "fake yml file.yml"
result = Fastlane::FastFile.new.parse("lane :test do
slather({
build_directory: '#{build_dir}',
Expand All @@ -182,6 +190,7 @@
source_directory: '#{source_dir}',
output_directory: '#{output_dir}',
ignore: '#{ignore}',
ymlfile: '#{ymlfile}',
proj: '#{proj}'
})
end").runner.execute(:test)
Expand All @@ -193,6 +202,7 @@
--ignore #{ignore.shellescape}
--input-format bah
--scheme #{scheme.shellescape}
--ymlfile #{ymlfile.shellescape}
#{proj.shellescape}".gsub(/\s+/, ' ')
expect(result).to eq(expected)
end
Expand Down Expand Up @@ -341,26 +351,78 @@
end
end

describe "#ymlfile_available?" do
let(:param) { { use_bundle_exec: false } }
let(:version) { '' }
before do
allow(action).to receive(:slather_version).and_return(Gem::Version.create(version))
end

context "when slather version is 2.7.0" do
let(:version) { '2.7.0' }
it "ymlfile option is not available" do
expect(action.ymlfile_available?).to be_falsey
end
end

context "when slather version is 2.8.0" do
let(:version) { '2.8.0' }
it "ymlfile option is available" do
expect(action.ymlfile_available?).to be_truthy
end
end

context "when slather version is 2.8.1" do
let(:version) { '2.8.1' }
it "ymlfile option is available" do
expect(action.ymlfile_available?).to be_truthy
end
end
end

describe "#validate_params!" do
let(:param) { { configuration: 'Debug', proj: 'test.xcodeproj' } }
let(:version) { '' }
before do
allow(action).to receive(:slather_version).and_return(Gem::Version.create(version))
end

context "when slather version is 2.4.0" do
let(:version) { '2.4.0' }
it "does not pass the validation" do
expect do
action.validate_params!(param)
end.to raise_error(FastlaneCore::Interface::FastlaneError, 'configuration option is available since version 2.4.1')
describe "with configuration param" do
let(:param) { { configuration: 'Debug', proj: 'test.xcodeproj' } }

context "when slather version is 2.4.0" do
let(:version) { '2.4.0' }
it "does not pass the validation" do
expect do
action.validate_params!(param)
end.to raise_error(FastlaneCore::Interface::FastlaneError, 'configuration option is available since version 2.4.1')
end
end

context "when slather version is 2.4.1" do
let(:version) { '2.4.1' }
it "pass the validation" do
expect(action.validate_params!(param)).to be_truthy
end
end
end

context "when slather version is 2.4.1" do
let(:version) { '2.4.1' }
it "pass the validation" do
expect(action.validate_params!(param)).to be_truthy
describe "with ymlfile param" do
let(:param) { { ymlfile: 'foo.yml', proj: 'test.xcodeproj' } }

context "when slather version is 2.7.0" do
let(:version) { '2.7.0' }
it "does not pass the validation" do
expect do
action.validate_params!(param)
end.to raise_error(FastlaneCore::Interface::FastlaneError, 'ymlfile option is available since version 2.8.0')
end
end

context "when slather version is 2.8.0" do
let(:version) { '2.8.0' }
it "pass the validation" do
expect(action.validate_params!(param)).to be_truthy
end
end
end
end
Expand Down
8 changes: 6 additions & 2 deletions fastlane/swift/Fastlane.swift
Expand Up @@ -10282,6 +10282,7 @@ public func slackTrainStart(distance: Int = 5,
- arch: Specify which architecture the binary file is in. Needed for universal binaries
- sourceFiles: A Dir.glob compatible pattern used to limit the lookup to specific source files. Ignored in gcov mode
- decimals: The amount of decimals to use for % coverage reporting
- ymlfile: Relative path to a file used in place of '.slather.yml'

Slather works with multiple code coverage formats, including Xcode 7 code coverage.
Slather is available at [https://github.com/SlatherOrg/slather](https://github.com/SlatherOrg/slather).
Expand Down Expand Up @@ -10317,7 +10318,8 @@ public func slather(buildDirectory: OptionalConfigValue<String?> = .fastlaneDefa
binaryFile: OptionalConfigValue<[String]?> = .fastlaneDefault(nil),
arch: OptionalConfigValue<String?> = .fastlaneDefault(nil),
sourceFiles: OptionalConfigValue<Bool> = .fastlaneDefault(false),
decimals: OptionalConfigValue<Bool> = .fastlaneDefault(false))
decimals: OptionalConfigValue<Bool> = .fastlaneDefault(false)),
ymlfile: OptionalConfigValue<String?> = .fastlaneDefault(nil)
{
let buildDirectoryArg = buildDirectory.asRubyArgument(name: "build_directory", type: nil)
let projArg = proj.asRubyArgument(name: "proj", type: nil)
Expand Down Expand Up @@ -10351,6 +10353,7 @@ public func slather(buildDirectory: OptionalConfigValue<String?> = .fastlaneDefa
let archArg = arch.asRubyArgument(name: "arch", type: nil)
let sourceFilesArg = sourceFiles.asRubyArgument(name: "source_files", type: nil)
let decimalsArg = decimals.asRubyArgument(name: "decimals", type: nil)
let ymlfileArg = ymlfile.asRubyArgument(name: "ymlfile", type: nil)
let array: [RubyCommand.Argument?] = [buildDirectoryArg,
projArg,
workspaceArg,
Expand Down Expand Up @@ -10382,7 +10385,8 @@ public func slather(buildDirectory: OptionalConfigValue<String?> = .fastlaneDefa
binaryFileArg,
archArg,
sourceFilesArg,
decimalsArg]
decimalsArg,
ymlfileArg]
let args: [RubyCommand.Argument] = array
.filter { $0?.value != nil }
.compactMap { $0 }
Expand Down

0 comments on commit cc19214

Please sign in to comment.