Skip to content

Commit

Permalink
Migrate to common GitHub Actions
Browse files Browse the repository at this point in the history
Migrate CI to use swiftlang / SwiftNIO common GitHub Actions.

Motivation:

* Reduce duplication
* Centralise boilerplate changes when new Swift versions are picked up.
* Benefit from centralised work to add new linting / test
  infrastructure.

Modifications:

Changes of note:
* Use soundness checks from swiftlang/github-workflows.
* Retain bespoke license-checking code for .swift files as the gRPC
  header style is very different to most templates.
* Remove scripts which are no longer needed.
* Move scripts to `scripts/` directory in-line with most other Swift on
  Server repositories.

Result:

More test, linting, formatting coverage. More common CI with other Swift
on Server projects.
  • Loading branch information
rnro committed Nov 5, 2024
1 parent fec325b commit a7cfe35
Show file tree
Hide file tree
Showing 25 changed files with 290 additions and 215 deletions.
14 changes: 14 additions & 0 deletions .github/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
changelog:
categories:
- title: SemVer Major
labels:
- ⚠️ semver/major
- title: SemVer Minor
labels:
- semver/minor
- title: SemVer Patch
labels:
- semver/patch
- title: Other Changes
labels:
- semver/none
54 changes: 0 additions & 54 deletions .github/workflows/ci.yaml

This file was deleted.

28 changes: 28 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
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_enabled: false
linux_5_10_enabled: false
linux_6_0_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable"
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"

integration-tests:
name: Integration Tests
# Workaround https://github.com/nektos/act/issues/1875
uses: apple/swift-nio/.github/workflows/swift_matrix.yml@main
with:
name: "Integration tests"
matrix_linux_5_9_enabled: false
matrix_linux_5_10_enabled: false
matrix_linux_command: "./dev/integration_tests.sh"
53 changes: 53 additions & 0 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: PR

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

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

swift-license-check:
name: Swift License Header Check
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
persist-credentials: false
- name: Mark the workspace as safe
run: git config --global --add safe.directory ${GITHUB_WORKSPACE}
- name: Run license check
run: |
./dev/license-check.sh
unit-tests:
name: Unit Tests
uses: apple/swift-nio/.github/workflows/unit_tests.yml@main
with:
linux_5_9_enabled: false
linux_5_10_enabled: false
linux_6_0_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable"
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"

integration-tests:
name: Integration Tests
uses: apple/swift-nio/.github/workflows/swift_matrix.yml@main
with:
name: "Integration Tests"
matrix_linux_5_9_enabled: false
matrix_linux_5_10_enabled: false
matrix_linux_command: "./dev/integration_tests.sh"

cxx-interop:
name: Cxx Interop
uses: apple/swift-nio/.github/workflows/cxx_interop.yml@main
with:
linux_5_9_enabled: false
linux_5_10_enabled: false
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

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
13 changes: 13 additions & 0 deletions .license_header_template
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
@@ Copyright YEARS, gRPC Authors All rights reserved.
@@
@@ Licensed under the Apache License, Version 2.0 (the "License");
@@ you may not use this file except in compliance with the License.
@@ You may obtain a copy of the License at
@@
@@ http://www.apache.org/licenses/LICENSE-2.0
@@
@@ Unless required by applicable law or agreed to in writing, software
@@ distributed under the License is distributed on an "AS IS" BASIS,
@@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ See the License for the specific language governing permissions and
@@ limitations under the License.
41 changes: 41 additions & 0 deletions .licenseignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
.gitignore
**/.gitignore
.licenseignore
.gitattributes
.git-blame-ignore-revs
.mailfilter
.mailmap
.spi.yml
.swift-format
.editorconfig
.github/*
*.md
*.txt
*.yml
*.yaml
*.json
Package.swift
**/Package.swift
Package@-*.swift
**/Package@-*.swift
Package.resolved
**/Package.resolved
Makefile
*.modulemap
**/*.modulemap
**/*.docc/*
*.xcprivacy
**/*.xcprivacy
*.symlink
**/*.symlink
Dockerfile
**/Dockerfile
Snippets/*
dev/git.commit.template
dev/version-bump.commit.template
.unacceptablelanguageignore
IntegrationTests/grpc-performance-tests/Sources/Generated/*
LICENSE
**/*.swift
Sources/CGRPCZlib/*
dev/protos/**/*.proto
6 changes: 3 additions & 3 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ let dependencies: [Package.Dependency] = [
let defaultSwiftSettings: [SwiftSetting] = [
.swiftLanguageMode(.v6),
.enableUpcomingFeature("ExistentialAny"),
.enableUpcomingFeature("InternalImportsByDefault")
.enableUpcomingFeature("InternalImportsByDefault"),
]

let targets: [Target] = [
Expand All @@ -87,7 +87,7 @@ let targets: [Target] = [
.product(name: "NIOCore", package: "swift-nio"),
.product(name: "NIOHTTP2", package: "swift-nio-http2"),
.product(name: "NIOExtras", package: "swift-nio-extras"),
.target(name: "CGRPCZlib")
.target(name: "CGRPCZlib"),
],
swiftSettings: defaultSwiftSettings
),
Expand Down Expand Up @@ -140,7 +140,7 @@ let targets: [Target] = [
.product(name: "X509", package: "swift-certificates"),
.product(name: "NIOSSL", package: "swift-nio-ssl"),
]
)
),
]

let package = Package(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ package enum ClientConnectionEvent: Sendable {
/// 2. Closing the connection if it is idle (has no open streams) for a configured amount of time.
/// 3. Forwarding lifecycle events to the next handler.
///
/// Some of the behaviours are described in [gRFC A8](https://github.com/grpc/proposal/blob/master/A8-client-side-keepalive.md).
/// Some of the behaviours are described in [gRFC A8](https://github.com/grpc/proposal/blob/0e1807a6e30a1a915c0dcadc873bca92b9fa9720/A8-client-side-keepalive.md).
package final class ClientConnectionHandler: ChannelInboundHandler, ChannelOutboundHandler {
package typealias InboundIn = HTTP2Frame
package typealias InboundOut = ClientConnectionEvent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ extension RoundRobinLoadBalancer {
mutating func updateState(_ newState: ConnectivityState) -> Bool {
// The transition from transient failure to connecting is ignored.
//
// See: https://github.com/grpc/grpc/blob/master/doc/load-balancing.md
// See: https://github.com/grpc/grpc/blob/7f664c69b2a636386fbf95c16bc78c559734ce0f/doc/load-balancing.md
if case .transientFailure = self.state, newState == .connecting {
return false
}
Expand Down Expand Up @@ -733,7 +733,7 @@ extension RoundRobinLoadBalancer {

extension ConnectivityState {
static func aggregate(_ states: some Collection<ConnectivityState>) -> ConnectivityState {
// See https://github.com/grpc/grpc/blob/master/doc/load-balancing.md
// See https://github.com/grpc/grpc/blob/7f664c69b2a636386fbf95c16bc78c559734ce0f/doc/load-balancing.md

// If any one subchannel is in READY state, the channel's state is READY.
if states.contains(where: { $0 == .ready }) {
Expand Down
6 changes: 3 additions & 3 deletions Sources/GRPCNIOTransportCore/GRPCStreamStateMachine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ extension GRPCStreamStateMachine {
headers.reserveCapacity(7 + customMetadata.count)

// Add required headers.
// See https://github.com/grpc/grpc/blob/master/doc/PROTOCOL-HTTP2.md#requests
// See https://github.com/grpc/grpc/blob/7f664c69b2a636386fbf95c16bc78c559734ce0f/doc/PROTOCOL-HTTP2.md#requests

// The order is important here: reserved HTTP2 headers (those starting with `:`)
// must come before all other headers.
Expand Down Expand Up @@ -851,7 +851,7 @@ extension GRPCStreamStateMachine {
if (100 ... 199).contains(httpStatusCode.code) {
// For 1xx status codes, the entire header should be skipped and a
// subsequent header should be read.
// See https://github.com/grpc/grpc/blob/master/doc/http-grpc-status-mapping.md
// See https://github.com/grpc/grpc/blob/7f664c69b2a636386fbf95c16bc78c559734ce0f/doc/http-grpc-status-mapping.md
return .invalid(.doNothing)
}

Expand Down Expand Up @@ -1868,7 +1868,7 @@ extension Metadata {
}

extension Status.Code {
// See https://github.com/grpc/grpc/blob/master/doc/http-grpc-status-mapping.md
// See https://github.com/grpc/grpc/blob/7f664c69b2a636386fbf95c16bc78c559734ce0f/doc/http-grpc-status-mapping.md
init(httpStatusCode: HTTPResponseStatus) {
switch httpStatusCode {
case .badRequest:
Expand Down
2 changes: 1 addition & 1 deletion Sources/GRPCNIOTransportCore/Internal/ContentType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

// See:
// - https://github.com/grpc/grpc/blob/master/doc/PROTOCOL-HTTP2.md
// - https://github.com/grpc/grpc/blob/7f664c69b2a636386fbf95c16bc78c559734ce0f/doc/PROTOCOL-HTTP2.md
enum ContentType {
case grpc

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ extension GRPCStatusMessageMarshaller {

for char in message.utf8 {
switch char {
// See: https://github.com/grpc/grpc/blob/master/doc/PROTOCOL-HTTP2.md#responses
// See: https://github.com/grpc/grpc/blob/7f664c69b2a636386fbf95c16bc78c559734ce0f/doc/PROTOCOL-HTTP2.md#responses
case 0x20 ... 0x24,
0x26 ... 0x7E:
bytes.append(char)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ package final class CommonHTTP2ServerTransport<
// - If we get an error because the http2Stream failed to close, then there's nothing we can do
// - If we get an error because the inner closure threw, then the only possible scenario in which
// that could happen is if methodDescriptor.get() throws - in which case, it means we never got
// the RPC metadata, which means we can't do anything either and it's okay to just kill the stream.
// the RPC metadata, which means we can't do anything either and it's okay to just close the stream.
try? await stream.executeThenClose { inbound, outbound in
guard let descriptor = try? await descriptor.get() else {
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ extension ServerConnectionManagementHandler.StateMachine {
// If there are no open streams and keep alive pings aren't allowed without calls then
// use an interval of two hours.
//
// This comes from gRFC A8: https://github.com/grpc/proposal/blob/master/A8-client-side-keepalive.md
// This comes from gRFC A8: https://github.com/grpc/proposal/blob/0e1807a6e30a1a915c0dcadc873bca92b9fa9720/A8-client-side-keepalive.md
interval = .hours(2)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ private import NIOTLS
/// too many pings.
///
/// Some of the behaviours are described in:
/// - [gRFC A8](https://github.com/grpc/proposal/blob/master/A8-client-side-keepalive.md), and
/// - [gRFC A9](https://github.com/grpc/proposal/blob/master/A9-server-side-conn-mgt.md).
/// - [gRFC A8](https://github.com/grpc/proposal/blob/0e1807a6e30a1a915c0dcadc873bca92b9fa9720/A8-client-side-keepalive.md), and
/// - [gRFC A9](https://github.com/grpc/proposal/blob/0e1807a6e30a1a915c0dcadc873bca92b9fa9720/A9-server-side-conn-mgt.md).
package final class ServerConnectionManagementHandler: ChannelDuplexHandler {
package typealias InboundIn = HTTP2Frame
package typealias InboundOut = HTTP2Frame
Expand Down
2 changes: 1 addition & 1 deletion Tests/GRPCNIOTransportHTTP2Tests/HTTP2TransportTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1274,7 +1274,7 @@ final class HTTP2TransportTests: XCTestCase {
}

private static let httpToStatusCodePairs: [(Int, RPCError.Code)] = [
// See https://github.com/grpc/grpc/blob/master/doc/http-grpc-status-mapping.md
// See https://github.com/grpc/grpc/blob/7f664c69b2a636386fbf95c16bc78c559734ce0f/doc/http-grpc-status-mapping.md
(400, .internalError),
(401, .unauthenticated),
(403, .permissionDenied),
Expand Down
27 changes: 13 additions & 14 deletions dev/build-performance-tests.sh
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
#!/bin/bash

# Copyright 2024, gRPC Authors All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
## Copyright 2024, gRPC Authors All rights reserved.
##
## Licensed under the Apache License, Version 2.0 (the "License");
## you may not use this file except in compliance with the License.
## You may obtain a copy of the License at
##
## http://www.apache.org/licenses/LICENSE-2.0
##
## Unless required by applicable law or agreed to in writing, software
## distributed under the License is distributed on an "AS IS" BASIS,
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
## See the License for the specific language governing permissions and
## limitations under the License.

set -euo pipefail

Expand Down
Loading

0 comments on commit a7cfe35

Please sign in to comment.