Skip to content

Commit

Permalink
[CI] Migrate to GitHub Actions (apple#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
czechboy0 authored Nov 8, 2024
1 parent cad7a22 commit 94a6b2c
Show file tree
Hide file tree
Showing 39 changed files with 1,344 additions and 1,383 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Main

on:
push:
branches: [main]
schedule:
- cron: "0 8,20 * * *"

jobs:
unit-tests:
name: Unit tests
uses: apple/swift-nio/.github/workflows/unit_tests.yml@main
with:
linux_5_9_arguments_override: "--explicit-target-dependency-import-check error"
linux_5_10_arguments_override: "--explicit-target-dependency-import-check error"
linux_6_0_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable -Xswiftc -warnings-as-errors"
linux_nightly_6_0_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable"
linux_nightly_main_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable"
26 changes: 26 additions & 0 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: PR

on:
pull_request:
types: [opened, reopened, synchronize]

jobs:
soundness:
name: Soundness
uses: swiftlang/github-workflows/.github/workflows/soundness.yml@main
with:
license_header_check_project_name: "SwiftServiceDiscovery"

unit-tests:
name: Unit tests
uses: apple/swift-nio/.github/workflows/unit_tests.yml@main
with:
linux_5_9_arguments_override: "--explicit-target-dependency-import-check error"
linux_5_10_arguments_override: "--explicit-target-dependency-import-check error"
linux_6_0_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable -Xswiftc -warnings-as-errors"
linux_nightly_6_0_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable"
linux_nightly_main_enabled: false

cxx-interop:
name: Cxx interop
uses: apple/swift-nio/.github/workflows/cxx_interop.yml@main
18 changes: 18 additions & 0 deletions .github/workflows/pull_request_label.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: PR label

on:
pull_request:
types: [labeled, unlabeled, opened, reopened, synchronize]

jobs:
semver-label-check:
name: Semantic Version label check
runs-on: ubuntu-latest
timeout-minutes: 1
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
persist-credentials: false
- name: Check for Semantic Version label
uses: apple/swift-nio/.github/actions/pull_request_semver_label_checker@main
9 changes: 9 additions & 0 deletions .licenseignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.gitignore
.licenseignore
.swiftformatignore
.spi.yml
.swift-format
.github/
**.md
**.txt
**Package.swift
61 changes: 61 additions & 0 deletions .swift-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{
"fileScopedDeclarationPrivacy" : {
"accessLevel" : "private"
},
"indentation" : {
"spaces" : 4
},
"indentConditionalCompilationBlocks" : false,
"indentSwitchCaseLabels" : false,
"lineBreakAroundMultilineExpressionChainComponents" : true,
"lineBreakBeforeControlFlowKeywords" : false,
"lineBreakBeforeEachArgument" : true,
"lineBreakBeforeEachGenericRequirement" : true,
"lineLength" : 120,
"maximumBlankLines" : 1,
"prioritizeKeepingFunctionOutputTogether" : false,
"respectsExistingLineBreaks" : false,
"rules" : {
"AllPublicDeclarationsHaveDocumentation" : true,
"AlwaysUseLowerCamelCase" : false,
"AlwaysUseLiteralForEmptyCollectionInit" : true,
"AmbiguousTrailingClosureOverload" : true,
"BeginDocumentationCommentWithOneLineSummary" : false,
"DoNotUseSemicolons" : true,
"DontRepeatTypeInStaticProperties" : false,
"FileScopedDeclarationPrivacy" : true,
"FullyIndirectEnum" : true,
"GroupNumericLiterals" : true,
"IdentifiersMustBeASCII" : true,
"NeverForceUnwrap" : false,
"NeverUseForceTry" : false,
"NeverUseImplicitlyUnwrappedOptionals" : false,
"NoAccessLevelOnExtensionDeclaration" : false,
"NoAssignmentInExpressions" : true,
"NoBlockComments" : true,
"NoCasesWithOnlyFallthrough" : true,
"NoEmptyTrailingClosureParentheses" : true,
"NoLabelsInCasePatterns" : false,
"NoLeadingUnderscores" : false,
"NoParensAroundConditions" : true,
"NoVoidReturnOnFunctionSignature" : true,
"OmitExplicitReturns" : true,
"OneCasePerLine" : true,
"OneVariableDeclarationPerLine" : true,
"OnlyOneTrailingClosureArgument" : true,
"OrderedImports" : false,
"ReplaceForEachWithForLoop" : true,
"ReturnVoidInsteadOfEmptyTuple" : true,
"UseEarlyExits" : false,
"UseLetInEveryBoundCaseVariable" : false,
"UseShorthandTypeNames" : true,
"UseSingleLinePropertyGetter" : false,
"UseSynthesizedInitializer" : true,
"UseTripleSlashForDocumentationComments" : true,
"UseWhereClausesInForLoops" : false,
"ValidateDocumentationComments" : true
},
"spacesAroundRangeFormationOperators" : false,
"tabWidth" : 8,
"version" : 1
}
20 changes: 0 additions & 20 deletions .swiftformat

This file was deleted.

36 changes: 32 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,45 @@ A good SwiftServiceDiscovery patch is:
3. Documented, adding API documentation as needed to cover new functions and properties.
4. Accompanied by a great commit message, using our commit message template.

### Commit Message Template
### Run CI checks locally

We require that your commit messages match our template. The easiest way to do that is to get git to help you by explicitly using the template. To do that, `cd` to the root of our repository and run:
You can run the Github Actions workflows locally using
[act](https://github.com/nektos/act). To run all the jobs that run on a pull
request, use the following command:

git config commit.template dev/git.commit.template
```
% act pull_request
```

To run just a single job, use `workflow_call -j <job>`, and specify the inputs
the job expects. For example, to run just shellcheck:

```
% act workflow_call -j soundness --input shell_check_enabled=true
```

To bind-mount the working directory to the container, rather than a copy, use
`--bind`. For example, to run just the formatting, and have the results
reflected in your working directory:

```
% act --bind workflow_call -j soundness --input format_check_enabled=true
```

If you'd like `act` to always run with certain flags, these can be be placed in
an `.actrc` file either in the current working directory or your home
directory, for example:

```
--container-architecture=linux/amd64
--remote-name upstream
--action-offline-mode
```

### Make sure Tests work on Linux

SwiftServiceDiscovery uses XCTest to run tests on both macOS and Linux.


## How to contribute your work

Please open a pull request at https://github.com/apple/swift-service-discovery. Make sure the CI passes, and then wait for code review.
19 changes: 0 additions & 19 deletions CONTRIBUTORS.txt

This file was deleted.

17 changes: 8 additions & 9 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.6
// swift-tools-version:5.9

//===----------------------------------------------------------------------===//
//
Expand All @@ -18,19 +18,18 @@ import PackageDescription

let package = Package(
name: "swift-service-discovery",
products: [
.library(name: "ServiceDiscovery", targets: ["ServiceDiscovery"]),
],
products: [.library(name: "ServiceDiscovery", targets: ["ServiceDiscovery"])],
dependencies: [
.package(url: "https://github.com/apple/swift-atomics", from: "1.0.2"),
.package(url: "https://github.com/apple/swift-log", from: "1.2.0"),
.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0"),
],
targets: [
.target(name: "ServiceDiscovery", dependencies: [
.product(name: "Atomics", package: "swift-atomics"),
.product(name: "Logging", package: "swift-log"),
]),
.target(
name: "ServiceDiscovery",
dependencies: [
.product(name: "Atomics", package: "swift-atomics"), .product(name: "Logging", package: "swift-log"),
]
),

.testTarget(name: "ServiceDiscoveryTests", dependencies: ["ServiceDiscovery"]),
]
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ let serviceDiscovery = InMemoryServiceDiscovery(configuration: configuration)
To add a dependency on the API package, you need to declare it in your `Package.swift`:

```swift
.package(url: "https://github.com/apple/swift-service-discovery.git", from: "0.1.0"),
.package(url: "https://github.com/apple/swift-service-discovery.git", from: "1.3.0"),
```

and to your library target, add "ServiceDiscovery" to your dependencies:
Expand Down
59 changes: 44 additions & 15 deletions Sources/ServiceDiscovery/FilterInstanceServiceDiscovery.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import Dispatch

/// A service discovery implementation that filters instances using a predicate.
public final class FilterInstanceServiceDiscovery<BaseDiscovery: ServiceDiscovery> {
typealias Predicate = (BaseDiscovery.Instance) throws -> Bool

Expand All @@ -28,32 +29,60 @@ public final class FilterInstanceServiceDiscovery<BaseDiscovery: ServiceDiscover

extension FilterInstanceServiceDiscovery: ServiceDiscovery {
/// Default timeout for lookup.
public var defaultLookupTimeout: DispatchTimeInterval {
self.originalSD.defaultLookupTimeout
}
public var defaultLookupTimeout: DispatchTimeInterval { self.originalSD.defaultLookupTimeout }

public func lookup(_ service: BaseDiscovery.Service, deadline: DispatchTime?, callback: @escaping (Result<[BaseDiscovery.Instance], Error>) -> Void) {
self.originalSD.lookup(service, deadline: deadline) { result in callback(self.transform(result)) }
}
/// Performs a lookup for the given service's instances. The result will be sent to `callback`.
///
/// ``defaultLookupTimeout`` will be used to compute `deadline` in case one is not specified.
///
/// ### Threading
///
/// `callback` may be invoked on arbitrary threads, as determined by implementation.
///
/// - Parameters:
/// - service: The service to lookup
/// - deadline: Lookup is considered to have timed out if it does not complete by this time
/// - callback: The closure to receive lookup result
public func lookup(
_ service: BaseDiscovery.Service,
deadline: DispatchTime?,
callback: @escaping (Result<[BaseDiscovery.Instance], Error>) -> Void
) { self.originalSD.lookup(service, deadline: deadline) { result in callback(self.transform(result)) } }

public func subscribe(to service: BaseDiscovery.Service, onNext nextResultHandler: @escaping (Result<[BaseDiscovery.Instance], Error>) -> Void, onComplete completionHandler: @escaping (CompletionReason) -> Void) -> CancellationToken {
/// Subscribes to receive a service's instances whenever they change.
///
/// The service's current list of instances will be sent to `nextResultHandler` when this method is first called. Subsequently,
/// `nextResultHandler` will only be invoked when the `service`'s instances change.
///
/// ### Threading
///
/// `nextResultHandler` and `completionHandler` may be invoked on arbitrary threads, as determined by implementation.
///
/// - Parameters:
/// - service: The service to subscribe to
/// - nextResultHandler: The closure to receive update result
/// - completionHandler: The closure to invoke when the subscription completes (e.g., when the `ServiceDiscovery` instance exits, etc.),
/// including cancellation requested through `CancellationToken`.
///
/// - Returns: A ``CancellationToken`` instance that can be used to cancel the subscription in the future.
public func subscribe(
to service: BaseDiscovery.Service,
onNext nextResultHandler: @escaping (Result<[BaseDiscovery.Instance], Error>) -> Void,
onComplete completionHandler: @escaping (CompletionReason) -> Void
) -> CancellationToken {
self.originalSD.subscribe(
to: service,
onNext: { result in nextResultHandler(self.transform(result)) },
onComplete: completionHandler
)
}

private func transform(_ result: Result<[BaseDiscovery.Instance], Error>) -> Result<[BaseDiscovery.Instance], Error> {
private func transform(_ result: Result<[BaseDiscovery.Instance], Error>) -> Result<[BaseDiscovery.Instance], Error>
{
switch result {
case .success(let instances):
do {
return try .success(instances.filter(self.predicate))
} catch {
return .failure(error)
}
case .failure(let error):
return .failure(error)
do { return try .success(instances.filter(self.predicate)) } catch { return .failure(error) }
case .failure(let error): return .failure(error)
}
}
}
4 changes: 1 addition & 3 deletions Sources/ServiceDiscovery/HostPort.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,5 @@ public struct HostPort: Hashable, CustomStringConvertible {
self.port = port
}

public var description: String {
"\(self.host):\(self.port)"
}
public var description: String { "\(self.host):\(self.port)" }
}
Loading

0 comments on commit 94a6b2c

Please sign in to comment.