Skip to content

Commit

Permalink
bugfix/swift 510 compile errors (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
jagreenwood authored Dec 3, 2024
1 parent c7f7420 commit e199663
Show file tree
Hide file tree
Showing 8 changed files with 211 additions and 68 deletions.
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Swift",
"image": "swift:5.9.1",
"image": "swift:5.10",
"features": {
"ghcr.io/devcontainers/features/common-utils:2": {
"installZsh": "false",
Expand Down
25 changes: 25 additions & 0 deletions .github/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# https://docs.github.com/en/repositories/releasing-projects-on-github/automatically-generated-release-notes#configuration-options
changelog:
exclude:
labels:
- ci
- ignore-for-release
authors:
- github-actions
- octocat
categories:
- title: Breaking Changes 🛠
labels:
- semver/major
- breaking-change
- title: New Features 🎉
labels:
- semver/minor
- enhancement
- title: Bug Fixes 🐛
labels:
- semver/patch
- bug
- title: Other Changes
labels:
- "*"
64 changes: 64 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: Release
on:
workflow_dispatch:
inputs:
release_type:
description: Type of release
type: choice
required: true
options:
- patch
- minor
- major

jobs:
release:
name: Release
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Git checkout
uses: actions/checkout@v4

- name: Get latest release version
id: get_current_version
uses: actions/github-script@v7
with:
script: |
const { data: { tag_name } } = await github.rest.repos.getLatestRelease({
owner: context.repo.owner,
repo: context.repo.repo
})
return tag_name
- name: Bump version
id: bump
uses: Mobelux/bump-version-action@v1
with:
release-type: ${{ inputs.release_type }}
version: ${{ steps.get_current_version.outputs.result }}

- name: Push tag
uses: actions/github-script@v7
with:
script: |
github.rest.git.createRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: 'refs/tags/${{ steps.bump.outputs.version }}',
sha: context.sha
})
- name: Create release
uses: actions/github-script@v7
with:
script: |
github.rest.repos.createRelease({
owner: context.repo.owner,
repo: context.repo.repo,
tag_name: '${{ steps.bump.outputs.version }}',
generate_release_notes: true,
draft: false,
prerelease: false
})
6 changes: 3 additions & 3 deletions .github/workflows/swift-macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ jobs:
build:
runs-on: macos-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Build
run: swift build -v
run: swift build
- name: Run tests
run: swift test -v
run: swift test
6 changes: 3 additions & 3 deletions .github/workflows/swift-ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Build
run: swift build -v
run: swift build
- name: Run tests
run: swift test -v
run: swift test
52 changes: 37 additions & 15 deletions Sources/OpenWeatherKit/Public/Requests/WeatherQuery.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,27 @@ import Foundation
public struct WeatherQuery<T> {
@usableFromInline
let queryType: QueryType

@usableFromInline
let weatherKeyPath: KeyPath<WeatherProxy, T?>
let result: (WeatherProxy) throws -> T

/// The current weather query.
public static var current: WeatherQuery<CurrentWeather> {
WeatherQuery<CurrentWeather>(
queryType: .current(APIWeather.CodingKeys.currentWeather.rawValue),
weatherKeyPath: \.currentWeather
result: { try $0.currentWeather
.unwrap(or: WeatherError.missingData(APIWeather.CodingKeys.currentWeather.rawValue))
}
)
}

/// The minute forecast query.
public static var minute: WeatherQuery<Forecast<MinuteWeather>?> {
WeatherQuery<Forecast<MinuteWeather>?>(
queryType: .minute(APIWeather.CodingKeys.forecastNextHour.rawValue),
weatherKeyPath: \.minuteForecast?
result: { try $0.minuteForecast
.unwrap(or: WeatherError.missingData(APIWeather.CodingKeys.forecastNextHour.rawValue))
}
)
}

Expand All @@ -40,7 +44,9 @@ public struct WeatherQuery<T> {
Date(),
Date.hoursFromNow(24)
),
weatherKeyPath: \.hourlyForecast
result: { try $0.hourlyForecast
.unwrap(or: WeatherError.missingData(APIWeather.CodingKeys.forecastHourly.rawValue))
}
)
}

Expand All @@ -52,17 +58,21 @@ public struct WeatherQuery<T> {
Date(),
Date.daysFromNow(10)
),
weatherKeyPath: \.dailyForecast
result: { try $0.dailyForecast
.unwrap(or: WeatherError.missingData(APIWeather.CodingKeys.forecastDaily.rawValue))
}
)
}

#if canImport(CoreLocation)
public static var alerts: WeatherQuery<[WeatherAlert]?> {
WeatherQuery<[WeatherAlert]?>(
queryType: .availability(
queryType: .alerts(
APIWeather.CodingKeys.weatherAlerts.rawValue, ""
),
weatherKeyPath: \.weatherAlerts?
result: { try $0.weatherAlerts
.unwrap(or: WeatherError.missingData(APIWeather.CodingKeys.weatherAlerts.rawValue))
}
)
}

Expand All @@ -71,7 +81,10 @@ public struct WeatherQuery<T> {
queryType: .availability(
QueryContants.availability, ""
),
weatherKeyPath: \.availability)
result: { try $0.availability
.unwrap(or: WeatherError.missingData(QueryContants.availability))
}
)
}
#endif
}
Expand All @@ -88,7 +101,9 @@ public extension WeatherQuery where T == Forecast<DayWeather> {
startDate,
endDate
),
weatherKeyPath: \.dailyForecast
result: { try $0.dailyForecast
.unwrap(or: WeatherError.missingData(APIWeather.CodingKeys.forecastDaily.rawValue))
}
)
}
}
Expand All @@ -104,7 +119,9 @@ public extension WeatherQuery where T == Forecast<HourWeather> {
startDate,
endDate
),
weatherKeyPath: \.hourlyForecast
result: { try $0.hourlyForecast
.unwrap(or: WeatherError.missingData(APIWeather.CodingKeys.forecastHourly.rawValue))
}
)
}
}
Expand All @@ -117,7 +134,9 @@ public extension WeatherQuery where T == [WeatherAlert]? {
APIWeather.CodingKeys.weatherAlerts.rawValue,
countryCode
),
weatherKeyPath: \.weatherAlerts?
result: { try $0.weatherAlerts
.unwrap(or: WeatherError.missingData(APIWeather.CodingKeys.weatherAlerts.rawValue))
}
)
}
}
Expand All @@ -130,7 +149,10 @@ public extension WeatherQuery where T == WeatherAvailability {
QueryContants.availability,
countryCode
),
weatherKeyPath: \.availability)
result: { try $0.availability
.unwrap(or: WeatherError.missingData(QueryContants.availability))
}
)
}
}

Expand All @@ -143,14 +165,14 @@ extension WeatherQuery {
queryType: .alerts(
dataSet,
countryCode),
weatherKeyPath: weatherKeyPath
result: result
)
case let .availability(dataSet, _):
return WeatherQuery(
queryType: .availability(
dataSet,
countryCode),
weatherKeyPath: weatherKeyPath
result: result
)
default: return self
}
Expand Down
63 changes: 21 additions & 42 deletions Sources/OpenWeatherKit/Public/WeatherService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,7 @@ final public class WeatherService: Sendable {
jwt: Self.configuration.jwt()
)

return try proxy[keyPath: _dataSet.weatherKeyPath]
.unwrap(or: WeatherError.missingData(_dataSet.queryType.dataSet))
return try _dataSet.result(proxy)
}

///
Expand Down Expand Up @@ -231,10 +230,8 @@ final public class WeatherService: Sendable {
)

return try (
proxy[keyPath: _dataSet1.weatherKeyPath]
.unwrap(or: WeatherError.missingData(_dataSet1.queryType.dataSet)),
proxy[keyPath: _dataSet2.weatherKeyPath]
.unwrap(or: WeatherError.missingData(_dataSet2.queryType.dataSet))
_dataSet1.result(proxy),
_dataSet2.result(proxy)
)
}

Expand Down Expand Up @@ -275,12 +272,9 @@ final public class WeatherService: Sendable {
)

return try (
proxy[keyPath: _dataSet1.weatherKeyPath]
.unwrap(or: WeatherError.missingData(_dataSet1.queryType.dataSet)),
proxy[keyPath: _dataSet2.weatherKeyPath]
.unwrap(or: WeatherError.missingData(_dataSet2.queryType.dataSet)),
proxy[keyPath: _dataSet3.weatherKeyPath]
.unwrap(or: WeatherError.missingData(_dataSet3.queryType.dataSet))
_dataSet1.result(proxy),
_dataSet2.result(proxy),
_dataSet3.result(proxy)
)
}

Expand Down Expand Up @@ -324,14 +318,10 @@ final public class WeatherService: Sendable {
)

return try (
proxy[keyPath: _dataSet1.weatherKeyPath]
.unwrap(or: WeatherError.missingData(_dataSet1.queryType.dataSet)),
proxy[keyPath: _dataSet2.weatherKeyPath]
.unwrap(or: WeatherError.missingData(_dataSet2.queryType.dataSet)),
proxy[keyPath: _dataSet3.weatherKeyPath]
.unwrap(or: WeatherError.missingData(_dataSet3.queryType.dataSet)),
proxy[keyPath: _dataSet4.weatherKeyPath]
.unwrap(or: WeatherError.missingData(_dataSet4.queryType.dataSet))
_dataSet1.result(proxy),
_dataSet2.result(proxy),
_dataSet3.result(proxy),
_dataSet4.result(proxy)
)
}

Expand Down Expand Up @@ -378,16 +368,11 @@ final public class WeatherService: Sendable {
)

return try (
proxy[keyPath: _dataSet1.weatherKeyPath]
.unwrap(or: WeatherError.missingData(_dataSet1.queryType.dataSet)),
proxy[keyPath: _dataSet2.weatherKeyPath]
.unwrap(or: WeatherError.missingData(_dataSet2.queryType.dataSet)),
proxy[keyPath: _dataSet3.weatherKeyPath]
.unwrap(or: WeatherError.missingData(_dataSet3.queryType.dataSet)),
proxy[keyPath: _dataSet4.weatherKeyPath]
.unwrap(or: WeatherError.missingData(_dataSet4.queryType.dataSet)),
proxy[keyPath: _dataSet5.weatherKeyPath]
.unwrap(or: WeatherError.missingData(_dataSet5.queryType.dataSet))
_dataSet1.result(proxy),
_dataSet2.result(proxy),
_dataSet3.result(proxy),
_dataSet4.result(proxy),
_dataSet5.result(proxy)
)
}

Expand Down Expand Up @@ -437,18 +422,12 @@ final public class WeatherService: Sendable {
)

return try (
proxy[keyPath: _dataSet1.weatherKeyPath]
.unwrap(or: WeatherError.missingData(_dataSet1.queryType.dataSet)),
proxy[keyPath: _dataSet2.weatherKeyPath]
.unwrap(or: WeatherError.missingData(_dataSet2.queryType.dataSet)),
proxy[keyPath: _dataSet3.weatherKeyPath]
.unwrap(or: WeatherError.missingData(_dataSet3.queryType.dataSet)),
proxy[keyPath: _dataSet4.weatherKeyPath]
.unwrap(or: WeatherError.missingData(_dataSet4.queryType.dataSet)),
proxy[keyPath: _dataSet5.weatherKeyPath]
.unwrap(or: WeatherError.missingData(_dataSet5.queryType.dataSet)),
proxy[keyPath: _dataSet6.weatherKeyPath]
.unwrap(or: WeatherError.missingData(_dataSet6.queryType.dataSet))
_dataSet1.result(proxy),
_dataSet2.result(proxy),
_dataSet3.result(proxy),
_dataSet4.result(proxy),
_dataSet5.result(proxy),
_dataSet6.result(proxy)
)
}
}
Expand Down
Loading

0 comments on commit e199663

Please sign in to comment.