Skip to content

Commit 37b68d2

Browse files
authored
Add Basic Windows & Linux Support (#184)
* Seems to compile and sort of run tests * Fix a few more issues * Fix naming and unneeded import * Get CI a little further * Use platform specific snapshots * More snapshots * Try again with non-Darwin * Turns out we just need a darwin and non-darwin snapshots dir * Fix header look up for client creation * update ci configuration * Skip problematic test on Windows and Linux * Use a supported version of Swift for the linux CI * Go back to specific folders for each platform, it's just easier to deal with * Attempt to disable conversion and skip broken test * Cleaning up the PR a little * Add missing test files * Update tests * Address some PR feedback * Recomment out test * Drop down to see if using a Semaphore works across platforms * Allow threading in a local storage client * Remove defaults from designated initializer and put defaults in platform specific convenience inits * Give linux a convenience init so tests can use it * Remove default local storage * Fix mock generation * Remove old tests * Remove autocanonicalization problems by making Apikey consistent casing. * Re-record all snapshots to prevent auto-canonicalization issues across toolchains * Turn on autocrlf to see if that gets the test snapshots further * fix line endings for snapshots * fix initializer * Remove unneeded testing workaround * Update tests to use empty response where needed * Fix empty implementation to work across platforms * Fix test that breaks to only run if not Windows or Linux * use correct operator * Fix binary packaging * Use URLs and remove convenience * Fix cancellation * fix example * Fix actuallyCancel logic
1 parent 3b97d39 commit 37b68d2

File tree

56 files changed

+534
-149
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+534
-149
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/Tests/**/__Snapshots__/**/*.txt eol=lf

.github/workflows/ci.yml

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ concurrency:
1414
cancel-in-progress: true
1515

1616
jobs:
17-
library:
17+
library-darwin:
1818
runs-on: macos-13
19-
name: Test Library
19+
name: Test Library (Darwin)
2020
steps:
2121
- uses: actions/checkout@v3
2222
- name: Select Xcode 15.0.1
@@ -25,7 +25,7 @@ jobs:
2525
run: make test-library
2626

2727
library-evolution:
28-
name: Library (evolution)
28+
name: Library (evolution, Darwin)
2929
runs-on: macos-13
3030
steps:
3131
- uses: actions/checkout@v4
@@ -34,6 +34,33 @@ jobs:
3434
- name: Build for library evolution
3535
run: make build-for-library-evolution
3636

37+
library-linux:
38+
runs-on: ubuntu-latest
39+
name: Test Library (Linux)
40+
steps:
41+
- uses: swift-actions/setup-swift@v1
42+
with:
43+
swift-version: "5.9"
44+
- uses: actions/checkout@v3
45+
- name: Run Tests
46+
run: swift test
47+
48+
library-windows:
49+
runs-on: windows-latest
50+
name: Test Library (Windows)
51+
steps:
52+
# We use BCNY's repo since they have newer builds of Swift
53+
# which have fixed libcurl in Foundation.
54+
- uses: compnerd/gha-setup-swift@main
55+
with:
56+
release-tag-name: "20231203.0"
57+
github-repo: "thebrowsercompany/swift-build"
58+
release-asset-name: installer-amd64.exe
59+
github-token: ${{ secrets.GITHUB_TOKEN }}
60+
- uses: actions/checkout@v3
61+
- name: Run Tests
62+
run: swift test
63+
3764
examples:
3865
runs-on: macos-13
3966
name: Build Examples
@@ -45,4 +72,3 @@ jobs:
4572
run: cp Examples/Examples/_Secrets.swift Examples/Examples/Secrets.swift
4673
- name: Build examples
4774
run: make build-examples
48-

.vscode/settings.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"cSpell.words": [
3+
"apikey",
4+
"HTTPURL",
5+
"pkce",
6+
"postgrest",
7+
"preconcurrency",
8+
"Supabase",
9+
"whitespaces",
10+
"xctest"
11+
]
12+
}

Examples/Examples/ExamplesApp.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,6 @@ struct ExamplesApp: App {
2020

2121
let supabase = SupabaseClient(
2222
supabaseURL: Secrets.supabaseURL,
23-
supabaseKey: Secrets.supabaseAnonKey
23+
supabaseKey: Secrets.supabaseAnonKey,
24+
options: .init(auth: .init(storage: KeychainLocalStorage(service: "supabase.gotrue.swift", accessGroup: nil)))
2425
)

Examples/UserManagement/Supabase.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import Foundation
99
import Supabase
1010

1111
let supabase = SupabaseClient(
12-
supabaseURL: "https://PROJECT_ID.supabase.co",
13-
supabaseKey: "YOUR_SUPABASE_ANON_KEY"
12+
supabaseURL: URL(string: "https://PROJECT_ID.supabase.co")!,
13+
supabaseKey: "YOUR_SUPABASE_ANON_KEY",
14+
options: .init(auth: .init(storage: KeychainLocalStorage(service: "supabase.gotrue.swift", accessGroup: nil)))
1415
)

Package.resolved

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,28 @@
44
import Foundation
55
import PackageDescription
66

7+
var dependencies: [Package.Dependency] = [
8+
.package(url: "https://github.com/pointfreeco/swift-snapshot-testing", from: "1.8.1"),
9+
.package(url: "https://github.com/pointfreeco/xctest-dynamic-overlay", from: "1.0.0"),
10+
.package(url: "https://github.com/pointfreeco/swift-concurrency-extras", from: "1.0.0"),
11+
.package(url: "https://github.com/apple/swift-crypto.git", "1.0.0" ..< "3.0.0"),
12+
]
13+
14+
var goTrueDependencies: [Target.Dependency] = [
15+
"_Helpers",
16+
.product(name: "ConcurrencyExtras", package: "swift-concurrency-extras"),
17+
.product(name: "Crypto", package: "swift-crypto"),
18+
]
19+
20+
#if !os(Windows) && !os(Linux)
21+
dependencies += [
22+
.package(url: "https://github.com/kishikawakatsumi/KeychainAccess", from: "4.2.2"),
23+
]
24+
goTrueDependencies += [
25+
.product(name: "KeychainAccess", package: "KeychainAccess"),
26+
]
27+
#endif
28+
729
let package = Package(
830
name: "Supabase",
931
platforms: [
@@ -24,12 +46,7 @@ let package = Package(
2446
targets: ["Supabase", "Functions", "PostgREST", "Auth", "Realtime", "Storage"]
2547
),
2648
],
27-
dependencies: [
28-
.package(url: "https://github.com/kishikawakatsumi/KeychainAccess", from: "4.2.2"),
29-
.package(url: "https://github.com/pointfreeco/swift-snapshot-testing", from: "1.8.1"),
30-
.package(url: "https://github.com/pointfreeco/xctest-dynamic-overlay", from: "1.0.0"),
31-
.package(url: "https://github.com/pointfreeco/swift-concurrency-extras", from: "1.0.0"),
32-
],
49+
dependencies: dependencies,
3350
targets: [
3451
.target(
3552
name: "_Helpers",
@@ -47,16 +64,13 @@ let package = Package(
4764
),
4865
.target(
4966
name: "Auth",
50-
dependencies: [
51-
"_Helpers",
52-
.product(name: "ConcurrencyExtras", package: "swift-concurrency-extras"),
53-
.product(name: "KeychainAccess", package: "KeychainAccess"),
54-
]
67+
dependencies: goTrueDependencies
5568
),
5669
.testTarget(
5770
name: "AuthTests",
5871
dependencies: [
5972
"Auth",
73+
"_Helpers",
6074
.product(name: "SnapshotTesting", package: "swift-snapshot-testing"),
6175
.product(name: "XCTestDynamicOverlay", package: "xctest-dynamic-overlay"),
6276
],

Sources/Auth/AuthClient.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public actor AuthClient {
3434
url: URL,
3535
headers: [String: String] = [:],
3636
flowType: AuthFlowType = Configuration.defaultFlowType,
37-
localStorage: AuthLocalStorage = Configuration.defaultLocalStorage,
37+
localStorage: AuthLocalStorage,
3838
encoder: JSONEncoder = AuthClient.Configuration.jsonEncoder,
3939
decoder: JSONDecoder = AuthClient.Configuration.jsonDecoder,
4040
fetch: @escaping FetchHandler = { try await URLSession.shared.data(for: $0) }
@@ -101,7 +101,7 @@ public actor AuthClient {
101101
url: URL,
102102
headers: [String: String] = [:],
103103
flowType: AuthFlowType = AuthClient.Configuration.defaultFlowType,
104-
localStorage: AuthLocalStorage = AuthClient.Configuration.defaultLocalStorage,
104+
localStorage: AuthLocalStorage,
105105
encoder: JSONEncoder = AuthClient.Configuration.jsonEncoder,
106106
decoder: JSONDecoder = AuthClient.Configuration.jsonDecoder,
107107
fetch: @escaping FetchHandler = { try await URLSession.shared.data(for: $0) }

Sources/Auth/AuthLocalStorage.swift

Lines changed: 0 additions & 32 deletions
This file was deleted.

Sources/Auth/Defaults.swift

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,4 @@ extension AuthClient.Configuration {
6262

6363
/// The default ``AuthFlowType`` used when initializing a ``AuthClient`` instance.
6464
public static let defaultFlowType: AuthFlowType = .pkce
65-
66-
/// The default ``AuthLocalStorage`` instance used by the ``AuthClient``.
67-
public static let defaultLocalStorage: AuthLocalStorage = KeychainLocalStorage(
68-
service: "supabase.gotrue.swift",
69-
accessGroup: nil
70-
)
7165
}

0 commit comments

Comments
 (0)