Skip to content

Commit

Permalink
feat: includes fastlane in gem file
Browse files Browse the repository at this point in the history
  • Loading branch information
GMinucci committed Jan 15, 2025
1 parent d6d23b9 commit daeb6a2
Show file tree
Hide file tree
Showing 5 changed files with 152 additions and 147 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@ jobs:

steps:
- uses: actions/checkout@v2

- uses: swift-actions/setup-swift@v2
with:
swift-version: ${{ matrix.swift }}

- name: Run unit tests and coverage
run: make coverage
- name: Run CI validation
run: make ci-validation

#
# CODECOV temporarily disabled due to issues running 'bundle install'
Expand Down
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
source 'https://rubygems.org'

gem "fastlane"
gem "slather"
gem "nokogiri", ">= 1.13.2"
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,8 @@ lint:
validation: lint coverage
@rm -rf variants.yml
@echo "Ready to go."

.PHONY: ci-validation
validation: coverage
@rm -rf variants.yml
@echo "Ready to go."
141 changes: 70 additions & 71 deletions Sources/VariantsCore/Custom Types/Project/AndroidProject.swift
Original file line number Diff line number Diff line change
Expand Up @@ -103,84 +103,83 @@ class AndroidProject: Project {

// swiftlint:disable:next function_body_length
private func setupFastlane(with configuration: AndroidConfiguration, skip: Bool) {
if skip {
Logger.shared.logInfo("Skipped Fastlane setup", item: "")
} else {
Logger.shared.logInfo("Setting up Fastlane", item: "")

do {
let projectSourceFolder = configuration.path
let path = try TemplateDirectory().path
try Bash("cp", arguments: "-R", "\(path.absolute())/android/_fastlane/", ".")
.run()

let baseSetupCompletedMessage =
"""
✅ Your variants configuration was setup
✅ For configuration properties with 'project' destination, they have been
stored in '\(projectSourceFolder)/gradleScripts/variants.gradle'.
This gradle file should be used by your 'app/build.gradle' in order to read the app's
information and custom properties you've set with destination 'project'.
🔄 Use 'variants switch --variants <value>' to switch between variants and
update the properties in the files described above.
That is all.
"""

var setupCompleteMessage =
guard skip == false else {
return Logger.shared.logInfo("Skipped Fastlane setup for Android", item: "")
}

Logger.shared.logInfo("Setting up Fastlane for Android", item: "")
do {
let projectSourceFolder = configuration.path
let path = try TemplateDirectory().path
try Bash("cp", arguments: "-R", "\(path.absolute())/android/_fastlane/", ".")
.run()

let baseSetupCompletedMessage =
"""
✅ Your variants configuration was setup
✅ For configuration properties with 'project' destination, they have been
stored in '\(projectSourceFolder)/gradleScripts/variants.gradle'.
This gradle file should be used by your 'app/build.gradle' in order to read the app's
information and custom properties you've set with destination 'project'.
🔄 Use 'variants switch --variants <value>' to switch between variants and
update the properties in the files described above.
That is all.
"""

var setupCompleteMessage =
"""
We got almost everything done!
❌ Fastlane could not be setup. The template wasn't found or something else went wrong when
copying it.
"""

if StaticPath.Fastlane.baseFolder.isDirectory {
guard let defaultVariant = configuration.variants
.first(where: { $0.name.lowercased() == "default" }) else {
throw ValidationError("Variant 'default' not found.")
}

// Create 'variants_params.rb' with parameters whose
// destination are set as '.fastlane'
try storeFastlaneParams(for: defaultVariant, configuration: configuration)

setupCompleteMessage =
"""
We got almost everything done!
Your setup is complete, congratulations! 🎉
However, you still need to provide some parameters in order for fastlane to run correctly.
❌ Fastlane could not be setup. The template wasn't found or something else went wrong when
copying it.
⚠️ Check the files in 'fastlane/parameters/', change the parameters
accordingly, provide environment variables when applicable.
⚠️ Note that the values in the file 'fastlane/parameters/variants_params.rb'
where generated automatically for configuration properties with 'fastlane' destination.
"""

if StaticPath.Fastlane.baseFolder.isDirectory {
guard let defaultVariant = configuration.variants
.first(where: { $0.name.lowercased() == "default" }) else {
throw ValidationError("Variant 'default' not found.")
}

// Create 'variants_params.rb' with parameters whose
// destination are set as '.fastlane'
try storeFastlaneParams(for: defaultVariant, configuration: configuration)

setupCompleteMessage =
"""
Your setup is complete, congratulations! 🎉
However, you still need to provide some parameters in order for fastlane to run correctly.
⚠️ Check the files in 'fastlane/parameters/', change the parameters
accordingly, provide environment variables when applicable.
⚠️ Note that the values in the file 'fastlane/parameters/variants_params.rb'
where generated automatically for configuration properties with 'fastlane' destination.
"""

Logger.shared.logInfo("🚀 ", item: "Fastlane setup with success", color: .green)
Logger.shared.logInfo("👇 Next steps ", item: "", color: .yellow)
} else {
Logger.shared.logWarning("", item: "Fastlane setup couldn't be completed")
Logger.shared.logInfo("👇 What happened ", item: "", color: .yellow)
}

setupCompleteMessage += baseSetupCompletedMessage
setupCompleteMessage.enumerateLines { (line, _) in
Logger.shared.logInfo("", item: line, color: .yellow)
}

} catch let error as ValidationError {
Logger.shared.logFatal(item: error.description)

} catch let error as RuntimeError {
Logger.shared.logFatal(item: error.description)

} catch {
Logger.shared.logFatal(item: error.localizedDescription)
Logger.shared.logInfo("🚀 ", item: "Fastlane setup with success", color: .green)
Logger.shared.logInfo("👇 Next steps ", item: "", color: .yellow)
} else {
Logger.shared.logWarning("", item: "Fastlane setup couldn't be completed")
Logger.shared.logInfo("👇 What happened ", item: "", color: .yellow)
}

setupCompleteMessage += baseSetupCompletedMessage
setupCompleteMessage.enumerateLines { (line, _) in
Logger.shared.logInfo("", item: line, color: .yellow)
}

} catch let error as ValidationError {
Logger.shared.logFatal(item: error.description)

} catch let error as RuntimeError {
Logger.shared.logFatal(item: error.description)

} catch {
Logger.shared.logFatal(item: error.localizedDescription)
}
}

Expand Down
147 changes: 73 additions & 74 deletions Sources/VariantsCore/Custom Types/Project/iOSProject.swift
Original file line number Diff line number Diff line change
Expand Up @@ -142,87 +142,86 @@ class iOSProject: Project {

// swiftlint:disable:next function_body_length
private func setupFastlane(with configuration: iOSConfiguration, skip: Bool) {
if skip {
Logger.shared.logInfo("Skipped Fastlane setup", item: "")
} else {
Logger.shared.logInfo("Setting up Fastlane", item: "")

do {
let path = try TemplateDirectory().path
try Bash("cp", arguments: "-R", "\(path.absolute())/ios/_fastlane/", ".")
.run()

let projectSourceFolder = configuration.targets.first?.value.source.path ?? "{{ SOURCE_PATH }}"
let baseSetupCompletedMessage =
"""
✅ Your variants configuration was setup
✅ '\(projectSourceFolder)/Variants/' has been created.
Add that folder to your Xcode project if it wasn't done automatically.
✅ For configuration properties with 'project' destination, they have been
stored in '\(projectSourceFolder)/Variants/variants.xcconfig'.
These values have been made available to your project via your Info.plist.
Use them in your code as 'Variants.configuration["SAMPLE_PROPERTY"]'.
🔄 Use 'variants switch --variants <value>' to switch between variants and
update the properties in the files described above.
That is all.
"""

var setupCompleteMessage =
guard skip == false else {
return Logger.shared.logInfo("Skipped Fastlane setup for iOS", item: "")
}

Logger.shared.logInfo("Setting up Fastlane for iOS", item: "")
do {
let path = try TemplateDirectory().path
try Bash("cp", arguments: "-R", "\(path.absolute())/ios/_fastlane/", ".")
.run()

let projectSourceFolder = configuration.targets.first?.value.source.path ?? "{{ SOURCE_PATH }}"
let baseSetupCompletedMessage =
"""
✅ Your variants configuration was setup
✅ '\(projectSourceFolder)/Variants/' has been created.
Add that folder to your Xcode project if it wasn't done automatically.
✅ For configuration properties with 'project' destination, they have been
stored in '\(projectSourceFolder)/Variants/variants.xcconfig'.
These values have been made available to your project via your Info.plist.
Use them in your code as 'Variants.configuration["SAMPLE_PROPERTY"]'.
🔄 Use 'variants switch --variants <value>' to switch between variants and
update the properties in the files described above.
That is all.
"""

var setupCompleteMessage =
"""
We got almost everything done!
❌ Fastlane could not be setup. The template wasn't found or something else went wrong when
copying it.
"""

if StaticPath.Fastlane.baseFolder.isDirectory {

guard let defaultVariant = configuration.variants
.first(where: { $0.name.lowercased() == "default" }),
let namedTarget = configuration.targets.first
else {
throw ValidationError("Variant 'default' not found.")
}
var customProperties: [CustomProperty] = (defaultVariant.custom ?? []) + (configuration.custom ?? [])
customProperties.append(defaultVariant.destinationProperty)

// Create 'variants_params.rb' with parameters whose
// destination are set as '.fastlane'
try storeFastlaneParams(customProperties)

try parametersFactory.createMatchFile(using: defaultVariant, target: namedTarget.value)

setupCompleteMessage =
"""
We got almost everything done!
Your setup is complete, congratulations! 🎉
However, you still need to provide some parameters in order for fastlane to run correctly.
❌ Fastlane could not be setup. The template wasn't found or something else went wrong when
copying it.
⚠️ Check the files in 'fastlane/parameters/', change the parameters accordingly,
provide environment variables when applicable.
⚠️ If you use Cocoapods-art, enable it in 'fastlane/Cocoapods'
⚠️ Change your signing configuration in 'fastlane/Match' and potentially 'fastlane/Deploy'
"""

if StaticPath.Fastlane.baseFolder.isDirectory {

guard let defaultVariant = configuration.variants
.first(where: { $0.name.lowercased() == "default" }),
let namedTarget = configuration.targets.first
else {
throw ValidationError("Variant 'default' not found.")
}
var customProperties: [CustomProperty] = (defaultVariant.custom ?? []) + (configuration.custom ?? [])
customProperties.append(defaultVariant.destinationProperty)

// Create 'variants_params.rb' with parameters whose
// destination are set as '.fastlane'
try storeFastlaneParams(customProperties)

try parametersFactory.createMatchFile(using: defaultVariant, target: namedTarget.value)

setupCompleteMessage =
"""
Your setup is complete, congratulations! 🎉
However, you still need to provide some parameters in order for fastlane to run correctly.
⚠️ Check the files in 'fastlane/parameters/', change the parameters accordingly,
provide environment variables when applicable.
⚠️ If you use Cocoapods-art, enable it in 'fastlane/Cocoapods'
⚠️ Change your signing configuration in 'fastlane/Match' and potentially 'fastlane/Deploy'
"""

Logger.shared.logInfo("🚀 ", item: "Fastlane setup with success", color: .green)
Logger.shared.logInfo("👇 Next steps ", item: "", color: .yellow)
} else {
Logger.shared.logWarning("", item: "Fastlane setup couldn't be completed")
Logger.shared.logInfo("👇 What happened ", item: "", color: .yellow)
}

setupCompleteMessage += baseSetupCompletedMessage
setupCompleteMessage.enumerateLines { (line, _) in
Logger.shared.logInfo("", item: line, color: .yellow)
}

} catch {
Logger.shared.logFatal(item: error.localizedDescription)
Logger.shared.logInfo("🚀 ", item: "Fastlane setup with success", color: .green)
Logger.shared.logInfo("👇 Next steps ", item: "", color: .yellow)
} else {
Logger.shared.logWarning("", item: "Fastlane setup couldn't be completed")
Logger.shared.logInfo("👇 What happened ", item: "", color: .yellow)
}

setupCompleteMessage += baseSetupCompletedMessage
setupCompleteMessage.enumerateLines { (line, _) in
Logger.shared.logInfo("", item: line, color: .yellow)
}

} catch {
Logger.shared.logFatal(item: error.localizedDescription)
}
}

Expand Down

0 comments on commit daeb6a2

Please sign in to comment.