Skip to content

Commit

Permalink
Remove Linux builds
Browse files Browse the repository at this point in the history
  • Loading branch information
adamayoung committed Feb 26, 2024
1 parent 98c0e72 commit 48facbf
Show file tree
Hide file tree
Showing 11 changed files with 7 additions and 179 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/ci-documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@ concurrency:
group: "ci-documentation-${{ github.head_ref || github.run_id }}"
cancel-in-progress: true

env:
DEVELOPER_DIR: /Applications/Xcode_15.2.app/Contents/Developer

jobs:
build-documentation:
name: Build Documentation
runs-on: ubuntu-latest
runs-on: macos-14
env:
SWIFTCI_DOCC: 1
steps:
Expand Down
17 changes: 0 additions & 17 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,20 +58,3 @@ jobs:

- name: Test
run: set -o pipefail && env NSUnbufferedIO=YES && xcodebuild test-without-building -scheme PoliceDataKit -only-testing PoliceDataKitTests -destination '${{ matrix.destination }}' | xcpretty

build-test-linux:
name: Build and Test (Linux)
runs-on: ubuntu-latest
container: swift:5.9.2-jammy
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Build
run: swift build -Xswiftc -warnings-as-errors --build-tests

- name: Test
run: swift test --skip-build --parallel --filter PoliceDataKitTests

- name: Build for Release
run: swift build -c release -Xswiftc -warnings-as-errors
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Wales and Northern Ireland.

## Requirements

* Swift 5.7+
* Swift 5.9+

## Installation

Expand All @@ -19,15 +19,15 @@ Add the PoliceDataKit package as a dependency to your `Package.swift` file, and
add it as a dependency to your target.

```swift
// swift-tools-version:5.7
// swift-tools-version:5.9

import PackageDescription

let package = Package(
name: "MyProject",

dependencies: [
.package(url: "https://github.com/adamayoung/police-data-kit.git", from: "3.0.0")
.package(url: "https://github.com/adamayoung/police-data-kit.git", from: "4.0.0")
],

targets: [
Expand Down
6 changes: 0 additions & 6 deletions Sources/PoliceDataKit/Availability/AvailabilityService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
//

import Foundation
import os

///
/// Provides an interface for obtaining availability data sets from the UK Police API.
Expand All @@ -33,8 +32,6 @@ public final class AvailabilityService {
///
public static let shared = AvailabilityService()

private static let logger = Logger(subsystem: Logger.policeDataKit, category: "AvailabilityService")

private let apiClient: any APIClient
private let cache: any AvailabilityCache

Expand Down Expand Up @@ -66,8 +63,6 @@ public final class AvailabilityService {
/// - Returns: The available data sets.
///
public func availableDataSets() async throws -> [DataSet] {
Self.logger.trace("fetching available data sets")

if let cachedDataSets = await cache.availableDataSets() {
return cachedDataSets
}
Expand All @@ -76,7 +71,6 @@ public final class AvailabilityService {
do {
dataSets = try await apiClient.get(endpoint: AvailabilityEndpoint.dataSets)
} catch let error {
Self.logger.error("failed fetching available data sets: \(error.localizedDescription)")
throw Self.mapToAvailabilityError(error)
}

Expand Down
8 changes: 0 additions & 8 deletions Sources/PoliceDataKit/Cache/InMemoryCache.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,37 +18,31 @@
//

import Foundation
import os

final actor InMemoryCache: Cache {

private let cache: NSCache<NSString, CacheItem>
private let defaultExpiresIn: TimeInterval
private let logger: Logger

init(name: String, defaultExpiresIn: TimeInterval = 60 * 60 * 12, countLimit: Int = 0) {
self.cache = NSCache()
cache.name = name
cache.countLimit = countLimit
self.defaultExpiresIn = defaultExpiresIn
self.logger = Logger(subsystem: Logger.policeDataKit, category: "\(name)InMemoryCache")
}

func object<ObjectType: Any>(for key: some CustomStringConvertible, type _: ObjectType.Type) async -> ObjectType? {
let cacheKey = keyValue(for: key)

guard let item = cache.object(forKey: cacheKey) else {
logger.trace("MISS \(key.description)")
return nil
}

guard !item.isExpired else {
logger.trace("EXPIRED \(key.description)")
cache.removeObject(forKey: cacheKey)
return nil
}

logger.trace("HIT \(key.description)")
return item.object as? ObjectType
}

Expand All @@ -57,13 +51,11 @@ final actor InMemoryCache: Cache {

guard let object else {
cache.removeObject(forKey: cacheKey)
logger.trace("REMOVE \(key.description)")
return
}

let item = CacheItem(key: key.description, object: object, expiresIn: expiresIn ?? defaultExpiresIn)
cache.setObject(item, forKey: cacheKey)
logger.trace("ADD \(key.description)")
}

func removeAll() async {
Expand Down
27 changes: 0 additions & 27 deletions Sources/PoliceDataKit/Crimes/CrimeService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import Combine
import Foundation
import MapKit
import os

///
/// Provides an interface for obtaining crime data from the UK Police API.
Expand All @@ -35,8 +34,6 @@ public final class CrimeService {
///
public static let shared = CrimeService()

private static let logger = Logger(subsystem: Logger.policeDataKit, category: "CrimeService")

private let apiClient: any APIClient
private let cache: any CrimeCache
private let availableDataRegion: MKCoordinateRegion
Expand Down Expand Up @@ -81,8 +78,6 @@ public final class CrimeService {
/// - Returns: The street level crimes in a 1 mile radius of the specifed coordinate and date.
///
public func streetLevelCrimes(at coordinate: CLLocationCoordinate2D, date: Date = Date()) async throws -> [Crime] {
Self.logger.trace("fetching street level Crimes at coordinate \(coordinate, privacy: .public)")

guard availableDataRegion.contains(coordinate: coordinate) else {
throw CrimeError.locationOutsideOfDataSetRegion
}
Expand All @@ -93,8 +88,6 @@ public final class CrimeService {
endpoint: CrimesEndpoint.streetLevelCrimesAtSpecificPoint(coordinate: coordinate, date: date)
)
} catch let error {
// swiftlint:disable:next line_length
Self.logger.error("failed fetching street level Crimes at coordinate \(coordinate, privacy: .public): \(error.localizedDescription, privacy: .public)")
throw Self.mapToCrimeError(error)
}

Expand Down Expand Up @@ -164,16 +157,13 @@ public final class CrimeService {
in coordinates: [CLLocationCoordinate2D],
date: Date = Date()
) async throws -> [Crime] {
Self.logger.trace("fetching street level Crimes in area")

let crimes: [Crime]
do {
crimes = try await apiClient.get(
endpoint: CrimesEndpoint.streetLevelCrimesInArea(coordinates: coordinates, date: date)
)
} catch let error {
// swiftlint:disable:next line_length
Self.logger.error("failed fetching street level Crimes in area: \(error.localizedDescription, privacy: .public)")
throw Self.mapToCrimeError(error)
}

Expand Down Expand Up @@ -238,8 +228,6 @@ public final class CrimeService {
/// - Returns: The crimes at the specified street and date.
///
public func crimes(forStreet streetID: Int, date: Date = Date()) async throws -> [Crime] {
Self.logger.trace("fetching Crimes for street \(streetID, privacy: .public)")

if let cachedCrimes = await cache.crimes(forStreet: streetID, date: date) {
return cachedCrimes
}
Expand All @@ -250,8 +238,6 @@ public final class CrimeService {
endpoint: CrimesEndpoint.crimesAtLocationForStreet(streetID: streetID, date: date)
)
} catch let error {
// swiftlint:disable:next line_length
Self.logger.error("failed fetching Crimes for street \(streetID, privacy: .public): \(error.localizedDescription, privacy: .public)")
throw Self.mapToCrimeError(error)
}

Expand All @@ -277,8 +263,6 @@ public final class CrimeService {
/// - Returns: The crimes for the street nearest to the specified coordinate and date.
///
public func crimes(at coordinate: CLLocationCoordinate2D, date: Date = Date()) async throws -> [Crime] {
Self.logger.trace("fetching Crimes at coordinate \(coordinate, privacy: .public)")

guard availableDataRegion.contains(coordinate: coordinate) else {
throw CrimeError.locationOutsideOfDataSetRegion
}
Expand All @@ -289,8 +273,6 @@ public final class CrimeService {
endpoint: CrimesEndpoint.crimesAtLocationAtSpecificPoint(coordinate: coordinate, date: date)
)
} catch let error {
// swiftlint:disable:next line_length
Self.logger.error("failed fetching Crimes at coordinate \(coordinate, privacy: .public): \(error.localizedDescription, privacy: .public)")
throw Self.mapToCrimeError(error)
}

Expand Down Expand Up @@ -353,9 +335,6 @@ public final class CrimeService {
inPoliceForce policeForceID: PoliceForce.ID,
date: Date = Date()
) async throws -> [Crime] {
// swiftlint:disable:next line_length
Self.logger.trace("fetching Crimes with no location for category \(categoryID, privacy: .public) in Police Force \(policeForceID, privacy: .public)")

if let cachedCrimes = await cache.crimesWithNoLocation(
forCategory: categoryID,
inPoliceForce: policeForceID,
Expand All @@ -372,8 +351,6 @@ public final class CrimeService {
)
)
} catch let error {
// swiftlint:disable:next line_length
Self.logger.error("failed fetching Crimes with no location for category \(categoryID, privacy: .public) in Police Force \(policeForceID, privacy: .public): \(error.localizedDescription, privacy: .public)")
throw Self.mapToCrimeError(error)
}

Expand All @@ -394,8 +371,6 @@ public final class CrimeService {
/// - Returns: The crime categories for the specified month.
///
public func crimeCategories(forDate date: Date = Date()) async throws -> [CrimeCategory] {
Self.logger.trace("fetching Crime categories for date \(date, privacy: .public)")

if let cachedCategories = await cache.crimeCategories(forDate: date) {
return cachedCategories
}
Expand All @@ -404,8 +379,6 @@ public final class CrimeService {
do {
crimeCategories = try await apiClient.get(endpoint: CrimesEndpoint.categories(date: date))
} catch let error {
// swiftlint:disable:next line_length
Self.logger.error("failed fetching Crime categories for date \(date, privacy: .public): \(error.localizedDescription, privacy: .public)")
throw Self.mapToCrimeError(error)
}

Expand Down
27 changes: 0 additions & 27 deletions Sources/PoliceDataKit/Logger+PoliceDataKit.swift

This file was deleted.

Loading

0 comments on commit 48facbf

Please sign in to comment.