Skip to content

Commit

Permalink
2.x.x -CI updates (#385)
Browse files Browse the repository at this point in the history
* Add timeouts, Add nightly-jammy to ci.yml

* Update actions/checkout version

* Remove nightly as things need fixed

* Enable swift-format validation

* Updates from project template

* Swift Format changes

* Update swiftformat version in validate.sh

* Setup dependabot

* Dependabot update, fix link in CONTRIBUTING

* SwiftFormat

* Fix server.swift

* Disable typeSugar swiftformat rule
  • Loading branch information
adam-fowler authored Feb 19, 2024
1 parent 88a49ba commit 65fd51f
Show file tree
Hide file tree
Showing 27 changed files with 217 additions and 251 deletions.
21 changes: 21 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "daily"
groups:
dependencies:
patterns:
- "*"
- package-ecosystem: "swift"
directory: "/"
schedule:
interval: "daily"
open-pull-requests-limit: 6
allow:
- dependency-type: all
groups:
all-dependencies:
patterns:
- "*"
7 changes: 4 additions & 3 deletions .github/workflows/api-breakage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@ name: API breaking changes
on:
pull_request:
branches:
- main
- main

jobs:
linux:
runs-on: ubuntu-latest
timeout-minutes: 15
container:
image: swift:5.8
image: swift:5.9
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0
# https://github.com/actions/checkout/issues/766
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@ jobs:
benchmark-delta:

runs-on: ${{ matrix.os }}
timeout-minutes: 15
continue-on-error: true

strategy:
matrix:
os: [ubuntu-latest]

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0

Expand Down
21 changes: 2 additions & 19 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,9 @@ on:
workflow_dispatch:

jobs:
# macOS:
# runs-on: macOS-13
# steps:
# - name: Checkout
# uses: actions/checkout@v3
# - name: SPM tests
# run: swift test --enable-code-coverage
# - name: Convert coverage files
# run: |
# xcrun llvm-cov export -format "lcov" \
# .build/debug/hummingbirdPackageTests.xctest/Contents/MacOs/hummingbirdPackageTests \
# -ignore-filename-regex="\/Tests\/" \
# -ignore-filename-regex="\/Benchmarks\/" \
# -instr-profile=.build/debug/codecov/default.profdata > info.lcov
# - name: Upload to codecov.io
# uses: codecov/codecov-action@v3
# with:
# file: info.lcov
linux:
runs-on: ubuntu-latest
timeout-minutes: 15
strategy:
matrix:
image:
Expand All @@ -45,7 +28,7 @@ jobs:
image: ${{ matrix.image }}
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Test
run: |
swift test --enable-code-coverage
Expand Down
35 changes: 0 additions & 35 deletions .github/workflows/codeql.yml

This file was deleted.

12 changes: 2 additions & 10 deletions .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,12 @@
name: Swift nightly build

on:
schedule:
- cron: '0 1 * * *'
workflow_dispatch:

jobs:
macOS:
runs-on: macOS-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: SPM tests
run: swift test
linux:
runs-on: ubuntu-latest
timeout-minutes: 15
strategy:
matrix:
image: ['nightly-focal', 'nightly-jammy', 'nightly-amazonlinux2']
Expand All @@ -23,7 +15,7 @@ jobs:
image: swiftlang/swift:${{ matrix.image }}
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Test
run: |
swift test --enable-test-discovery
6 changes: 4 additions & 2 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,20 @@ on:
pull_request:
branches:
- main
- 2.x.x

jobs:
validate:
runs-on: macOS-latest
timeout-minutes: 15
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Install Dependencies
run: |
brew install mint
mint install NickLockwood/SwiftFormat@0.48.17 --no-link
mint install NickLockwood/SwiftFormat@0.51.15 --no-link
- name: run script
run: ./scripts/validate.sh
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ xcuserdata/
Package.resolved
/public
/docs
.benchmarkBaselines
.benchmarkBaselines
4 changes: 2 additions & 2 deletions .swiftformat
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Minimum swiftformat version
--minversion 0.47.4
--minversion 0.51.0

# Swift version
--swiftversion 5.9
Expand All @@ -8,7 +8,7 @@
--exclude .build

# rules
--disable redundantReturn, extensionAccessControl, conditionalAssignment
--disable redundantReturn, extensionAccessControl, typeSugar

# format options
--ifdef no-indent
Expand Down
2 changes: 1 addition & 1 deletion Benchmarks/Benchmarks/Router/Benchmarks.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
//
//===----------------------------------------------------------------------===//

@testable import Hummingbird
import Benchmark
@testable import Hummingbird

let benchmarks = {
Benchmark.defaultConfiguration = .init(
Expand Down
4 changes: 2 additions & 2 deletions Benchmarks/Benchmarks/Router/RouterBenchmarks.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ extension Benchmark {
for _ in 0..<50 {
try await withThrowingTaskGroup(of: Void.self) { group in
let context = Context(
allocator: ByteBufferAllocator(),
allocator: ByteBufferAllocator(),
logger: Logger(label: "Benchmark")
)
let (inbound, source) = NIOAsyncChannelInboundStream<HTTPRequestPart>.makeTestingStream()
Expand Down Expand Up @@ -86,7 +86,7 @@ extension HTTPField.Name {
}

func routerBenchmarks() {
let buffer = ByteBufferAllocator().buffer(repeating: 0xff, count: 10000)
let buffer = ByteBufferAllocator().buffer(repeating: 0xFF, count: 10000)
Benchmark(
name: "Router:GET",
configuration: .init(warmupIterations: 10),
Expand Down
10 changes: 5 additions & 5 deletions Benchmarks/Benchmarks/Router/TrieRouterBenchmarks.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
//
//===----------------------------------------------------------------------===//

@testable import Hummingbird
import Benchmark
@testable import Hummingbird

func trieRouterBenchmarks() {
var trie: RouterPathTrie<String>!
Expand All @@ -25,9 +25,9 @@ func trieRouterBenchmarks() {
"/doesntExist",
]
benchmark.startMeasurement()

for _ in benchmark.scaledIterations {
blackHole(testValues.map { trie.getValueAndParameters($0)})
blackHole(testValues.map { trie.getValueAndParameters($0) })
}
} setup: {
let trieBuilder = RouterPathTrieBuilder<String>()
Expand All @@ -48,9 +48,9 @@ func trieRouterBenchmarks() {
"/test2/one/two",
]
benchmark.startMeasurement()

for _ in benchmark.scaledIterations {
blackHole(testValues.map { trie2.getValueAndParameters($0)})
blackHole(testValues.map { trie2.getValueAndParameters($0) })
}
} setup: {
let trieBuilder = RouterPathTrieBuilder<String>()
Expand Down
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Legal
By submitting a pull request, you represent that you have the right to license your contribution to the community, and agree by submitting the patch
that your contributions are licensed under the Apache 2.0 license (see [LICENSE](LICENSE.txt)).
that your contributions are licensed under the Apache 2.0 license (see [LICENSE](LICENSE)).

## Contributor Conduct
All contributors are expected to adhere to the project's [Code of Conduct](CODE_OF_CONDUCT.md).
Expand Down Expand Up @@ -30,4 +30,4 @@ The main development branch of the repository is `main`.

### Formatting

We use Nick Lockwood's SwiftFormat for formatting code. PRs will not be accepted if they haven't be formatted. The current version of SwiftFormat we are using is v0.48.17.
We use Nick Lockwood's SwiftFormat for formatting code. PRs will not be accepted if they haven't be formatted. The current version of SwiftFormat we are using is v0.51.15.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# ================================
# Build image
# ================================
FROM swift:5.7 as build
FROM swift:5.9 as build

WORKDIR /build

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public struct URLEncodedFormEncoder: Sendable {
/// - Parameters:
/// - value: Value to encode
/// - Returns: URL encoded form data
public func encode<T: Encodable>(_ value: T) throws -> String {
public func encode(_ value: some Encodable) throws -> String {
let encoder = _URLEncodedFormEncoder(options: options)
try value.encode(to: encoder)
guard let result = encoder.result else {
Expand Down Expand Up @@ -158,7 +158,7 @@ private class _URLEncodedFormEncoder: Encoder {
mutating func encode(_ value: UInt32, forKey key: Key) throws { self.encode(value, key: key.stringValue) }
mutating func encode(_ value: UInt64, forKey key: Key) throws { self.encode(value, key: key.stringValue) }

mutating func encode<T: Encodable>(_ value: T, forKey key: Key) throws {
mutating func encode(_ value: some Encodable, forKey key: Key) throws {
self.encoder.codingPath.append(key)
defer { self.encoder.codingPath.removeLast() }

Expand Down Expand Up @@ -238,7 +238,7 @@ private class _URLEncodedFormEncoder: Encoder {
mutating func encode(_ value: UInt32) throws { self.encodeResult(value) }
mutating func encode(_ value: UInt64) throws { self.encodeResult(value) }

mutating func encode<T: Encodable>(_ value: T) throws {
mutating func encode(_ value: some Encodable) throws {
self.count += 1

self.encoder.codingPath.append(URLEncodedForm.Key(index: self.count))
Expand Down Expand Up @@ -304,7 +304,7 @@ extension _URLEncodedFormEncoder: SingleValueEncodingContainer {
func encode(_ value: UInt32) throws { self.encodeResult(value) }
func encode(_ value: UInt64) throws { self.encodeResult(value) }

func encode<T: Encodable>(_ value: T) throws {
func encode(_ value: some Encodable) throws {
try value.encode(to: self)
}

Expand Down
4 changes: 2 additions & 2 deletions Sources/Hummingbird/HTTP/MediaType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ public struct HBMediaType: Sendable, CustomStringConvertible {
break
}
}
if let category = category,
let subCategory = subCategory
if let category,
let subCategory
{
self.type = category
self.subType = subCategory.lowercased()
Expand Down
2 changes: 1 addition & 1 deletion Sources/Hummingbird/Middleware/TracingMiddleware.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public struct HBTracingMiddleware<Context: HBBaseRequestContext>: HBMiddlewarePr
/// - Parameters
/// - recordingHeaders: A list of HTTP header names to be recorded as span attributes. By default, no headers
/// are being recorded.
/// - parameters: A list of static parameters added to every span. These could be the "net.host.name",
/// - parameters: A list of static parameters added to every span. These could be the "net.host.name",
/// "net.host.port" or "http.scheme"
public init(recordingHeaders headerNamesToRecord: some Collection<HTTPField.Name> = [], attributes: SpanAttributes? = nil) {
self.headerNamesToRecord = Set(headerNamesToRecord.map(RecordingHeader.init))
Expand Down
2 changes: 1 addition & 1 deletion Sources/Hummingbird/Router/TrieRouter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ struct RouterPathTrie<Value: Sendable>: Sendable {
}
}

extension HBParameters? {
extension Optional<HBParameters> {
fileprivate mutating func set(_ s: Substring, value: Substring) {
switch self {
case .some(var parameters):
Expand Down
2 changes: 1 addition & 1 deletion Sources/Hummingbird/Server/Request.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ private extension CodingKey {
}
}

private extension [CodingKey] {
private extension Array<CodingKey> {
/// returns a path key using a dot character as a separator
var pathKeyValue: String {
map(\.pathKeyValue).joined(separator: ".")
Expand Down
4 changes: 2 additions & 2 deletions Sources/Hummingbird/Storage/MemoryPersistDriver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ public actor HBMemoryPersistDriver<C: Clock>: HBPersistDriver where C.Duration =
self.clock = clock
}

public func create<Object: Codable & Sendable>(key: String, value: Object, expires: Duration?) async throws {
public func create(key: String, value: some Codable & Sendable, expires: Duration?) async throws {
guard self.values[key] == nil else { throw HBPersistError.duplicate }
self.values[key] = .init(value: value, expires: expires.map { self.clock.now.advanced(by: $0) })
}

public func set<Object: Codable & Sendable>(key: String, value: Object, expires: Duration?) async throws {
public func set(key: String, value: some Codable & Sendable, expires: Duration?) async throws {
self.values[key] = .init(value: value, expires: expires.map { self.clock.now.advanced(by: $0) })
}

Expand Down
Loading

0 comments on commit 65fd51f

Please sign in to comment.