Skip to content

Commit

Permalink
Merge pull request #18 from Recouse/ci-improvements
Browse files Browse the repository at this point in the history
CI improvements
  • Loading branch information
Recouse authored Nov 21, 2024
2 parents cb98227 + 04543b1 commit bcdfb61
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 46 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: 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
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
20 changes: 0 additions & 20 deletions .github/workflows/linux.yml

This file was deleted.

19 changes: 0 additions & 19 deletions .github/workflows/macos.yml

This file was deleted.

3 changes: 2 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version: 5.7
// swift-tools-version: 5.10

import PackageDescription

Expand All @@ -9,6 +9,7 @@ let package = Package(
.iOS(.v13),
.tvOS(.v13),
.watchOS(.v6),
.visionOS(.v1)
],
products: [
.library(
Expand Down
5 changes: 2 additions & 3 deletions [email protected][email protected]
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version: 5.9
// swift-tools-version: 6.0

import PackageDescription

Expand All @@ -18,8 +18,7 @@ let package = Package(
],
targets: [
.target(
name: "EventSource",
swiftSettings: [.enableExperimentalFeature("StrictConcurrency")]),
name: "EventSource"),
.testTarget(
name: "EventSourceTests",
dependencies: ["EventSource"]),
Expand Down
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -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)

Expand Down Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions Sources/EventSource/EventSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit bcdfb61

Please sign in to comment.