From 37255b7d12e7de407e8d38dd6456f4f144d44e6e Mon Sep 17 00:00:00 2001 From: Si Beaumont Date: Fri, 9 Jun 2023 10:34:47 +0100 Subject: [PATCH] Build IntegrationTest package as part of CI pipeline (#56) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ### Motivation We have an package in a subdirectory in this repo that we can be used as an integration test to gate changes to the various repos in Swift OpenAPI project, including the runtime package. This will likely be implemented by shallow cloning this repo in the pull request pipelines of other projects and running a script, using `swift package edit` to override the dependency on the package being tested, and building the integration test package. ### Modifications - Simplify the integration test package location and name. - Add a CI script that runs the integration test with a package override. - Run this script as part of the soundness pipeline. ### Result On each pull request, the integration test package will be built with the changes proposed in the pull request. ### Test Plan The CI pipeline for this PR will run the integration test because it's been added to the soundness script, which is run as part of an existing CI pipeline. I have also validated this locally: ```console ❯ docker-compose -f docker/docker-compose.yaml run --build soundness ... ** Running /code/scripts/check-for-broken-symlinks.sh... ** Checking for broken symlinks... ** ✅ Found 0 symlinks. ** Running /code/scripts/check-for-unacceptable-language.sh... ** Checking for unacceptable language... ** ✅ Found no unacceptable language. ** Running /code/scripts/check-license-headers.sh... ** ✅ Found no files with missing license header. ** Running /code/scripts/run-swift-format.sh... ** ✅ Ran swift-format with no errors. ** Running /code/scripts/check-for-docc-warnings.sh... ... ** ✅ Generated documentation with no warnings. ** Running /code/scripts/run-integration-test.sh... ** Checking required executables... ... Build complete! (42.53s) ** ✅ Successfully built integration test package. ** ✅ All soundness check(s) passed. ``` ### Notes This PR adds the integration test to the soundness script, but we probably want to split this out into its own pipeline. --------- Signed-off-by: Si Beaumont --- .../Simple => IntegrationTest}/.gitignore | 0 .../Simple => IntegrationTest}/Package.swift | 2 +- .../Simple => IntegrationTest}/README.md | 0 .../Sources/Client/Empty.swift | 0 .../Client/openapi-generator-config.yaml | 0 .../Sources/Client/openapi.yaml | 0 .../Sources/MockTransportClient/Client.swift | 0 .../Sources/MockTransportServer/Server.swift | 0 .../Sources/Server/Empty.swift | 0 .../Server/openapi-generator-config.yaml | 0 .../Sources/Server/openapi.yaml | 0 .../Sources/Types/Empty.swift | 0 .../Types/openapi-generator-config.yaml | 0 .../Sources/Types/openapi.yaml | 0 .../Sources/openapi.yaml | 0 docker/Dockerfile | 5 +- docker/docker-compose.yaml | 2 + scripts/run-integration-test.sh | 48 +++++++++++++++++++ scripts/run-swift-format.sh | 2 +- scripts/soundness.sh | 1 + 20 files changed, 57 insertions(+), 3 deletions(-) rename {IntegrationTests/Simple => IntegrationTest}/.gitignore (100%) rename {IntegrationTests/Simple => IntegrationTest}/Package.swift (98%) rename {IntegrationTests/Simple => IntegrationTest}/README.md (100%) rename {IntegrationTests/Simple => IntegrationTest}/Sources/Client/Empty.swift (100%) rename {IntegrationTests/Simple => IntegrationTest}/Sources/Client/openapi-generator-config.yaml (100%) rename {IntegrationTests/Simple => IntegrationTest}/Sources/Client/openapi.yaml (100%) rename {IntegrationTests/Simple => IntegrationTest}/Sources/MockTransportClient/Client.swift (100%) rename {IntegrationTests/Simple => IntegrationTest}/Sources/MockTransportServer/Server.swift (100%) rename {IntegrationTests/Simple => IntegrationTest}/Sources/Server/Empty.swift (100%) rename {IntegrationTests/Simple => IntegrationTest}/Sources/Server/openapi-generator-config.yaml (100%) rename {IntegrationTests/Simple => IntegrationTest}/Sources/Server/openapi.yaml (100%) rename {IntegrationTests/Simple => IntegrationTest}/Sources/Types/Empty.swift (100%) rename {IntegrationTests/Simple => IntegrationTest}/Sources/Types/openapi-generator-config.yaml (100%) rename {IntegrationTests/Simple => IntegrationTest}/Sources/Types/openapi.yaml (100%) rename {IntegrationTests/Simple => IntegrationTest}/Sources/openapi.yaml (100%) create mode 100644 scripts/run-integration-test.sh diff --git a/IntegrationTests/Simple/.gitignore b/IntegrationTest/.gitignore similarity index 100% rename from IntegrationTests/Simple/.gitignore rename to IntegrationTest/.gitignore diff --git a/IntegrationTests/Simple/Package.swift b/IntegrationTest/Package.swift similarity index 98% rename from IntegrationTests/Simple/Package.swift rename to IntegrationTest/Package.swift index 1ae155a6..f9f8fb1a 100644 --- a/IntegrationTests/Simple/Package.swift +++ b/IntegrationTest/Package.swift @@ -15,7 +15,7 @@ import PackageDescription let package = Package( - name: "Simple", + name: "swift-openapi-integration-test", platforms: [ .macOS(.v13) ], diff --git a/IntegrationTests/Simple/README.md b/IntegrationTest/README.md similarity index 100% rename from IntegrationTests/Simple/README.md rename to IntegrationTest/README.md diff --git a/IntegrationTests/Simple/Sources/Client/Empty.swift b/IntegrationTest/Sources/Client/Empty.swift similarity index 100% rename from IntegrationTests/Simple/Sources/Client/Empty.swift rename to IntegrationTest/Sources/Client/Empty.swift diff --git a/IntegrationTests/Simple/Sources/Client/openapi-generator-config.yaml b/IntegrationTest/Sources/Client/openapi-generator-config.yaml similarity index 100% rename from IntegrationTests/Simple/Sources/Client/openapi-generator-config.yaml rename to IntegrationTest/Sources/Client/openapi-generator-config.yaml diff --git a/IntegrationTests/Simple/Sources/Client/openapi.yaml b/IntegrationTest/Sources/Client/openapi.yaml similarity index 100% rename from IntegrationTests/Simple/Sources/Client/openapi.yaml rename to IntegrationTest/Sources/Client/openapi.yaml diff --git a/IntegrationTests/Simple/Sources/MockTransportClient/Client.swift b/IntegrationTest/Sources/MockTransportClient/Client.swift similarity index 100% rename from IntegrationTests/Simple/Sources/MockTransportClient/Client.swift rename to IntegrationTest/Sources/MockTransportClient/Client.swift diff --git a/IntegrationTests/Simple/Sources/MockTransportServer/Server.swift b/IntegrationTest/Sources/MockTransportServer/Server.swift similarity index 100% rename from IntegrationTests/Simple/Sources/MockTransportServer/Server.swift rename to IntegrationTest/Sources/MockTransportServer/Server.swift diff --git a/IntegrationTests/Simple/Sources/Server/Empty.swift b/IntegrationTest/Sources/Server/Empty.swift similarity index 100% rename from IntegrationTests/Simple/Sources/Server/Empty.swift rename to IntegrationTest/Sources/Server/Empty.swift diff --git a/IntegrationTests/Simple/Sources/Server/openapi-generator-config.yaml b/IntegrationTest/Sources/Server/openapi-generator-config.yaml similarity index 100% rename from IntegrationTests/Simple/Sources/Server/openapi-generator-config.yaml rename to IntegrationTest/Sources/Server/openapi-generator-config.yaml diff --git a/IntegrationTests/Simple/Sources/Server/openapi.yaml b/IntegrationTest/Sources/Server/openapi.yaml similarity index 100% rename from IntegrationTests/Simple/Sources/Server/openapi.yaml rename to IntegrationTest/Sources/Server/openapi.yaml diff --git a/IntegrationTests/Simple/Sources/Types/Empty.swift b/IntegrationTest/Sources/Types/Empty.swift similarity index 100% rename from IntegrationTests/Simple/Sources/Types/Empty.swift rename to IntegrationTest/Sources/Types/Empty.swift diff --git a/IntegrationTests/Simple/Sources/Types/openapi-generator-config.yaml b/IntegrationTest/Sources/Types/openapi-generator-config.yaml similarity index 100% rename from IntegrationTests/Simple/Sources/Types/openapi-generator-config.yaml rename to IntegrationTest/Sources/Types/openapi-generator-config.yaml diff --git a/IntegrationTests/Simple/Sources/Types/openapi.yaml b/IntegrationTest/Sources/Types/openapi.yaml similarity index 100% rename from IntegrationTests/Simple/Sources/Types/openapi.yaml rename to IntegrationTest/Sources/Types/openapi.yaml diff --git a/IntegrationTests/Simple/Sources/openapi.yaml b/IntegrationTest/Sources/openapi.yaml similarity index 100% rename from IntegrationTests/Simple/Sources/openapi.yaml rename to IntegrationTest/Sources/openapi.yaml diff --git a/docker/Dockerfile b/docker/Dockerfile index 4b7014a7..33f860d9 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -20,4 +20,7 @@ RUN echo 'export PATH="$HOME/.tools:$PATH"' >> $HOME/.profile ARG swiftformat_version=508.0.0 RUN git clone --branch $swiftformat_version --depth 1 https://github.com/apple/swift-format $HOME/.tools/swift-format-source RUN cd $HOME/.tools/swift-format-source && swift build -c release -RUN ln -s $HOME/.tools/swift-format-source/.build/release/swift-format $HOME/.tools/swift-format \ No newline at end of file +RUN ln -s $HOME/.tools/swift-format-source/.build/release/swift-format $HOME/.tools/swift-format + +# jq +RUN apt-get install -y jq diff --git a/docker/docker-compose.yaml b/docker/docker-compose.yaml index bb42b187..3e6f33a2 100644 --- a/docker/docker-compose.yaml +++ b/docker/docker-compose.yaml @@ -27,6 +27,8 @@ services: soundness: <<: *common command: /bin/bash -xcl "swift -version && uname -a && ./scripts/soundness.sh" + environment: + SWIFT_OPENAPI_GENERATOR_REPO_URL: file:///code test: <<: *common diff --git a/scripts/run-integration-test.sh b/scripts/run-integration-test.sh new file mode 100644 index 00000000..f9928287 --- /dev/null +++ b/scripts/run-integration-test.sh @@ -0,0 +1,48 @@ +#!/usr/bin/env bash +##===----------------------------------------------------------------------===## +## +## This source file is part of the SwiftOpenAPIGenerator open source project +## +## Copyright (c) 2023 Apple Inc. and the SwiftOpenAPIGenerator project authors +## Licensed under Apache License v2.0 +## +## See LICENSE.txt for license information +## See CONTRIBUTORS.txt for the list of SwiftOpenAPIGenerator project authors +## +## SPDX-License-Identifier: Apache-2.0 +## +##===----------------------------------------------------------------------===## +set -euo pipefail + +log() { printf -- "** %s\n" "$*" >&2; } +error() { printf -- "** ERROR: %s\n" "$*" >&2; } +fatal() { error "$@"; exit 1; } + +log "Checking required executables..." +SWIFT_BIN=${SWIFT_BIN:-$(command -v swift || xcrun -f swift)} || fatal "SWIFT_BIN unset and no swift on PATH" +JQ_BIN=${JQ_BIN:-$(command -v jq)} || fatal "JQ_BIN unset and no jq on PATH" + +CURRENT_SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +REPO_ROOT="$(git -C "${CURRENT_SCRIPT_DIR}" rev-parse --show-toplevel)" +TMP_DIR=$(mktemp -d "${PWD}/tmp.$(basename "$0").XXXXXXXXXX.noindex") + +PACKAGE_PATH=${PACKAGE_PATH:-${REPO_ROOT}} + +SWIFT_OPENAPI_GENERATOR_REPO_URL="${SWIFT_OPENAPI_GENERATOR_REPO_URL:-https://github.com/apple/swift-openapi-generator}" +SWIFT_OPENAPI_GENERATOR_REPO_CLONE_DIR="${TMP_DIR}/$(basename "${SWIFT_OPENAPI_GENERATOR_REPO_URL}")" +INTEGRATION_TEST_PACKAGE_PATH="${SWIFT_OPENAPI_GENERATOR_REPO_CLONE_DIR}/IntegrationTest" + +log "Cloning ${SWIFT_OPENAPI_GENERATOR_REPO_URL} to ${SWIFT_OPENAPI_GENERATOR_REPO_CLONE_DIR}" +git clone --depth=1 "${SWIFT_OPENAPI_GENERATOR_REPO_URL}" "${SWIFT_OPENAPI_GENERATOR_REPO_CLONE_DIR}" + +log "Extracting name for Swift package: ${PACKAGE_PATH}" +PACKAGE_NAME=$(swift package --package-path "${PACKAGE_PATH}" describe --type json | "${JQ_BIN}" -r .name) + +log "Overriding dependency in ${INTEGRATION_TEST_PACKAGE_PATH} on ${PACKAGE_NAME} to use ${PACKAGE_PATH}" +swift package --package-path "${INTEGRATION_TEST_PACKAGE_PATH}" \ + edit "${PACKAGE_NAME}" --path "${PACKAGE_PATH}" + +log "Building integration test package: ${INTEGRATION_TEST_PACKAGE_PATH}" +swift build --package-path "${INTEGRATION_TEST_PACKAGE_PATH}" + +log "✅ Successfully built integration test package." diff --git a/scripts/run-swift-format.sh b/scripts/run-swift-format.sh index f6ab93d5..f29f6108 100644 --- a/scripts/run-swift-format.sh +++ b/scripts/run-swift-format.sh @@ -26,7 +26,7 @@ SWIFTFORMAT_BIN=${SWIFTFORMAT_BIN:-$(command -v swift-format)} || fatal "❌ SWI "${SWIFTFORMAT_BIN}" lint \ --parallel --recursive --strict \ "${REPO_ROOT}/Examples" \ - "${REPO_ROOT}/IntegrationTests" \ + "${REPO_ROOT}/IntegrationTest" \ "${REPO_ROOT}/Plugins" \ "${REPO_ROOT}/Sources" \ "${REPO_ROOT}/Tests" \ diff --git a/scripts/soundness.sh b/scripts/soundness.sh index 9d6009bc..06c63e18 100755 --- a/scripts/soundness.sh +++ b/scripts/soundness.sh @@ -28,6 +28,7 @@ SCRIPT_PATHS=( "${CURRENT_SCRIPT_DIR}/check-license-headers.sh" "${CURRENT_SCRIPT_DIR}/run-swift-format.sh" "${CURRENT_SCRIPT_DIR}/check-for-docc-warnings.sh" + "${CURRENT_SCRIPT_DIR}/run-integration-test.sh" ) for SCRIPT_PATH in "${SCRIPT_PATHS[@]}"; do