Skip to content

Commit

Permalink
Update to Swift 5.8 Toolchain (#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
vsanthanam authored May 6, 2023
1 parent 918943b commit d70fc48
Show file tree
Hide file tree
Showing 8 changed files with 126 additions and 75 deletions.
8 changes: 5 additions & 3 deletions .github/workflows/spm-build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ on:

jobs:
build:

runs-on: macos-12

runs-on: macos-13
steps:
- uses: actions/checkout@v3
- name: Xcode Version
run: sudo xcode-select --switch /Applications/Xcode_14.3.app
- name: Lint
run: swift package plugin --allow-writing-to-package-directory swiftformat --lint
- name: Build
run: swift build -v
- name: Run tests
Expand Down
20 changes: 19 additions & 1 deletion Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,27 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-docc-plugin",
"state" : {
"revision" : "3303b164430d9a7055ba484c8ead67a52f7b74f6",
"revision" : "9b1258905c21fc1b97bf03d1b4ca12c4ec4e5fda",
"version" : "1.2.0"
}
},
{
"identity" : "swift-docc-symbolkit",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-docc-symbolkit",
"state" : {
"revision" : "b45d1f2ed151d057b54504d653e0da5552844e34",
"version" : "1.0.0"
}
},
{
"identity" : "swiftformat",
"kind" : "remoteSourceControl",
"location" : "https://github.com/nicklockwood/SwiftFormat",
"state" : {
"revision" : "fee7e1a1ac9518cfe3c4673382368641ccbdc62c",
"version" : "0.51.7"
}
}
],
"version" : 2
Expand Down
5 changes: 3 additions & 2 deletions 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.8
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription
Expand All @@ -18,7 +18,8 @@ let package = Package(
),
],
dependencies: [
.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0")
.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0"),
.package(url: "https://github.com/nicklockwood/SwiftFormat", exact: "0.51.7")
],
targets: [
.target(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@
func request(_ demand: Subscribers.Demand) {
requested += 1
do {
networkMonitor = .withContinuation(try refBuilder()) { [weak self] result in
networkMonitor = try .withContinuation(refBuilder()) { [weak self] result in
guard let self = self,
let subscriber = self.subscriber,
self.requested > .none else { return }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
private func stream(_ refBuilder: () throws -> SCNetworkReachability) -> AsyncThrowingStream<Reachability, Swift.Error> {
.init(bufferingPolicy: .bufferingNewest(1)) { continuation in
do {
_ = ReachabilityMonitor.withContinuation(try refBuilder()) { result in
_ = try ReachabilityMonitor.withContinuation(refBuilder()) { result in
do {
let reachability = try result.get()
continuation.yield(reachability)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,10 @@
///
/// - Throws: An error of type ``Error``
public convenience init() throws {
self.init(ref: try .general,
updateHandler: nil,
delegate: nil,
updateQueue: nil)
try self.init(ref: .general,
updateHandler: nil,
delegate: nil,
updateQueue: nil)
}

/// Create a reachablity monitor for a specific host
Expand All @@ -121,10 +121,10 @@
///
/// - Throws: An error of type ``Error``
public convenience init(host: String) throws {
self.init(ref: try .forHost(host),
updateHandler: nil,
delegate: nil,
updateQueue: nil)
try self.init(ref: .forHost(host),
updateHandler: nil,
delegate: nil,
updateQueue: nil)
}

/// Create a reachablity monitor for a socket address
Expand All @@ -135,10 +135,10 @@
///
/// - Throws: An error of type ``Error``
public convenience init(address: sockaddr) throws {
self.init(ref: try .forAddress(address),
updateHandler: nil,
delegate: nil,
updateQueue: nil)
try self.init(ref: .forAddress(address),
updateHandler: nil,
delegate: nil,
updateQueue: nil)
}

/// Create a reachability monitor with a closure used to respond to reachability changes
Expand All @@ -149,10 +149,10 @@
///
/// - Throws: An error of type ``Error``
public convenience init(updateHandler: @escaping UpdateHandler) throws {
self.init(ref: try .general,
updateHandler: updateHandler,
delegate: nil,
updateQueue: nil)
try self.init(ref: .general,
updateHandler: updateHandler,
delegate: nil,
updateQueue: nil)
}

/// Create a reachability monitor with a closure used to respond to reachability changes on a specific queue
Expand All @@ -166,10 +166,10 @@
/// - Throws: An error of type ``Error
public convenience init(updateQueue: DispatchQueue,
updateHandler: @escaping UpdateHandler) throws {
self.init(ref: try .general,
updateHandler: updateHandler,
delegate: nil,
updateQueue: updateQueue)
try self.init(ref: .general,
updateHandler: updateHandler,
delegate: nil,
updateQueue: updateQueue)
}

/// Create a reachability monitor for a specific host with a closure used to respond to reachability changes
Expand All @@ -183,10 +183,10 @@
/// - Throws: An error of type ``Error``
public convenience init(host: String,
updateHandler: @escaping UpdateHandler) throws {
self.init(ref: try .forHost(host),
updateHandler: updateHandler,
delegate: nil,
updateQueue: nil)
try self.init(ref: .forHost(host),
updateHandler: updateHandler,
delegate: nil,
updateQueue: nil)
}

/// Create a reachability monitor for a specific host with a closure used to respond to reachability changes on a specific queue
Expand All @@ -203,10 +203,10 @@
public convenience init(host: String,
updateQueue: DispatchQueue,
updateHandler: @escaping UpdateHandler) throws {
self.init(ref: try .forHost(host),
updateHandler: updateHandler,
delegate: nil,
updateQueue: updateQueue)
try self.init(ref: .forHost(host),
updateHandler: updateHandler,
delegate: nil,
updateQueue: updateQueue)
}

/// Create a reachability monitor for a specific socket address with a closure used to respond to reachability changes
Expand All @@ -220,10 +220,10 @@
/// - Throws: An error of type ``Error``
public convenience init(address: sockaddr,
updateHandler: @escaping UpdateHandler) throws {
self.init(ref: try .forAddress(address),
updateHandler: updateHandler,
delegate: nil,
updateQueue: nil)
try self.init(ref: .forAddress(address),
updateHandler: updateHandler,
delegate: nil,
updateQueue: nil)
}

/// Create a reachability monitor for a specific socket address with a closure used to respond to reachability changes on a specific queue
Expand All @@ -239,10 +239,10 @@
public convenience init(address: sockaddr,
updateQueue: DispatchQueue,
updateHandler: @escaping UpdateHandler) throws {
self.init(ref: try .forAddress(address),
updateHandler: updateHandler,
delegate: nil,
updateQueue: updateQueue)
try self.init(ref: .forAddress(address),
updateHandler: updateHandler,
delegate: nil,
updateQueue: updateQueue)
}

/// Create a reachability monitor with a delegate object used to respond to reachability changes
Expand All @@ -253,10 +253,10 @@
///
/// - Throws: An error of type ``Error``
public convenience init(delegate: any Delegate) throws {
self.init(ref: try .general,
updateHandler: nil,
delegate: delegate,
updateQueue: nil)
try self.init(ref: .general,
updateHandler: nil,
delegate: delegate,
updateQueue: nil)
}

/// Create a reachability monitor with a delegate object used to respond to reachability changes
Expand All @@ -270,10 +270,10 @@
/// - Throws: An error of type ``Error``
public convenience init(updateQueue: DispatchQueue,
delegate: any Delegate) throws {
self.init(ref: try .general,
updateHandler: nil,
delegate: delegate,
updateQueue: updateQueue)
try self.init(ref: .general,
updateHandler: nil,
delegate: delegate,
updateQueue: updateQueue)
}

/// Create a reachability monitor for a specific host with a delegate object used to respond to reachability changes
Expand All @@ -287,10 +287,10 @@
/// - Throws: An error of type ``Error``
public convenience init(host: String,
delegate: any Delegate) throws {
self.init(ref: try .forHost(host),
updateHandler: nil,
delegate: delegate,
updateQueue: nil)
try self.init(ref: .forHost(host),
updateHandler: nil,
delegate: delegate,
updateQueue: nil)
}

/// Create a reachability monitor for a specific host with a delegate object used to respond to reachability changes
Expand All @@ -306,10 +306,10 @@
public convenience init(host: String,
updateQueue: DispatchQueue,
delegate: any Delegate) throws {
self.init(ref: try .forHost(host),
updateHandler: nil,
delegate: delegate,
updateQueue: updateQueue)
try self.init(ref: .forHost(host),
updateHandler: nil,
delegate: delegate,
updateQueue: updateQueue)
}

/// Create a reachability monitor for a specific socket address with a delegate object used to respond to reachability changes
Expand All @@ -323,10 +323,10 @@
/// - Throws: An error of type ``Error``
public convenience init(address: sockaddr,
delegate: any Delegate) throws {
self.init(ref: try .forAddress(address),
updateHandler: nil,
delegate: delegate,
updateQueue: nil)
try self.init(ref: .forAddress(address),
updateHandler: nil,
delegate: delegate,
updateQueue: nil)
}

/// Create a reachability monitor for a specific socket address with a delegate object used to respond to reachability changes
Expand All @@ -342,10 +342,10 @@
public convenience init(address: sockaddr,
updateQueue: DispatchQueue,
delegate: any Delegate) throws {
self.init(ref: try .forAddress(address),
updateHandler: nil,
delegate: delegate,
updateQueue: updateQueue)
try self.init(ref: .forAddress(address),
updateHandler: nil,
delegate: delegate,
updateQueue: updateQueue)
}

// MARK: - API
Expand Down Expand Up @@ -413,7 +413,7 @@
public var currentReachability: Reachability {
get throws {
refreshFlags()
return Reachability(flags: try flags.get())
return try Reachability(flags: flags.get())
}
}

Expand Down
4 changes: 2 additions & 2 deletions Tests/NetworkReachabilityTests/ReachabilityMonitorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
func test_observe_closure() {
let expectation = expectation(description: "pass")
do {
withExtendedLifetime(try ReachabilityMonitor(updateHandler: { _, reachability in
try withExtendedLifetime(ReachabilityMonitor(updateHandler: { _, reachability in
do {
if try reachability.get().status.isReachable {
expectation.fulfill()
Expand Down Expand Up @@ -125,7 +125,7 @@
let expectation = expectation(description: "pass")
withExtendedLifetime(Observer(expectation)) {
do {
withExtendedLifetime(try ReachabilityMonitor()) {
try withExtendedLifetime(ReachabilityMonitor()) {
waitForExpectations(timeout: 5)
}
} catch {
Expand Down
38 changes: 34 additions & 4 deletions generate-static-site.sh
Original file line number Diff line number Diff line change
@@ -1,20 +1,50 @@
#!/bin/bash
branch=$(git branch | sed -n -e 's/^\* \(.*\)/\1/p')

if [[ "$branch" != "main" ]]; then
echo "Invalid Branch"
else
run_docc () {
swift package --allow-writing-to-directory docs generate-documentation --target NetworkReachability --disable-indexing --transform-for-static-hosting --hosting-base-path docs --output-path docs --include-extended-types
}

create_branches () {
git branch -D gh-pages
git checkout -b gh-pages
swift package --allow-writing-to-directory docs generate-documentation --target NetworkReachability --disable-indexing --transform-for-static-hosting --hosting-base-path docs --output-path docs
}

fix_readme () {
tail -n +2 README.md > README-2.md && mv README-2.md README.md
}

configure_site () {
echo "reachability.tools" > CNAME
echo "theme: jekyll-theme-modernist" > _config.yml
}

commit_and_publish () {
git add .
git commit -m 'Synchronize Hompage & Publish Documentation'
git push -f -u origin gh-pages
}

clean_up () {
git checkout main
git branch -D gh-pages
rm -rf docs
}

generate_documentation () {
create_branches
run_docc
fix_readme
configure_site
commit_and_publish
clean_up
}

if [[ "$branch" != "main" ]]; then
echo "Invalid Branch"
elif [[ -n $(git status -s) ]]; then
echo "Uncommited Changes"
else
generate_documentation
echo "Website Updated!"
fi

0 comments on commit d70fc48

Please sign in to comment.