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
4 changes: 3 additions & 1 deletion Sources/App/Commands/TriggerBuilds.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import Dependencies
import Fluent
import PostgresKit
import SQLKit
Expand Down Expand Up @@ -175,7 +176,8 @@ func triggerBuilds(on database: Database,
client: Client,
packages: [Package.Id],
force: Bool = false) async throws {
guard Current.allowBuildTriggers() else {
@Dependency(\.environment) var environment
guard environment.allowBuildTriggers() else {
Current.logger().info("Build trigger override switch OFF - no builds are being triggered")
return
}
Expand Down
6 changes: 0 additions & 6 deletions Sources/App/Core/AppEnvironment.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import FoundationNetworking


struct AppEnvironment: Sendable {
var allowBuildTriggers: @Sendable () -> Bool
var allowTwitterPosts: @Sendable () -> Bool
var apiSigningKey: @Sendable () -> String?
var appVersion: @Sendable () -> String?
Expand Down Expand Up @@ -111,11 +110,6 @@ extension AppEnvironment {
nonisolated(unsafe) static var logger: Logger!

static let live = AppEnvironment(
allowBuildTriggers: {
Environment.get("ALLOW_BUILD_TRIGGERS")
.flatMap(\.asBool)
?? Constants.defaultAllowBuildTriggering
},
allowTwitterPosts: {
Environment.get("ALLOW_TWITTER_POSTS")
.flatMap(\.asBool)
Expand Down
49 changes: 49 additions & 0 deletions Sources/App/Core/Dependencies/EnvironmentClient.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Copyright Dave Verwer, Sven A. Schmidt, and other contributors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import Dependencies
import DependenciesMacros
import Vapor


@DependencyClient
struct EnvironmentClient {
// See https://swiftpackageindex.com/pointfreeco/swift-dependencies/main/documentation/dependenciesmacros/dependencyclient()#Restrictions
// regarding the use of XCTFail here.
var allowBuildTriggers: @Sendable () -> Bool = { XCTFail(#function); return true }
}


extension EnvironmentClient: DependencyKey {
static var liveValue: EnvironmentClient {
.init(
allowBuildTriggers: {
Environment.get("ALLOW_BUILD_TRIGGERS").flatMap(\.asBool) ?? Constants.defaultAllowBuildTriggering
}
)
}
}


extension EnvironmentClient: TestDependencyKey {
static var testValue: Self { Self() }
}


extension DependencyValues {
var environment: EnvironmentClient {
get { self[EnvironmentClient.self] }
set { self[EnvironmentClient.self] = newValue }
}
}
Loading
Loading