Skip to content

Commit

Permalink
Build IntegrationTest package as part of CI pipeline (#56)
Browse files Browse the repository at this point in the history
### 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 <[email protected]>
  • Loading branch information
simonjbeaumont authored Jun 9, 2023
1 parent 02924d1 commit 37255b7
Show file tree
Hide file tree
Showing 20 changed files with 57 additions and 3 deletions.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import PackageDescription

let package = Package(
name: "Simple",
name: "swift-openapi-integration-test",
platforms: [
.macOS(.v13)
],
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
5 changes: 4 additions & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
RUN ln -s $HOME/.tools/swift-format-source/.build/release/swift-format $HOME/.tools/swift-format

# jq
RUN apt-get install -y jq
2 changes: 2 additions & 0 deletions docker/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
48 changes: 48 additions & 0 deletions scripts/run-integration-test.sh
Original file line number Diff line number Diff line change
@@ -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."
2 changes: 1 addition & 1 deletion scripts/run-swift-format.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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" \
Expand Down
1 change: 1 addition & 0 deletions scripts/soundness.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 37255b7

Please sign in to comment.