Browse 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 1 year ago
parent
commit
1230ee05c6
2 changed files with 24 additions and 52 deletions
  1. 16 49
      scripts/format.sh
  2. 8 3
      scripts/sanity.sh

+ 16 - 49
scripts/format.sh

@@ -52,53 +52,20 @@ while getopts ":flh" opt; do
   esac
   esac
 done
 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
 if "$lint"; then
-  "${SWIFTFORMAT_BIN}" lint \
+  swift format lint \
     --parallel --recursive --strict \
     --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=$?
     && SWIFT_FORMAT_RC=$? || SWIFT_FORMAT_RC=$?
 
 
   if [[ "${SWIFT_FORMAT_RC}" -ne 0 ]]; then
   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:
     To fix, run the following command:
 
 
@@ -107,21 +74,21 @@ if "$lint"; then
     exit "${SWIFT_FORMAT_RC}"
     exit "${SWIFT_FORMAT_RC}"
   fi
   fi
 
 
-  log "Ran swift-format lint with no errors."
+  log "Ran swift format lint with no errors."
 elif "$format"; then
 elif "$format"; then
-  "${SWIFTFORMAT_BIN}" format \
+  swift format \
     --parallel --recursive --in-place \
     --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=$?
     && SWIFT_FORMAT_RC=$? || SWIFT_FORMAT_RC=$?
 
 
   if [[ "${SWIFT_FORMAT_RC}" -ne 0 ]]; then
   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
   fi
 
 
-  log "Ran swift-format with no errors."
+  log "Ran swift format with no errors."
 else
 else
   fatal "No actions taken."
   fatal "No actions taken."
 fi
 fi

+ 8 - 3
scripts/sanity.sh

@@ -16,7 +16,7 @@
 
 
 set -eu
 set -eu
 
 
-HERE="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
+here="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
 
 
 function run_logged() {
 function run_logged() {
   local message=$1
   local message=$1
@@ -38,14 +38,19 @@ function run_logged() {
 }
 }
 
 
 function check_license_headers() {
 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() {
 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
 errors=0
 check_license_headers
 check_license_headers
 check_formatting
 check_formatting
+check_generated_code_is_up_to_date
 exit $errors
 exit $errors