diff --git a/.github/workflows/build_soundness.yml b/.github/workflows/build_soundness.yml deleted file mode 100644 index d944c14e..00000000 --- a/.github/workflows/build_soundness.yml +++ /dev/null @@ -1,35 +0,0 @@ -name: Build, tests & soundness checks - -on: [pull_request, workflow_dispatch] - -jobs: - swift-bedrock-library: - runs-on: ubuntu-latest - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - name: Run tests - run: swift test - - playground-backend: - runs-on: ubuntu-latest - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - name: Web playground backend build - working-directory: Examples/web-playground/backend - run: swift build - - soundness: - name: Soundness - uses: swiftlang/github-workflows/.github/workflows/soundness.yml@main - with: - license_header_check_enabled: true - license_header_check_project_name: "Swift Bedrock Library" - shell_check_enabled: false - python_lint_check_enabled: false - api_breakage_check_enabled: false - # api_breakage_check_container_image: "swift:6.0-noble" - docs_check_container_image: "swift:6.0-noble" - format_check_container_image: "swift:6.0-noble" - yamllint_check_enabled: true diff --git a/.github/workflows/integration_tests.yml b/.github/workflows/integration_tests.yml new file mode 100644 index 00000000..6ac2274a --- /dev/null +++ b/.github/workflows/integration_tests.yml @@ -0,0 +1,80 @@ +name: IntegrationTests + +on: + workflow_call: + inputs: + name: + type: string + description: "The name of the workflow used for the concurrency group." + required: true + # We pass the list of examples here, but we can't pass an array as argument + # Instead, we pass a String with a valid JSON array. + # The workaround is mentioned here https://github.com/orgs/community/discussions/11692 + examples: + type: string + description: "The list of examples to run. Pass a String with a valid JSON array such as \"[ 'Converse', 'ConverseStream' ]\"" + required: true + default: "" + examples_enabled: + type: boolean + description: "Boolean to enable the compilation of examples. Defaults to true." + default: true + check_foundation_enabled: + type: boolean + description: "Boolean to enable the check for Foundation dependency. Defaults to true." + default: true + matrix_linux_command: + type: string + description: "The command of the current Swift version linux matrix job to execute." + required: true + +## We are cancelling previously triggered workflow runs +concurrency: + group: ${{ github.workflow }}-${{ github.ref }}-${{ inputs.name }} + cancel-in-progress: true + +jobs: + test-examples: + name: Test Examples/${{ matrix.examples }} on ${{ matrix.swift.swift_version }} + if: ${{ inputs.examples_enabled }} + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + examples: ${{ fromJson(inputs.examples) }} + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Mark the workspace as safe + run: git config --global --add safe.directory ${GITHUB_WORKSPACE} + + - name: Run matrix job + env: + COMMAND: ${{ inputs.matrix_linux_command }} + EXAMPLE: ${{ matrix.examples }} + run: | + .github/workflows/scripts/integration_tests.sh + + playground-backend: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + - name: Web playground backend build + working-directory: Examples/web-playground/backend + run: swift build + + check-foundation: + name: No dependencies on Foundation + if: ${{ inputs.check_foundation_enabled }} + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + - name: Mark the workspace as safe + # https://github.com/actions/checkout/issues/766 + run: git config --global --add safe.directory ${GITHUB_WORKSPACE} + - name: Check for Foundation or ICU dependency + run: | + .github/workflows/scripts/check-link-foundation.sh diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml new file mode 100644 index 00000000..5c1cf092 --- /dev/null +++ b/.github/workflows/pull_request.yml @@ -0,0 +1,43 @@ +name: Build, tests & soundness checks + +on: [pull_request, workflow_dispatch] + +jobs: + swift-bedrock-library: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + - name: Run tests + run: swift test + + soundness: + name: Soundness + uses: swiftlang/github-workflows/.github/workflows/soundness.yml@main + with: + license_header_check_enabled: true + license_header_check_project_name: "Swift Bedrock Library" + shell_check_enabled: false + python_lint_check_enabled: false + api_breakage_check_enabled: false + # api_breakage_check_container_image: "swift:6.1-noble" + docs_check_container_image: "swift:6.1-noble" + format_check_container_image: "swift:6.1-noble" + yamllint_check_enabled: true + + integration-tests: + name: Integration Tests + uses: ./.github/workflows/integration_tests.yml + with: + name: "Integration tests" + examples_enabled: true + matrix_linux_command: "swift build" + check_foundation_enabled: true + # We pass the list of examples here, but we can't pass an array as argument + # Instead, we pass a String with a valid JSON array. + # The workaround is mentioned here https://github.com/orgs/community/discussions/11692 + examples: "[ 'converse', 'converse-stream' ]" + + swift-6-language-mode: + name: Swift 6 Language Mode + uses: ./.github/workflows/swift-6-language-mode.yml diff --git a/.github/workflows/scripts/check-link-foundation.sh b/.github/workflows/scripts/check-link-foundation.sh new file mode 100755 index 00000000..91293acc --- /dev/null +++ b/.github/workflows/scripts/check-link-foundation.sh @@ -0,0 +1,61 @@ +#!/bin/bash +##===----------------------------------------------------------------------===## +## +## This source file is part of the Swift Bedrock Library open source project +## +## Copyright (c) 2025 Amazon.com, Inc. or its affiliates +## and the Swift Bedrock Library project authors +## Licensed under Apache License v2.0 +## +## See LICENSE.txt for license information +## See CONTRIBUTORS.txt for the list of Swift Bedrock Library project authors +## +## SPDX-License-Identifier: Apache-2.0 +## +##===----------------------------------------------------------------------===## + +log() { printf -- "** %s\n" "$*" >&2; } +error() { printf -- "** ERROR: %s\n" "$*" >&2; } +fatal() { error "$@"; exit 1; } + +EXAMPLE=converse +OUTPUT_DIR=.build/release +OUTPUT_FILE=${OUTPUT_DIR}/converse +LIBS_TO_CHECK="libFoundation.so libFoundationInternationalization.so lib_FoundationICU.so" + +pushd Examples/${EXAMPLE} || fatal "Failed to change directory to Examples/${EXAMPLE}." + +# recompile the example without the --static-swift-stdlib flag +LAMBDA_USE_LOCAL_DEPS=../.. swift build -c release -Xlinker -s || fatal "Failed to build the example." + +# check if the binary exists +if [ ! -f "${OUTPUT_FILE}" ]; then + error "❌ ${OUTPUT_FILE} does not exist." +fi + +# Checking for Foundation or ICU dependencies +echo "Checking for Foundation or ICU dependencies in ${OUTPUT_DIR}/${OUTPUT_FILE}." +LIBRARIES=$(ldd ${OUTPUT_FILE} | awk '{print $1}') +for LIB in ${LIBS_TO_CHECK}; do + echo -n "Checking for ${LIB}... " + + # check if the binary has a dependency on Foundation or ICU + echo "${LIBRARIES}" | grep "${LIB}" # return 1 if not found + + # 1 is success (grep failed to find the lib), 0 is failure (grep successly found the lib) + SUCCESS=$? + if [ "$SUCCESS" -eq 0 ]; then + log "❌ ${LIB} found." && break + else + log "✅ ${LIB} not found." + fi +done + +popd || fatal "Failed to change directory back to the root directory." + +# exit code is the opposite of the grep exit code +if [ "$SUCCESS" -eq 0 ]; then + fatal "❌ At least one foundation lib was found, reporting the error." +else + log "✅ No foundation lib found, congrats!" && exit 0 +fi \ No newline at end of file diff --git a/.github/workflows/scripts/integration_tests.sh b/.github/workflows/scripts/integration_tests.sh new file mode 100755 index 00000000..22fdd5d4 --- /dev/null +++ b/.github/workflows/scripts/integration_tests.sh @@ -0,0 +1,33 @@ +#!/bin/bash +##===----------------------------------------------------------------------===## +## +## This source file is part of the Swift Bedrock Library open source project +## +## Copyright (c) 2025 Amazon.com, Inc. or its affiliates +## and the Swift Bedrock Library project authors +## Licensed under Apache License v2.0 +## +## See LICENSE.txt for license information +## See CONTRIBUTORS.txt for the list of Swift Bedrock Library 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; } + +SWIFT_VERSION=$(swift --version) +test -n "${SWIFT_VERSION:-}" || fatal "SWIFT_VERSION unset" +test -n "${COMMAND:-}" || fatal "COMMAND unset" +test -n "${EXAMPLE:-}" || fatal "EXAMPLE unset" + +pushd Examples/"$EXAMPLE" > /dev/null + +log "Running command with Swift $SWIFT_VERSION" +eval "$COMMAND" + +popd diff --git a/.github/workflows/swift-6-language-mode.yml b/.github/workflows/swift-6-language-mode.yml new file mode 100644 index 00000000..818e9f48 --- /dev/null +++ b/.github/workflows/swift-6-language-mode.yml @@ -0,0 +1,24 @@ +name: Swift 6 language mode + +on: + workflow_call: + +# We are cancelling previously triggered workflow runs +concurrency: + group: ${{ github.workflow }}-${{ github.ref }}-swift-6-language-mode + cancel-in-progress: true + +jobs: + swift-6-language-mode: + name: Swift 6 language mode + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + persist-credentials: false + submodules: true + - name: Set the language mode + run: swift package tools-version --set 6.0 + - name: Build with Swift 6 language mode + run: swift build -Xswiftc -warnings-as-errors diff --git a/Examples/converse-stream/Package.swift b/Examples/converse-stream/Package.swift index 517e3b45..470db0c1 100644 --- a/Examples/converse-stream/Package.swift +++ b/Examples/converse-stream/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version: 6.1 +// swift-tools-version: 6.0 // The swift-tools-version declares the minimum version of Swift required to build this package. import PackageDescription diff --git a/Examples/converse/Package.swift b/Examples/converse/Package.swift index a09889a7..e2b5a3b3 100644 --- a/Examples/converse/Package.swift +++ b/Examples/converse/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version: 6.1 +// swift-tools-version: 6.0 // The swift-tools-version declares the minimum version of Swift required to build this package. import PackageDescription diff --git a/Package.swift b/Package.swift index c8c3bdb3..f5ff2bba 100644 --- a/Package.swift +++ b/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version: 6.1 +// swift-tools-version: 6.0 // The swift-tools-version declares the minimum version of Swift required to build this package. import PackageDescription