Skip to content

Commit a3f81b1

Browse files
authored
Add ubuntu and windows CI actions (#8)
* Add ubuntu and windows CI actions * Update file spacing * Update windows.yml and fix multiple platform cache * Use correct boolean operator * Limit PersitableCache to apple platforms * Limit ExampleTests * Limit PersistableCacheTest * Update code for Windows support * Make Windows PropertyWrapper unique inits * Limit some tests in ExpiringCacheTest from windows
1 parent 936865e commit a3f81b1

File tree

14 files changed

+123
-10
lines changed

14 files changed

+123
-10
lines changed

.github/workflows/CI.yml renamed to .github/workflows/macOS.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: CI
1+
name: macOS
22

33
on:
44
push:
@@ -8,7 +8,7 @@ on:
88

99
jobs:
1010
build:
11-
runs-on: macos-12
11+
runs-on: macos-latest
1212

1313
steps:
1414
- uses: actions/checkout@v3

.github/workflows/ubuntu.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: Ubuntu
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
pull_request:
7+
branches: [ "main" ]
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- uses: actions/checkout@v3
15+
- name: Build
16+
run: swift build -v
17+
- name: Run tests
18+
run: swift test -v

.github/workflows/windows.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: Windows
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
pull_request:
7+
branches: [ "main" ]
8+
9+
jobs:
10+
build:
11+
runs-on: windows-latest
12+
steps:
13+
- uses: compnerd/gha-setup-swift@main
14+
with:
15+
branch: swift-5.6-release
16+
tag: 5.6-RELEASE
17+
18+
- uses: actions/checkout@v2
19+
- run: swift build
20+
- run: swift test

Sources/Cache/Cache/Cache+subscript.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ extension Cache {
1212
get(key, as: Value.self)
1313
}
1414
set(newValue) {
15-
guard let newValue else {
15+
guard let newValue = newValue else {
1616
return remove(key)
1717
}
1818

Sources/Cache/Cache/Cache.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,17 @@ import Foundation
1313
let age = cache.get("age") // age is now 100
1414
```
1515
*/
16-
open class Cache<Key: Hashable, Value>: Cacheable, ObservableObject {
16+
open class Cache<Key: Hashable, Value>: Cacheable {
1717

1818
/// Lock to synchronize the access to the cache dictionary.
1919
fileprivate var lock: NSLock
2020

21+
#if os(Linux) || os(Windows)
22+
fileprivate var cache: [Key: Value] = [:]
23+
#else
2124
/// The actual cache dictionary of key-value pairs.
2225
@Published fileprivate var cache: [Key: Value] = [:]
26+
#endif
2327

2428
/**
2529
Initializes a new `Cache` instance with an optional dictionary of initial key-value pairs.
@@ -154,3 +158,7 @@ open class Cache<Key: Hashable, Value>: Cacheable, ObservableObject {
154158
return cache.values(ofType: Output.self)
155159
}
156160
}
161+
162+
#if !os(Linux) && !os(Windows)
163+
extension Cache: ObservableObject { }
164+
#endif

Sources/Cache/Cache/ExpiringCache+subscript.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ extension ExpiringCache {
1212
get(key, as: Value.self)
1313
}
1414
set(newValue) {
15-
guard let newValue else {
15+
guard let newValue = newValue else {
1616
return remove(key)
1717
}
1818

Sources/Cache/Cache/PersistableCache.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#if !os(Linux) && !os(Windows)
12
import Foundation
23

34
/**
@@ -142,3 +143,4 @@ private extension URL {
142143
return appending(path: name)
143144
}
144145
}
146+
#endif

Sources/Cache/JSON/JSON+subscript.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ extension JSON {
1212
get(key, as: Any.self)
1313
}
1414
set(newValue) {
15-
guard let newValue else {
15+
guard let newValue = newValue else {
1616
return remove(key)
1717
}
1818

Sources/Cache/PropertyWrappers/Cached.swift

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242
}
4343
}
4444

45+
46+
#if !os(Windows)
4547
/**
4648
Initializes a new instance of the `Cached` property wrapper.
4749

@@ -59,4 +61,23 @@
5961
self.cache = cache
6062
self.defaultValue = defaultValue
6163
}
64+
#else
65+
/**
66+
Initializes a new instance of the `Cached` property wrapper.
67+
68+
- Parameters:
69+
- key: The key associated with the value in the cache.
70+
- cache: The cache instance to retrieve the value from.
71+
- defaultValue: The default value to be used if the value is not present in the cache.
72+
*/
73+
public init(
74+
key: Key,
75+
using cache: Cache<Key, Any>,
76+
defaultValue: Value
77+
) {
78+
self.key = key
79+
self.cache = cache
80+
self.defaultValue = defaultValue
81+
}
82+
#endif
6283
}

Sources/Cache/PropertyWrappers/OptionallyCached.swift

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,18 @@
3838
cache.get(key, as: Value.self)
3939
}
4040
set {
41-
guard let newValue else {
41+
guard let newValue = newValue else {
4242
return cache.remove(key)
4343
}
4444

4545
cache.set(value: newValue, forKey: key)
4646
}
4747
}
4848

49+
#if !os(Windows)
4950
/**
5051
Initializes a new instance of the `OptionallyCached` property wrapper.
51-
52+
5253
- Parameters:
5354
- key: The key associated with the value in the cache.
5455
- cache: The cache instance to retrieve the value from. The default is `Global.cache`.
@@ -60,4 +61,20 @@
6061
self.key = key
6162
self.cache = cache
6263
}
64+
#else
65+
/**
66+
Initializes a new instance of the `OptionallyCached` property wrapper.
67+
68+
- Parameters:
69+
- key: The key associated with the value in the cache.
70+
- cache: The cache instance to retrieve the value from.
71+
*/
72+
public init(
73+
key: Key,
74+
using cache: Cache<Key, Any>
75+
) {
76+
self.key = key
77+
self.cache = cache
78+
}
79+
#endif
6380
}

0 commit comments

Comments
 (0)