Skip to content

Commit a7ed651

Browse files
muzixHoang Pham
andauthored
fix: fix workflow (#2)
* Fix workflow * fix workflow --------- Co-authored-by: Hoang Pham <hoangpham@swiftcode.me>
1 parent df37188 commit a7ed651

11 files changed

Lines changed: 82 additions & 105 deletions

File tree

.github/workflows/tests.yml

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,28 @@ on:
55
branches: [ main ]
66
pull_request:
77
branches: [ main ]
8+
workflow_dispatch:
89

910
jobs:
1011
test:
1112
name: Test SwiftUI Query
12-
runs-on: macos-14
13-
13+
runs-on: macos-15
14+
1415
steps:
1516
- name: Checkout
1617
uses: actions/checkout@v4
17-
18-
- name: Setup Swift
19-
uses: swift-actions/setup-swift@v2
20-
with:
21-
swift-version: "6.2"
22-
18+
2319
- name: Show Swift version
2420
run: swift --version
25-
26-
- name: Run Tests
27-
run: swift test --parallel
28-
21+
22+
- name: Install SwiftLint
23+
run: brew install swiftlint
24+
25+
- name: Lint Code
26+
run: make lint
27+
2928
- name: Run Tests with Coverage
30-
run: swift test --enable-code-coverage
29+
run: swift test --parallel --enable-code-coverage
3130

3231
- name: Generate Coverage Report
3332
run: |
@@ -43,17 +42,4 @@ jobs:
4342
with:
4443
file: ./coverage.lcov
4544
fail_ci_if_error: false
46-
continue-on-error: true
47-
48-
lint:
49-
name: Swift Format
50-
runs-on: ubuntu-latest
51-
52-
steps:
53-
- name: Checkout
54-
uses: actions/checkout@v4
55-
56-
- name: Swift Format Lint
57-
uses: norio-nomura/action-swiftlint@3.2.1
58-
with:
59-
args: --strict
45+
continue-on-error: true

.swiftlint.yml

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
included:
55
- Sources
66
- Tests
7-
- Example
87

98
excluded:
109
- Documentation
10+
- Example
1111
- .build
1212
- .swiftpm
1313
- Package.swift
@@ -23,7 +23,8 @@ disabled_rules:
2323
- function_parameter_count # Allow functions with more than 6 parameters
2424
- redundant_string_enum_value # Allow explicit raw values for consistency
2525
- raw_value_for_camel_cased_codable_enum # Disable conflicting camel case enum rule
26-
26+
- closure_parameter_position
27+
- optional_data_string_conversion
2728
# Per-path rule customization
2829

2930
opt_in_rules:
@@ -92,6 +93,7 @@ opt_in_rules:
9293
- vertical_whitespace_opening_braces
9394
- weak_delegate
9495
- yoda_condition
96+
- non_optional_string_data_conversion
9597

9698
# Rule configuration
9799
analyzer_rules:
@@ -184,11 +186,6 @@ custom_rules:
184186
severity: warning
185187

186188

187-
observable_usage:
188-
name: "Observable Usage"
189-
regex: 'ObservableObject'
190-
message: "Consider using @Observable instead of ObservableObject for Swift 6"
191-
severity: warning
192189

193190
# Reporter type (xcode, json, csv, checkstyle, junit, html, emoji)
194191
reporter: "xcode"

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ install: ## Install dependencies (SwiftLint and SwiftFormat)
88

99
.PHONY: lint
1010
lint: ## Run SwiftLint
11-
swiftlint
11+
swiftlint --strict
1212

1313
.PHONY: lint-fix
1414
lint-fix: ## Run SwiftLint with auto-fix
@@ -40,7 +40,7 @@ fix: ## Fix all issues (lint auto-fix + format)
4040

4141
.PHONY: build
4242
build: ## Build the package
43-
swift build -Xswiftc -strict-concurrency=complete
43+
swift build
4444

4545
.PHONY: test
4646
test: ## Run tests

Package.swift

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,12 @@ let package = Package(
2424
name: "SwiftUIQuery",
2525
dependencies: [
2626
.product(name: "Perception", package: "swift-perception")
27-
],
28-
swiftSettings: [
29-
.enableUpcomingFeature("StrictConcurrency")
3027
]
3128
),
3229
.testTarget(
3330
name: "SwiftUIQueryTests",
3431
dependencies: [
3532
"SwiftUIQuery",
36-
],
37-
swiftSettings: [
38-
.enableUpcomingFeature("StrictConcurrency")
3933
]
4034
),
4135
]

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# SwiftUI Query
22

3-
[![Tests](https://github.com/muzix/swiftui-query/actions/workflows/tests.yml/badge.svg)](https://github.com/muzix/swiftui-query/actions/workflows/tests.yml)
3+
[![Tests](https://github.com/muzix/SwiftUIQuery/actions/workflows/tests.yml/badge.svg)](https://github.com/muzix/SwiftUIQuery/actions/workflows/tests.yml)
44
[![Swift 6.0](https://img.shields.io/badge/Swift-6.0-orange.svg)](https://swift.org)
55
[![Platforms](https://img.shields.io/badge/Platforms-iOS%20|%20macOS%20|%20tvOS%20|%20watchOS-blue.svg)](https://swift.org)
66
[![License](https://img.shields.io/badge/License-MIT-green.svg)](LICENSE)

Sources/SwiftUIQuery/Core/GarbageCollector.swift

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,7 @@ public final class GarbageCollector {
4949

5050
isRunning = true
5151

52-
#if DEBUG
53-
print("🗑️ SwiftUI Query: Starting GarbageCollector with \(interval)s interval")
54-
#endif
52+
QueryLogger.shared.logGCStart(interval: interval)
5553

5654
timer = Timer.scheduledTimer(withTimeInterval: interval, repeats: true) { [weak self] _ in
5755
Task { @MainActor [weak self] in
@@ -68,9 +66,7 @@ public final class GarbageCollector {
6866
timer?.invalidate()
6967
timer = nil
7068

71-
#if DEBUG
72-
print("🗑️ SwiftUI Query: Stopping GarbageCollector")
73-
#endif
69+
QueryLogger.shared.logGCStop()
7470
}
7571

7672
/// Register a query cache for garbage collection monitoring
@@ -132,22 +128,16 @@ public final class GarbageCollector {
132128
for query in inactiveQueries {
133129
cache.remove(query)
134130
removedQueries += 1
135-
136-
#if DEBUG
137-
print("🗑️ SwiftUI Query: GC removed inactive query \(query.queryHash)")
138-
#endif
131+
QueryLogger.shared.logGCRemoving(hash: query.queryHash, reason: "inactive query")
139132
}
140133
}
141134

142135
let duration = Date().timeIntervalSince(startTime)
143136

144-
#if DEBUG
145-
if removedQueries > 0 {
146-
print(
147-
"🗑️ SwiftUI Query: GC completed - removed \(removedQueries)/\(totalQueries) queries in \(String(format: "%.2f", duration * 1000))ms"
148-
)
149-
}
150-
#endif
137+
if removedQueries > 0 {
138+
let reason = "removed \(removedQueries)/\(totalQueries) queries in \(String(format: "%.2f", duration * 1000))ms"
139+
QueryLogger.shared.logGCRemoving(hash: "GC-Complete", reason: reason)
140+
}
151141
}
152142

153143
/// Check if a query is eligible for garbage collection

Sources/SwiftUIQuery/InfiniteQuery.swift

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -867,15 +867,11 @@ public final class InfiniteQuery<
867867
public func optionalRemove() {
868868
// Only remove if query has no observers and is eligible for GC
869869
guard observers.isEmpty, state.fetchStatus == .idle, isEligibleForGC else {
870-
#if DEBUG
871-
print("🗑️ SwiftUI Query: GC cancelled for \(queryHash) - Query is active or not eligible")
872-
#endif
870+
QueryLogger.shared.logGCCancelled(hash: queryHash)
873871
return
874872
}
875873

876-
#if DEBUG
877-
print("🗑️ SwiftUI Query: Executing GC for \(queryHash)")
878-
#endif
874+
QueryLogger.shared.logGCExecuting(hash: queryHash)
879875

880876
// Remove from cache (let cache handle the cleanup)
881877
cache?.remove(self)

Sources/SwiftUIQuery/Query.swift

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -709,15 +709,11 @@ public final class Query<TData: Sendable, TKey: QueryKey>: AnyQuery {
709709
public func optionalRemove() {
710710
// Only remove if query has no observers and is eligible for GC
711711
guard observers.isEmpty, state.fetchStatus == .idle, isEligibleForGC else {
712-
#if DEBUG
713-
print("🗑️ SwiftUI Query: GC cancelled for \(queryHash) - Query is active or not eligible")
714-
#endif
712+
QueryLogger.shared.logGCCancelled(hash: queryHash)
715713
return
716714
}
717715

718-
#if DEBUG
719-
print("🗑️ SwiftUI Query: Executing GC for \(queryHash)")
720-
#endif
716+
QueryLogger.shared.logGCExecuting(hash: queryHash)
721717

722718
// Remove from cache (let cache handle the cleanup)
723719
cache?.remove(self)

Sources/SwiftUIQuery/QueryLogger.swift

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ public final class QueryLogger {
2828
/// Enable/disable QueryObserver cache interaction logging
2929
public var logQueryObserver = true
3030

31+
/// Enable/disable GarbageCollector logging
32+
public var logGarbageCollector = true
33+
3134
private init() {}
3235

3336
// MARK: - Logging Methods
@@ -115,6 +118,38 @@ public final class QueryLogger {
115118
guard isEnabled, logQueryObserver else { return }
116119
print("📊 QueryObserver reading query state for hash: \(hash)")
117120
}
121+
122+
// MARK: - Garbage Collector Logging
123+
124+
/// Log GarbageCollector starting
125+
func logGCStart(interval: TimeInterval) {
126+
guard isEnabled, logGarbageCollector else { return }
127+
print("🗑️ SwiftUI Query: Starting GarbageCollector with \(interval)s interval")
128+
}
129+
130+
/// Log GarbageCollector stopping
131+
func logGCStop() {
132+
guard isEnabled, logGarbageCollector else { return }
133+
print("🗑️ SwiftUI Query: Stopping GarbageCollector")
134+
}
135+
136+
/// Log GC cancelled for active query
137+
func logGCCancelled(hash: String) {
138+
guard isEnabled, logGarbageCollector else { return }
139+
print("🗑️ SwiftUI Query: GC cancelled for \(hash) - Query is active or not eligible")
140+
}
141+
142+
/// Log GC executing for query
143+
func logGCExecuting(hash: String) {
144+
guard isEnabled, logGarbageCollector else { return }
145+
print("🗑️ SwiftUI Query: Executing GC for \(hash)")
146+
}
147+
148+
/// Log GC removing query
149+
func logGCRemoving(hash: String, reason: String) {
150+
guard isEnabled, logGarbageCollector else { return }
151+
print("🗑️ SwiftUI Query: GC removing \(hash) - \(reason)")
152+
}
118153
}
119154

120155
// MARK: - Public API Extensions
@@ -126,6 +161,7 @@ extension QueryLogger {
126161
logQueryClient = true
127162
logQuery = true
128163
logQueryObserver = true
164+
logGarbageCollector = true
129165
}
130166

131167
/// Disable all cache logging (convenience method)
@@ -157,3 +193,5 @@ extension QueryLogger {
157193
logQueryObserver = true
158194
}
159195
}
196+
197+
// swiftlint:enable no_print_statements

0 commit comments

Comments
 (0)