Skip to content

Commit b7ae7af

Browse files
Add integration test CI check (#17)
### Motivation We want to make sure that we don't unknowingly introduce changes in the runtime that break the generator, which relies on its SPI. We have an package in a subdirectory in the generator 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. The generator repo also contains a script that can be used to clone the integration test package and use `swift package edit` to override a dependency to check it still functions with the proposed changes. ### Modifications - Bring in the `run-integraton-test.sh` script from the generator repo. - 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/run-integration-test.sh... ... ** Extracting name for Swift package: /code ** Overriding dependency in /code/tmp.run-integration-test.sh.uyS9Hf8siA.noindex/swift-openapi-generator/IntegrationTest on swift-openapi-runtime to use /code ... 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 in the future. Signed-off-by: Si Beaumont <beaumont@apple.com>
1 parent b66f94a commit b7ae7af

File tree

3 files changed

+53
-1
lines changed

3 files changed

+53
-1
lines changed

docker/Dockerfile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,7 @@ RUN echo 'export PATH="$HOME/.tools:$PATH"' >> $HOME/.profile
2020
ARG swiftformat_version=508.0.0
2121
RUN git clone --branch $swiftformat_version --depth 1 https://github.com/apple/swift-format $HOME/.tools/swift-format-source
2222
RUN cd $HOME/.tools/swift-format-source && swift build -c release
23-
RUN ln -s $HOME/.tools/swift-format-source/.build/release/swift-format $HOME/.tools/swift-format
23+
RUN ln -s $HOME/.tools/swift-format-source/.build/release/swift-format $HOME/.tools/swift-format
24+
25+
# jq
26+
RUN apt-get install -y jq

scripts/run-integration-test.sh

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/usr/bin/env bash
2+
##===----------------------------------------------------------------------===##
3+
##
4+
## This source file is part of the SwiftOpenAPIGenerator open source project
5+
##
6+
## Copyright (c) 2023 Apple Inc. and the SwiftOpenAPIGenerator project authors
7+
## Licensed under Apache License v2.0
8+
##
9+
## See LICENSE.txt for license information
10+
## See CONTRIBUTORS.txt for the list of SwiftOpenAPIGenerator project authors
11+
##
12+
## SPDX-License-Identifier: Apache-2.0
13+
##
14+
##===----------------------------------------------------------------------===##
15+
set -euo pipefail
16+
17+
log() { printf -- "** %s\n" "$*" >&2; }
18+
error() { printf -- "** ERROR: %s\n" "$*" >&2; }
19+
fatal() { error "$@"; exit 1; }
20+
21+
log "Checking required executables..."
22+
SWIFT_BIN=${SWIFT_BIN:-$(command -v swift || xcrun -f swift)} || fatal "SWIFT_BIN unset and no swift on PATH"
23+
JQ_BIN=${JQ_BIN:-$(command -v jq)} || fatal "JQ_BIN unset and no jq on PATH"
24+
25+
CURRENT_SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
26+
REPO_ROOT="$(git -C "${CURRENT_SCRIPT_DIR}" rev-parse --show-toplevel)"
27+
TMP_DIR=$(mktemp -d "${PWD}/tmp.$(basename "$0").XXXXXXXXXX.noindex")
28+
29+
PACKAGE_PATH=${PACKAGE_PATH:-${REPO_ROOT}}
30+
31+
SWIFT_OPENAPI_GENERATOR_REPO_URL="${SWIFT_OPENAPI_GENERATOR_REPO_URL:-https://github.com/apple/swift-openapi-generator}"
32+
SWIFT_OPENAPI_GENERATOR_REPO_CLONE_DIR="${TMP_DIR}/$(basename "${SWIFT_OPENAPI_GENERATOR_REPO_URL}")"
33+
INTEGRATION_TEST_PACKAGE_PATH="${SWIFT_OPENAPI_GENERATOR_REPO_CLONE_DIR}/IntegrationTest"
34+
35+
log "Cloning ${SWIFT_OPENAPI_GENERATOR_REPO_URL} to ${SWIFT_OPENAPI_GENERATOR_REPO_CLONE_DIR}"
36+
git clone --depth=1 "${SWIFT_OPENAPI_GENERATOR_REPO_URL}" "${SWIFT_OPENAPI_GENERATOR_REPO_CLONE_DIR}"
37+
38+
log "Extracting name for Swift package: ${PACKAGE_PATH}"
39+
PACKAGE_NAME=$(swift package --package-path "${PACKAGE_PATH}" describe --type json | "${JQ_BIN}" -r .name)
40+
41+
log "Overriding dependency in ${INTEGRATION_TEST_PACKAGE_PATH} on ${PACKAGE_NAME} to use ${PACKAGE_PATH}"
42+
swift package --package-path "${INTEGRATION_TEST_PACKAGE_PATH}" \
43+
edit "${PACKAGE_NAME}" --path "${PACKAGE_PATH}"
44+
45+
log "Building integration test package: ${INTEGRATION_TEST_PACKAGE_PATH}"
46+
swift build --package-path "${INTEGRATION_TEST_PACKAGE_PATH}"
47+
48+
log "✅ Successfully built integration test package."

scripts/soundness.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ SCRIPT_PATHS=(
2828
"${CURRENT_SCRIPT_DIR}/check-license-headers.sh"
2929
"${CURRENT_SCRIPT_DIR}/run-swift-format.sh"
3030
"${CURRENT_SCRIPT_DIR}/check-for-docc-warnings.sh"
31+
"${CURRENT_SCRIPT_DIR}/run-integration-test.sh"
3132
)
3233

3334
for SCRIPT_PATH in "${SCRIPT_PATHS[@]}"; do

0 commit comments

Comments
 (0)