Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,30 @@ jobs:
windows_6_1_enabled: false
windows_nightly_next_enabled: false
windows_nightly_main_enabled: false

construct-example-packages-matrix:
name: Construct example packages matrix
runs-on: ubuntu-latest
outputs:
example-packages-matrix: '${{ steps.generate-matrix.outputs.example-packages-matrix }}'
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
persist-credentials: false
- id: generate-matrix
run: echo "example-packages-matrix=$(curl -s https://raw.githubusercontent.com/apple/swift-nio/main/scripts/generate_matrix.sh | bash)" >> "$GITHUB_OUTPUT"
env:
MATRIX_LINUX_SETUP_COMMAND: git config --global --add safe.directory /swift-configuration
MATRIX_LINUX_COMMAND: ./Scripts/test-examples.sh
MATRIX_LINUX_5_10_ENABLED: false
MATRIX_LINUX_6_0_ENABLED: false
MATRIX_LINUX_NIGHTLY_MAIN_ENABLED: false

example-packages:
name: Example packages
needs: construct-example-packages-matrix
uses: apple/swift-nio/.github/workflows/swift_test_matrix.yml@main
with:
name: "Example packages"
matrix_string: '${{ needs.construct-example-packages-matrix.outputs.example-packages-matrix }}'
27 changes: 27 additions & 0 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,30 @@ jobs:
windows_6_1_enabled: false
windows_nightly_next_enabled: false
windows_nightly_main_enabled: false

construct-example-packages-matrix:
name: Construct example packages matrix
runs-on: ubuntu-latest
outputs:
example-packages-matrix: '${{ steps.generate-matrix.outputs.example-packages-matrix }}'
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
persist-credentials: false
- id: generate-matrix
run: echo "example-packages-matrix=$(curl -s https://raw.githubusercontent.com/apple/swift-nio/main/scripts/generate_matrix.sh | bash)" >> "$GITHUB_OUTPUT"
env:
MATRIX_LINUX_SETUP_COMMAND: git config --global --add safe.directory /swift-configuration
MATRIX_LINUX_COMMAND: ./Scripts/test-examples.sh
MATRIX_LINUX_5_10_ENABLED: false
MATRIX_LINUX_6_0_ENABLED: false
MATRIX_LINUX_NIGHTLY_MAIN_ENABLED: false

example-packages:
name: Example packages
needs: construct-example-packages-matrix
uses: apple/swift-nio/.github/workflows/swift_test_matrix.yml@main
with:
name: "Example packages"
matrix_string: '${{ needs.construct-example-packages-matrix.outputs.example-packages-matrix }}'
9 changes: 9 additions & 0 deletions NOTICE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,12 @@ This repository contains the gyb script from the swiftlang/swift repository.
* https://github.com/swiftlang/swift

---

This repository contains a modified copy of the test-examples.sh script the apple/swift-openapi-generator repository.

* LICENSE (Apache License 2.0):
* https://www.apache.org/licenses/LICENSE-2.0
* HOMEPAGE:
* https://github.com/apple/swift-openapi-generator

---
73 changes: 73 additions & 0 deletions Scripts/test-examples.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#!/bin/bash
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"
SHARED_EXAMPLE_HARNESS_PACKAGE_PATH="${TMP_DIR}/example-harness"
SHARED_PACKAGE_SCRATCH_PATH="${TMP_DIR}/example-cache"
SHARED_PACKAGE_CACHE_PATH="${TMP_DIR}/example-scratch"

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

EXAMPLE_PACKAGE_NAME="$(basename "${EXAMPLE_PACKAGE_PATH}")"

if [[ "${SINGLE_EXAMPLE_PACKAGE:-${EXAMPLE_PACKAGE_NAME}}" != "${EXAMPLE_PACKAGE_NAME}" ]]; then
log "Skipping example: ${EXAMPLE_PACKAGE_NAME}"
continue
fi

log "Recreating shared example harness directory: ${SHARED_EXAMPLE_HARNESS_PACKAGE_PATH}"
rm -rf "${SHARED_EXAMPLE_HARNESS_PACKAGE_PATH}"
mkdir -v "${SHARED_EXAMPLE_HARNESS_PACKAGE_PATH}"

log "Copying example contents from ${EXAMPLE_PACKAGE_NAME} to ${SHARED_EXAMPLE_HARNESS_PACKAGE_PATH}"
git archive HEAD "${EXAMPLE_PACKAGE_PATH}" --format tar | tar -C "${SHARED_EXAMPLE_HARNESS_PACKAGE_PATH}" -xvf- --strip-components 2

# GNU tar has --touch, but BSD tar does not, so we'll use touch directly.
log "Updating mtime of example contents..."
find "${SHARED_EXAMPLE_HARNESS_PACKAGE_PATH}" -print0 | xargs -0 -n1 touch -m

log "Re-overriding dependency in ${EXAMPLE_PACKAGE_NAME} to use ${PACKAGE_PATH}"
"${SWIFT_BIN}" package \
--package-path "${SHARED_EXAMPLE_HARNESS_PACKAGE_PATH}" \
--cache-path "${SHARED_PACKAGE_CACHE_PATH}" \
--skip-update \
--scratch-path "${SHARED_PACKAGE_SCRATCH_PATH}" \
unedit swift-configuration || :
"${SWIFT_BIN}" package \
--package-path "${SHARED_EXAMPLE_HARNESS_PACKAGE_PATH}" \
--cache-path "${SHARED_PACKAGE_CACHE_PATH}" \
--skip-update \
--scratch-path "${SHARED_PACKAGE_SCRATCH_PATH}" \
edit swift-configuration \
--path "${PACKAGE_PATH}"

log "Building example package: ${EXAMPLE_PACKAGE_NAME}"
"${SWIFT_BIN}" build --build-tests \
--package-path "${SHARED_EXAMPLE_HARNESS_PACKAGE_PATH}" \
--cache-path "${SHARED_PACKAGE_CACHE_PATH}" \
--skip-update \
--scratch-path "${SHARED_PACKAGE_SCRATCH_PATH}"
log "✅ Successfully built the example package ${EXAMPLE_PACKAGE_NAME}."

if [ -d "${SHARED_EXAMPLE_HARNESS_PACKAGE_PATH}/Tests" ]; then
log "Running tests for example package: ${EXAMPLE_PACKAGE_NAME}"
"${SWIFT_BIN}" test \
--package-path "${SHARED_EXAMPLE_HARNESS_PACKAGE_PATH}" \
--cache-path "${SHARED_PACKAGE_CACHE_PATH}" \
--skip-update \
--scratch-path "${SHARED_PACKAGE_SCRATCH_PATH}"
log "✅ Passed the tests for the example package ${EXAMPLE_PACKAGE_NAME}."
fi
done