Parcourir la source

Add check that generated code is up-to-date (#2013)

Motivation:

It's easy for checked in generated code to not be up-to-date.

Modifications:

- Add a script to check it's up-to-date and run it in CI

Result:

More guarantess that checked in code is up-to-date
George Barnett il y a 1 an
Parent
commit
7738bcfda1
3 fichiers modifiés avec 43 ajouts et 71 suppressions
  1. 19 19
      Tests/GRPCHTTP2TransportTests/Generated/control.grpc.swift
  2. 16 49
      scripts/format.sh
  3. 8 3
      scripts/sanity.sh

+ 19 - 19
Tests/GRPCHTTP2TransportTests/Generated/control.grpc.swift

@@ -91,11 +91,11 @@ extension ServiceDescriptor {
 @available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
 internal protocol ControlStreamingServiceProtocol: GRPCCore.RegistrableRPCService {
     func unary(request: ServerRequest.Stream<ControlInput>) async throws -> ServerResponse.Stream<ControlOutput>
-
+    
     func serverStream(request: ServerRequest.Stream<ControlInput>) async throws -> ServerResponse.Stream<ControlOutput>
-
+    
     func clientStream(request: ServerRequest.Stream<ControlInput>) async throws -> ServerResponse.Stream<ControlOutput>
-
+    
     func bidiStream(request: ServerRequest.Stream<ControlInput>) async throws -> ServerResponse.Stream<ControlOutput>
 }
 
@@ -146,11 +146,11 @@ extension Control.StreamingServiceProtocol {
 @available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
 internal protocol ControlServiceProtocol: Control.StreamingServiceProtocol {
     func unary(request: ServerRequest.Single<ControlInput>) async throws -> ServerResponse.Single<ControlOutput>
-
+    
     func serverStream(request: ServerRequest.Single<ControlInput>) async throws -> ServerResponse.Stream<ControlOutput>
-
+    
     func clientStream(request: ServerRequest.Stream<ControlInput>) async throws -> ServerResponse.Single<ControlOutput>
-
+    
     func bidiStream(request: ServerRequest.Stream<ControlInput>) async throws -> ServerResponse.Stream<ControlOutput>
 }
 
@@ -161,12 +161,12 @@ extension Control.ServiceProtocol {
         let response = try await self.unary(request: ServerRequest.Single(stream: request))
         return ServerResponse.Stream(single: response)
     }
-
+    
     internal func serverStream(request: ServerRequest.Stream<ControlInput>) async throws -> ServerResponse.Stream<ControlOutput> {
         let response = try await self.serverStream(request: ServerRequest.Single(stream: request))
         return response
     }
-
+    
     internal func clientStream(request: ServerRequest.Stream<ControlInput>) async throws -> ServerResponse.Stream<ControlOutput> {
         let response = try await self.clientStream(request: request)
         return ServerResponse.Stream(single: response)
@@ -186,7 +186,7 @@ internal protocol ControlClientProtocol: Sendable {
         options: CallOptions,
         _ body: @Sendable @escaping (ClientResponse.Single<ControlOutput>) async throws -> R
     ) async throws -> R where R: Sendable
-
+    
     func serverStream<R>(
         request: ClientRequest.Single<ControlInput>,
         serializer: some MessageSerializer<ControlInput>,
@@ -194,7 +194,7 @@ internal protocol ControlClientProtocol: Sendable {
         options: CallOptions,
         _ body: @Sendable @escaping (ClientResponse.Stream<ControlOutput>) async throws -> R
     ) async throws -> R where R: Sendable
-
+    
     func clientStream<R>(
         request: ClientRequest.Stream<ControlInput>,
         serializer: some MessageSerializer<ControlInput>,
@@ -202,7 +202,7 @@ internal protocol ControlClientProtocol: Sendable {
         options: CallOptions,
         _ body: @Sendable @escaping (ClientResponse.Single<ControlOutput>) async throws -> R
     ) async throws -> R where R: Sendable
-
+    
     func bidiStream<R>(
         request: ClientRequest.Stream<ControlInput>,
         serializer: some MessageSerializer<ControlInput>,
@@ -227,7 +227,7 @@ extension Control.ClientProtocol {
             body
         )
     }
-
+    
     internal func serverStream<R>(
         request: ClientRequest.Single<ControlInput>,
         options: CallOptions = .defaults,
@@ -241,7 +241,7 @@ extension Control.ClientProtocol {
             body
         )
     }
-
+    
     internal func clientStream<R>(
         request: ClientRequest.Stream<ControlInput>,
         options: CallOptions = .defaults,
@@ -255,7 +255,7 @@ extension Control.ClientProtocol {
             body
         )
     }
-
+    
     internal func bidiStream<R>(
         request: ClientRequest.Stream<ControlInput>,
         options: CallOptions = .defaults,
@@ -278,11 +278,11 @@ extension Control.ClientProtocol {
 @available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
 internal struct ControlClient: Control.ClientProtocol {
     private let client: GRPCCore.GRPCClient
-
+    
     internal init(wrapping client: GRPCCore.GRPCClient) {
         self.client = client
     }
-
+    
     internal func unary<R>(
         request: ClientRequest.Single<ControlInput>,
         serializer: some MessageSerializer<ControlInput>,
@@ -299,7 +299,7 @@ internal struct ControlClient: Control.ClientProtocol {
             handler: body
         )
     }
-
+    
     internal func serverStream<R>(
         request: ClientRequest.Single<ControlInput>,
         serializer: some MessageSerializer<ControlInput>,
@@ -316,7 +316,7 @@ internal struct ControlClient: Control.ClientProtocol {
             handler: body
         )
     }
-
+    
     internal func clientStream<R>(
         request: ClientRequest.Stream<ControlInput>,
         serializer: some MessageSerializer<ControlInput>,
@@ -333,7 +333,7 @@ internal struct ControlClient: Control.ClientProtocol {
             handler: body
         )
     }
-
+    
     internal func bidiStream<R>(
         request: ClientRequest.Stream<ControlInput>,
         serializer: some MessageSerializer<ControlInput>,

+ 16 - 49
scripts/format.sh

@@ -52,53 +52,20 @@ while getopts ":flh" opt; do
   esac
 done
 
-THIS_SCRIPT=$0
-HERE="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
-REPO="$HERE/.."
-SWIFTFORMAT_DIR="$HERE/.swift-format-source"
-SWIFTFORMAT_VERSION=510.0.0
-
-# Clone SwiftFormat if we don't already have it.
-if [ ! -d "$SWIFTFORMAT_DIR" ]; then
-  echo "- Cloning swift-format @ $SWIFTFORMAT_VERSION"
-  git clone \
-    --depth 1 \
-    --branch "$SWIFTFORMAT_VERSION" \
-    https://github.com/apple/swift-format.git \
-    "$SWIFTFORMAT_DIR"
-fi
-
-cd "$SWIFTFORMAT_DIR"
-
-# Figure out the path for the binary.
-SWIFTFORMAT_BIN="$(swift build --show-bin-path -c release)/swift-format-$SWIFTFORMAT_VERSION"
-
-# Build it if we don't already have it.
-if [ ! -f "$SWIFTFORMAT_BIN" ]; then
-  # We're not on the right tag, fetch and checkout the right one.
-  echo "- Fetching swift-format @ $SWIFTFORMAT_VERSION"
-  git fetch --depth 1 origin "refs/tags/$SWIFTFORMAT_VERSION:refs/tags/$SWIFTFORMAT_VERSION"
-  git checkout "$SWIFTFORMAT_VERSION"
-
-  # Now build and name the bin appropriately.
-  echo "- Building swift-format @ $SWIFTFORMAT_VERSION"
-  swift build -c release --product swift-format
-  mv "$(swift build --show-bin-path -c release)/swift-format" "$SWIFTFORMAT_BIN"
-
-  echo "- OK"
-fi
+here="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
+repo="$here/.."
 
 if "$lint"; then
-  "${SWIFTFORMAT_BIN}" lint \
+  swift format lint \
     --parallel --recursive --strict \
-    "${REPO}/Sources" \
-    "${REPO}/Tests" \
-    "${REPO}/Plugins" \
-    "${REPO}/Performance/Benchmarks/Benchmarks/GRPCSwiftBenchmark" \
+    "${repo}/Sources" \
+    "${repo}/Tests" \
+    "${repo}/Plugins" \
+    "${repo}/Performance/Benchmarks/Benchmarks/GRPCSwiftBenchmark" \
     && SWIFT_FORMAT_RC=$? || SWIFT_FORMAT_RC=$?
 
   if [[ "${SWIFT_FORMAT_RC}" -ne 0 ]]; then
-    fatal "Running swift-format produced errors.
+    fatal "Running swift format produced errors.
 
     To fix, run the following command:
 
@@ -107,21 +74,21 @@ if "$lint"; then
     exit "${SWIFT_FORMAT_RC}"
   fi
 
-  log "Ran swift-format lint with no errors."
+  log "Ran swift format lint with no errors."
 elif "$format"; then
-  "${SWIFTFORMAT_BIN}" format \
+  swift format \
     --parallel --recursive --in-place \
-    "${REPO}/Sources" \
-    "${REPO}/Tests" \
-    "${REPO}/Plugins" \
-    "${REPO}/Performance/Benchmarks/Benchmarks/GRPCSwiftBenchmark" \
+    "${repo}/Sources" \
+    "${repo}/Tests" \
+    "${repo}/Plugins" \
+    "${repo}/Performance/Benchmarks/Benchmarks/GRPCSwiftBenchmark" \
     && SWIFT_FORMAT_RC=$? || SWIFT_FORMAT_RC=$?
 
   if [[ "${SWIFT_FORMAT_RC}" -ne 0 ]]; then
-    fatal "Running swift-format produced errors." "${SWIFT_FORMAT_RC}"
+    fatal "Running swift format produced errors." "${SWIFT_FORMAT_RC}"
   fi
 
-  log "Ran swift-format with no errors."
+  log "Ran swift format with no errors."
 else
   fatal "No actions taken."
 fi

+ 8 - 3
scripts/sanity.sh

@@ -16,7 +16,7 @@
 
 set -eu
 
-HERE="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
+here="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
 
 function run_logged() {
   local message=$1
@@ -38,14 +38,19 @@ function run_logged() {
 }
 
 function check_license_headers() {
-  run_logged "Checking license headers" "$HERE/license-check.sh"
+  run_logged "Checking license headers" "$here/license-check.sh"
 }
 
 function check_formatting() {
-  run_logged "Checking formatting" "$HERE/format.sh -l"
+  run_logged "Checking formatting" "$here/format.sh -l"
+}
+
+function check_generated_code_is_up_to_date() {
+  run_logged "Checking generated code is up-to-date" "$here/check-generated-code.sh"
 }
 
 errors=0
 check_license_headers
 check_formatting
+check_generated_code_is_up_to_date
 exit $errors