Last active
December 23, 2023 14:26
-
-
Save Sorix/21e61347f478ae2e83ef4d8a92d933af to your computer and use it in GitHub Desktop.
Example of Package.swift with environment variables support
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// swift-tools-version:4.0 | |
import PackageDescription | |
#if os(Linux) | |
import Glibc | |
#else | |
import Darwin.C | |
#endif | |
enum Enviroment: String { | |
static let `default`: Enviroment = .development | |
case development, production | |
static func get() -> Enviroment { | |
if let envPointer = getenv("ENV_TYPE") { | |
let env = String(cString: envPointer) | |
return Enviroment(rawValue: env) ?? .default | |
} else { | |
return .default | |
} | |
} | |
} | |
var dependencies: [Package.Dependency] = [ | |
.package(url: "https://github.com/vapor/vapor.git", from: "3.1.0"), | |
.package(url: "https://github.com/Sorix/whirr-feedback-api-model", .branch("develop")) | |
] | |
var appTargetDependencies: [Target.Dependency] = ["Vapor", "FluentSQLite", "APIModel", "GooglePlaces"] | |
switch Enviroment.get() { | |
case .production: | |
dependencies.append(.package(url: "https://github.com/vapor/fluent-postgresql.git", from: "1.0.0")) | |
appTargetDependencies.append("FluentPostgreSQL") | |
case .development: | |
dependencies.append(.package(url: "https://github.com/vapor/fluent-sqlite.git", from: "3.0.0")) | |
appTargetDependencies.append("FluentSQLite") | |
} | |
let package = Package( | |
name: "backend", | |
dependencies: dependencies, | |
targets: [ | |
.target(name: "GooglePlaces", dependencies: ["Vapor"]), | |
.target(name: "App", dependencies: appTargetDependencies), | |
.target(name: "Run", dependencies: ["App"]), | |
.testTarget(name: "AppTests", dependencies: ["App"]) | |
] | |
) |
@Fab1n we can either set it in repo secrets,
If we are running local then its under xcode -> scheme -> env variables.
Xcode scheme env variables didn’t work for me
You can pass env variables directly to xcodebuild or if using fastlane you can set env vars in Fastfile. Wasn’t able to use xcode scheme env vars. Maybe someone can check again.
Xcode scheme env variables are for app run, not for build time, that's why this doesn't work.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@Fab1n we can either set it in repo secrets,
If we are running local then its under xcode -> scheme -> env variables.