From 01de974d0d1a27817c4967ce01e927e500e975f3 Mon Sep 17 00:00:00 2001 From: Firdavs Khaydarov Date: Wed, 20 Nov 2024 09:57:28 +0200 Subject: [PATCH 1/6] Updated swift-tools-version to support swift 5.10 and 6.0 --- Package.swift | 3 ++- Package@swift-5.9.swift => Package@swift-6.0.swift | 5 ++--- 2 files changed, 4 insertions(+), 4 deletions(-) rename Package@swift-5.9.swift => Package@swift-6.0.swift (76%) diff --git a/Package.swift b/Package.swift index d348a6e..9d9d6be 100644 --- a/Package.swift +++ b/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version: 5.7 +// swift-tools-version: 5.10 import PackageDescription @@ -9,6 +9,7 @@ let package = Package( .iOS(.v13), .tvOS(.v13), .watchOS(.v6), + .visionOS(.v1) ], products: [ .library( diff --git a/Package@swift-5.9.swift b/Package@swift-6.0.swift similarity index 76% rename from Package@swift-5.9.swift rename to Package@swift-6.0.swift index 53b4a19..66f1cc8 100644 --- a/Package@swift-5.9.swift +++ b/Package@swift-6.0.swift @@ -1,4 +1,4 @@ -// swift-tools-version: 5.9 +// swift-tools-version: 6.0 import PackageDescription @@ -18,8 +18,7 @@ let package = Package( ], targets: [ .target( - name: "EventSource", - swiftSettings: [.enableExperimentalFeature("StrictConcurrency")]), + name: "EventSource"), .testTarget( name: "EventSourceTests", dependencies: ["EventSource"]), From a377ad314ffd970014f99712b4637a1072f7f2e8 Mon Sep 17 00:00:00 2001 From: Firdavs Khaydarov Date: Wed, 20 Nov 2024 10:23:26 +0200 Subject: [PATCH 2/6] Github actions workflows refactoring --- .github/workflows/ci.yml | 40 +++++++++++++++++++++++++++++++++++++ .github/workflows/linux.yml | 20 ------------------- .github/workflows/macos.yml | 19 ------------------ 3 files changed, 40 insertions(+), 39 deletions(-) create mode 100644 .github/workflows/ci.yml delete mode 100644 .github/workflows/linux.yml delete mode 100644 .github/workflows/macos.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..1151fa1 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,40 @@ +name: EventSource CI + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +jobs: + macos-14: + name: Build macOS 14 (Swift 5.10) + runs-on: macos-14 + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Build + run: swift build -v + - name: Run tests + run: swift test -v + macos-15: + name: Build macOS 15 (Swift 6.0) + runs-on: macos-15 + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Build + run: swift build -v + - name: Run tests + run: swift test -v + ubuntu: + name: Build Linux + runs-on: ubuntu-latest + container: + image: swift:latest + steps: + - uses: actions/checkout@v4 + - name: Build + run: swift build -v + - name: Run tests + run: swift test -v diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml deleted file mode 100644 index 67a622f..0000000 --- a/.github/workflows/linux.yml +++ /dev/null @@ -1,20 +0,0 @@ -name: Build Linux - -on: - push: - branches: [ "main" ] - pull_request: - branches: [ "main" ] - -jobs: - build: - name: Build Linux - runs-on: ubuntu-latest - container: - image: swift:latest - steps: - - uses: actions/checkout@v4 - - name: Build - run: swift build -v - - name: Run tests - run: swift test -v diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml deleted file mode 100644 index 98e74c9..0000000 --- a/.github/workflows/macos.yml +++ /dev/null @@ -1,19 +0,0 @@ -name: Build macOS - -on: - push: - branches: [ "main" ] - pull_request: - branches: [ "main" ] - -jobs: - build: - name: Build macOS - runs-on: macos-15 - steps: - - name: Checkout - uses: actions/checkout@v4 - - name: Build - run: swift build -v - - name: Run tests - run: swift test -v From 9ef63a35f19106f0c1d6c08ba42161a1cfc04ac4 Mon Sep 17 00:00:00 2001 From: Firdavs Khaydarov Date: Wed, 20 Nov 2024 10:31:17 +0200 Subject: [PATCH 3/6] Updated README.md --- README.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 53d74f9..a112118 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,6 @@ # EventSource -[![Build macOS](https://github.com/Recouse/EventSource/actions/workflows/macos.yml/badge.svg)](https://github.com/Recouse/EventSource/actions/workflows/macos.yml) -[![Build Linux](https://github.com/Recouse/EventSource/actions/workflows/linux.yml/badge.svg)](https://github.com/Recouse/EventSource/actions/workflows/linux.yml) +[![CI](https://github.com/Recouse/EventSource/actions/workflows/ci.yml/badge.svg)](https://github.com/Recouse/EventSource/actions/workflows/ci.yml) [![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2FRecouse%2FEventSource%2Fbadge%3Ftype%3Dplatforms)](https://swiftpackageindex.com/Recouse/EventSource) [![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2FRecouse%2FEventSource%2Fbadge%3Ftype%3Dswift-versions)](https://swiftpackageindex.com/Recouse/EventSource) @@ -104,7 +103,7 @@ var response: String = "" for await event in await dataTask.events() { switch event { case .event(let event): - if let eventData = event.data, let data = eventData.data(using: .utf8) { + if let data = eventDevent.data?ata.data(using: .utf8) { let chunk = try? JSONDecoder().decode(ChatCompletionChunk.self, from: data) let string = chunk?.choices.first?.delta.content ?? "" response += string From 5d36c7e6867c586b0ad5c250e2e79922af16215f Mon Sep 17 00:00:00 2001 From: Firdavs Khaydarov Date: Thu, 21 Nov 2024 02:28:44 +0200 Subject: [PATCH 4/6] Fixed swift 5.10 concurrency error --- Sources/EventSource/EventSource.swift | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Sources/EventSource/EventSource.swift b/Sources/EventSource/EventSource.swift index fb6cffd..f5688b9 100644 --- a/Sources/EventSource/EventSource.swift +++ b/Sources/EventSource/EventSource.swift @@ -151,10 +151,19 @@ public extension EventSource { } } + #if compiler(>=6.0) continuation.onTermination = { @Sendable [weak self] _ in sesstionDelegateTask.cancel() Task { await self?.close() } } + #else + continuation.onTermination = { @Sendable _ in + sesstionDelegateTask.cancel() + Task { [weak self] in + await self?.close() + } + } + #endif self.continuation = continuation From 2ded7e0a6d4cbc4bef5a005cd2a23a9590e7176e Mon Sep 17 00:00:00 2001 From: Firdavs Khaydarov Date: Thu, 21 Nov 2024 02:28:58 +0200 Subject: [PATCH 5/6] Renamed the CI workflow --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1151fa1..9a7ab62 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,4 +1,4 @@ -name: EventSource CI +name: CI on: push: From 04543b1907c030238a7d661f23051441717b4b22 Mon Sep 17 00:00:00 2001 From: Firdavs Khaydarov Date: Thu, 21 Nov 2024 02:32:35 +0200 Subject: [PATCH 6/6] No tests on macOS 14 Tests using Swift Testing framework which is only available in Xcode 16+, and macOS 14 only supports Xcode 15 --- .github/workflows/ci.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9a7ab62..5453fa8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,8 +15,6 @@ jobs: uses: actions/checkout@v4 - name: Build run: swift build -v - - name: Run tests - run: swift test -v macos-15: name: Build macOS 15 (Swift 6.0) runs-on: macos-15