Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

๐Ÿš€ Add ability to set shared folder root path #272

Merged
merged 4 commits into from
Nov 20, 2023
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
73 changes: 68 additions & 5 deletions Docs/commands-help/env.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,74 @@

## Discussion

Rugby supports these environment variables:
This command prints the Rugby environment. For example:
```yml
Rugby version: 2.3.0
Swift: 5.9
CLT: Xcode 15.0.1 (Build version 15A507)
CPU: Apple M1 (arm64)
Project: Example
Git branch: main
RUGBY_KEEP_HASH_YAMLS: NO
RUGBY_PRINT_MISSING_BINARIES: NO
RUGBY_SHARED_DIR_ROOT: /Users/swiftyfinch
```

You can find the same environment output in the head of each Rugby log file.

<br>

### Keep hash YML files

A flag to keep yaml files with target hash in the binaries folder.
```objc
# A flag to keep yaml files with target hash in the binaries folder.
RUGBY_KEEP_HASH_YAMLS = NO
RUGBY_KEEP_HASH_YAMLS=YES rugby
```
```sh
.rugby
โ””โ”€ bin
โ””โ”€ Debug-iphonesimulator-arm64
โ””โ”€ 85d4367
โ”œโ”€ 85d4367.yml # Hash yml file
โ””โ”€ Alamofire.framework
```

### Print missing binaries as a tree

# A flag to print missing binaries as a tree during an analysing process.
RUGBY_PRINT_MISSING_BINARIES = NO
A flag to print missing binaries as a tree during an analysing process.
```objc
RUGBY_PRINT_MISSING_BINARIES=YES rugby
```
```
. Missing Binaries (3)
โ”ฃโ” Kingfisher-framework (1a1f878)
โ”—โ” Moya-framework (a4a42b2)
โ”—โ” Alamofire-framework (85d4367)
```

### Set a custom path to shared folder root

A path to the root of shared folder (without `.rugby` folder name).
By default:
```objc
RUGBY_SHARED_DIR_ROOT=$HOME rugby
```
```sh
~
โ””โ”€ .rugby # shared folder
โ”œโ”€ bin
โ””โ”€ logs
```

You can set a different one. For example, a current directory:
```objc
RUGBY_SHARED_DIR_ROOT=`pwd` rugby
```
```sh
pwd
โ””โ”€ .rugby # shared folder combined with local one
โ”œโ”€ backup
โ”œโ”€ bin
โ”œโ”€ build
โ””โ”€ logs
```
2 changes: 1 addition & 1 deletion Sources/Rugby/Commands/Utils/Env.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ struct Env: AsyncParsableCommand {
func run() async throws {
try await dependencies.environmentCollector.env(
rugbyVersion: Rugby.configuration.version,
rugbyEnvironment: dependencies.featureToggles.all
rugbyEnvironment: dependencies.env.all
).forEach { print($0) }
}
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
import Fish
import Foundation
import RugbyFoundation

final class FeatureToggles {
final class Environment {
// swiftlint:disable identifier_name
private let RUGBY_KEEP_HASH_YAMLS = "RUGBY_KEEP_HASH_YAMLS"
private let RUGBY_PRINT_MISSING_BINARIES = "RUGBY_PRINT_MISSING_BINARIES"
private let RUGBY_SHARED_DIR_ROOT = "RUGBY_SHARED_DIR_ROOT"
// swiftlint:enable identifier_name
}

extension FeatureToggles: IFeatureToggles {
extension Environment: IEnvironment {
var all: [String: String] {
[
RUGBY_KEEP_HASH_YAMLS: keepHashYamls.yesNo,
RUGBY_PRINT_MISSING_BINARIES: printMissingBinaries.yesNo
RUGBY_PRINT_MISSING_BINARIES: printMissingBinaries.yesNo,
RUGBY_SHARED_DIR_ROOT: sharedFolderParentPath

Check warning on line 18 in Sources/Rugby/Core/Dependencies/Environment/Environment.swift

View check run for this annotation

Codecov / codecov/patch

Sources/Rugby/Core/Dependencies/Environment/Environment.swift#L17-L18

Added lines #L17 - L18 were not covered by tests
]
}

Expand All @@ -23,6 +26,10 @@
var printMissingBinaries: Bool {
ProcessInfo.processInfo.environment[RUGBY_PRINT_MISSING_BINARIES].isEnabled
}

var sharedFolderParentPath: String {
ProcessInfo.processInfo.environment[RUGBY_SHARED_DIR_ROOT] ?? Folder.home.path
}

Check warning on line 32 in Sources/Rugby/Core/Dependencies/Environment/Environment.swift

View check run for this annotation

Codecov / codecov/patch

Sources/Rugby/Core/Dependencies/Environment/Environment.swift#L30-L32

Added lines #L30 - L32 were not covered by tests
}

private extension String? {
Expand Down
2 changes: 1 addition & 1 deletion Sources/Rugby/Core/RunnableCommand/RunnableCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
try await dependencies.environmentCollector.write(
rugbyVersion: Rugby.configuration.version,
command: self,
rugbyEnvironment: dependencies.featureToggles.all
rugbyEnvironment: dependencies.env.all

Check warning on line 32 in Sources/Rugby/Core/RunnableCommand/RunnableCommand.swift

View check run for this annotation

Codecov / codecov/patch

Sources/Rugby/Core/RunnableCommand/RunnableCommand.swift#L32

Added line #L32 was not covered by tests
)

let name = Self.configuration.commandName?.capitalized ?? "Unknown"
Expand Down
7 changes: 4 additions & 3 deletions Sources/Rugby/Rugby.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,13 @@
// MARK: - Private

private static func prepareDependencies() {
Vault.setupShared(
featureToggles: FeatureToggles(),
let env = Environment()
return Vault.setupShared(
env: env,

Check warning on line 75 in Sources/Rugby/Rugby.swift

View check run for this annotation

Codecov / codecov/patch

Sources/Rugby/Rugby.swift#L73-L75

Added lines #L73 - L75 were not covered by tests
logger: Logger(clock: Clock()),
router: Router(
workingDirectory: Folder.current,
sharedFolderPath: Folder.home.path
sharedFolderPath: env.sharedFolderParentPath

Check warning on line 79 in Sources/Rugby/Rugby.swift

View check run for this annotation

Codecov / codecov/patch

Sources/Rugby/Rugby.swift#L79

Added line #L79 was not covered by tests
)
)
}
Expand Down
8 changes: 4 additions & 4 deletions Sources/RugbyFoundation/Core/Build/BuildManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
private let useBinariesManager: IUseBinariesManager
private let binariesCleaner: BinariesCleaner
private let environmentCollector: IEnvironmentCollector
private let featureToggles: IFeatureToggles
private let env: IEnvironment
private let targetTreePainter: ITargetTreePainter

init(logger: ILogger,
Expand All @@ -59,7 +59,7 @@
useBinariesManager: IUseBinariesManager,
binariesCleaner: BinariesCleaner,
environmentCollector: IEnvironmentCollector,
featureToggles: IFeatureToggles,
env: IEnvironment,
targetTreePainter: ITargetTreePainter) {
self.logger = logger
self.buildTargetsManager = buildTargetsManager
Expand All @@ -74,7 +74,7 @@
self.useBinariesManager = useBinariesManager
self.binariesCleaner = binariesCleaner
self.environmentCollector = environmentCollector
self.featureToggles = featureToggles
self.env = env

Check warning on line 77 in Sources/RugbyFoundation/Core/Build/BuildManager.swift

View check run for this annotation

Codecov / codecov/patch

Sources/RugbyFoundation/Core/Build/BuildManager.swift#L77

Added line #L77 was not covered by tests
self.targetTreePainter = targetTreePainter
}

Expand All @@ -99,7 +99,7 @@
return nil
}

if featureToggles.printMissingBinaries {
if env.printMissingBinaries {

Check warning on line 102 in Sources/RugbyFoundation/Core/Build/BuildManager.swift

View check run for this annotation

Codecov / codecov/patch

Sources/RugbyFoundation/Core/Build/BuildManager.swift#L102

Added line #L102 was not covered by tests
let tree = targetTreePainter.paint(targets: buildTargets)
await logPlain(
"\(".".yellow) \("Missing Binaries (\(buildTargets.count))".green)\n\(tree)"
Expand Down
14 changes: 14 additions & 0 deletions Sources/RugbyFoundation/Core/Common/IEnvironment.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/// The protocol describing a service providing the environment variables.
public protocol IEnvironment: AnyObject {
/// The variable names and their values.
var all: [String: String] { get }

/// A flag to keep yaml files with target hash in the binaries folder.
var keepHashYamls: Bool { get }

/// A flag to print missing binaries as a tree during an analysing process.
var printMissingBinaries: Bool { get }

/// A path to the root of shared folder (without `.rugby` folder name).
var sharedFolderParentPath: String { get }
}
11 changes: 0 additions & 11 deletions Sources/RugbyFoundation/Core/Common/IFeatureToggles.swift

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ extension Vault {
useBinariesManager: useBinariesManager,
binariesCleaner: binariesCleaner,
environmentCollector: environmentCollector,
featureToggles: featureToggles,
env: env,
targetTreePainter: TargetTreePainter())
}
}
14 changes: 7 additions & 7 deletions Sources/RugbyFoundation/Vault/Vault.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ public final class Vault {
/// - logger: The service collecting information about Rugby execution.
/// - router: The service providing all paths for Rugby infrastructure.
public static func setupShared(
featureToggles: IFeatureToggles,
env: IEnvironment,
logger: ILogger,
router: IRouter
) {
shared = Vault(featureToggles: featureToggles, logger: logger, router: router)
shared = Vault(env: env, logger: logger, router: router)
}

// MARK: - Init

/// The service providing feature toggles.
public let featureToggles: IFeatureToggles
/// The service providing environment variables.
public let env: IEnvironment
/// The general Rugby settings.
public let settings = Settings()
/// The service collecting information about Rugby execution.
Expand All @@ -30,11 +30,11 @@ public final class Vault {
public let router: IRouter

private init(
featureToggles: IFeatureToggles,
env: IEnvironment,
logger: ILogger,
router: IRouter
) {
self.featureToggles = featureToggles
self.env = env
self.logger = logger
self.router = router
}
Expand Down Expand Up @@ -95,7 +95,7 @@ public final class Vault {
private(set) lazy var binariesManager = BinariesStorage(
logger: logger,
sharedPath: router.binFolderPath,
keepHashYamls: featureToggles.keepHashYamls
keepHashYamls: env.keepHashYamls
)
func targetsHasher() -> TargetsHasher {
let foundationHasher = SHA1Hasher()
Expand Down