Skip to content

Commit

Permalink
[CI] Start testing examples (#412)
Browse files Browse the repository at this point in the history
[CI] Start testing examples

### Motivation

We're expanding the Examples section and want to verify that they continue to work as the project evolves.

That means that they successfully build, and for those with tests, that the tests are passing.

### Modifications

Added a script that is now triggered by the new `examples` pipeline.

It goes through all the packages in Examples and builds them, and for those with a Tests directory, also tests them.

### Result

More confidence that our Examples are working.

### Test Plan

Ran the test on macOS, ran it in docker-compose, all passed, so did the new CI. Verified in CI logs that the script is actually running and the two existing examples were exercised.



Reviewed by: simonjbeaumont

Builds:
     ✔︎ pull request validation (5.10) - Build finished. 
     ✔︎ pull request validation (5.9) - Build finished. 
     ✔︎ pull request validation (5.9.0) - Build finished. 
     ✔︎ pull request validation (compatibility test) - Build finished. 
     ✔︎ pull request validation (docc test) - Build finished. 
     ✔︎ pull request validation (examples) - Build finished. 
     ✔︎ pull request validation (integration test) - Build finished. 
     ✔︎ pull request validation (nightly) - Build finished. 
     ✔︎ pull request validation (soundness) - Build finished. 

#412
  • Loading branch information
czechboy0 committed Dec 1, 2023
1 parent 424f638 commit 61fa836
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 1 deletion.
1 change: 1 addition & 0 deletions Examples/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
**/Package.resolved
2 changes: 1 addition & 1 deletion docker/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,4 @@ services:

examples:
<<: *common
command: /bin/bash -xcl "swift -version && uname -a && true" # Placeholder to bootstrap pipeline.
command: /bin/bash -xcl "swift -version && uname -a && bash ./scripts/test-examples.sh"
51 changes: 51 additions & 0 deletions scripts/test-examples.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/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"

CURRENT_SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
REPO_ROOT="$(git -C "${CURRENT_SCRIPT_DIR}" rev-parse --show-toplevel)"
TMP_DIR=$(/usr/bin/mktemp -d -p "${TMPDIR-/tmp}" "$(basename "$0").XXXXXXXXXX")

PACKAGE_PATH=${PACKAGE_PATH:-${REPO_ROOT}}
EXAMPLES_PACKAGE_PATH="${PACKAGE_PATH}/Examples"

for EXAMPLE_PACKAGE_PATH in $(find "${EXAMPLES_PACKAGE_PATH}" -maxdepth 2 -name Package.swift -type f -print0 | xargs -0 dirname); do

EXAMPLE_PACKAGE_NAME="$(basename "${EXAMPLE_PACKAGE_PATH}")"
EXAMPLE_COPY_DIR="${TMP_DIR}/${EXAMPLE_PACKAGE_NAME}"
log "Copying example ${EXAMPLE_PACKAGE_NAME} to ${EXAMPLE_COPY_DIR}"
cp -R "${EXAMPLE_PACKAGE_PATH}" "${EXAMPLE_COPY_DIR}"

log "Overriding dependency in ${EXAMPLE_PACKAGE_NAME} to use ${PACKAGE_PATH}"
"${SWIFT_BIN}" package --package-path "${EXAMPLE_COPY_DIR}" \
edit swift-openapi-generator --path "${PACKAGE_PATH}"

log "Building example package: ${EXAMPLE_PACKAGE_NAME}"
"${SWIFT_BIN}" build --package-path "${EXAMPLE_COPY_DIR}"
log "✅ Successfully built the example package ${EXAMPLE_PACKAGE_NAME}."

if [ -d "${EXAMPLE_COPY_DIR}/Tests" ]; then
log "Running tests for example package: ${EXAMPLE_PACKAGE_NAME}"
"${SWIFT_BIN}" test --package-path "${EXAMPLE_COPY_DIR}"
log "✅ Passed the tests for the example package ${EXAMPLE_PACKAGE_NAME}."
fi
done

0 comments on commit 61fa836

Please sign in to comment.