Skip to content

Commit 3800ee6

Browse files
Merge pull request #3481 from SwiftPackageIndex/issue-3469-dependency-transition
Issue 3469 dependency transition
2 parents 375ca12 + 408228b commit 3800ee6

File tree

6 files changed

+388
-316
lines changed

6 files changed

+388
-316
lines changed

Sources/App/Commands/TriggerBuilds.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
import Dependencies
1516
import Fluent
1617
import PostgresKit
1718
import SQLKit
@@ -175,7 +176,8 @@ func triggerBuilds(on database: Database,
175176
client: Client,
176177
packages: [Package.Id],
177178
force: Bool = false) async throws {
178-
guard Current.allowBuildTriggers() else {
179+
@Dependency(\.environment) var environment
180+
guard environment.allowBuildTriggers() else {
179181
Current.logger().info("Build trigger override switch OFF - no builds are being triggered")
180182
return
181183
}

Sources/App/Core/AppEnvironment.swift

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import FoundationNetworking
2323

2424

2525
struct AppEnvironment: Sendable {
26-
var allowBuildTriggers: @Sendable () -> Bool
2726
var allowTwitterPosts: @Sendable () -> Bool
2827
var apiSigningKey: @Sendable () -> String?
2928
var appVersion: @Sendable () -> String?
@@ -111,11 +110,6 @@ extension AppEnvironment {
111110
nonisolated(unsafe) static var logger: Logger!
112111

113112
static let live = AppEnvironment(
114-
allowBuildTriggers: {
115-
Environment.get("ALLOW_BUILD_TRIGGERS")
116-
.flatMap(\.asBool)
117-
?? Constants.defaultAllowBuildTriggering
118-
},
119113
allowTwitterPosts: {
120114
Environment.get("ALLOW_TWITTER_POSTS")
121115
.flatMap(\.asBool)
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Copyright Dave Verwer, Sven A. Schmidt, and other contributors.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
import Dependencies
16+
import DependenciesMacros
17+
import Vapor
18+
19+
20+
@DependencyClient
21+
struct EnvironmentClient {
22+
// See https://swiftpackageindex.com/pointfreeco/swift-dependencies/main/documentation/dependenciesmacros/dependencyclient()#Restrictions
23+
// regarding the use of XCTFail here.
24+
var allowBuildTriggers: @Sendable () -> Bool = { XCTFail(#function); return true }
25+
}
26+
27+
28+
extension EnvironmentClient: DependencyKey {
29+
static var liveValue: EnvironmentClient {
30+
.init(
31+
allowBuildTriggers: {
32+
Environment.get("ALLOW_BUILD_TRIGGERS").flatMap(\.asBool) ?? Constants.defaultAllowBuildTriggering
33+
}
34+
)
35+
}
36+
}
37+
38+
39+
extension EnvironmentClient: TestDependencyKey {
40+
static var testValue: Self { Self() }
41+
}
42+
43+
44+
extension DependencyValues {
45+
var environment: EnvironmentClient {
46+
get { self[EnvironmentClient.self] }
47+
set { self[EnvironmentClient.self] = newValue }
48+
}
49+
}

0 commit comments

Comments
 (0)