Skip to content

Commit c8e3357

Browse files
authored
improve ci (#22)
* improve ci * fix yaml lint * fix container for integration test * make sure we use ubuntu container and checkout action * lower the requirement to swift 6.0 instead of swift 6.1 * fix example directory names * fix directory name * fix integration test * execute integration test on GH provided images
1 parent 193848d commit c8e3357

File tree

9 files changed

+244
-38
lines changed

9 files changed

+244
-38
lines changed

.github/workflows/build_soundness.yml

Lines changed: 0 additions & 35 deletions
This file was deleted.
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
name: IntegrationTests
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
name:
7+
type: string
8+
description: "The name of the workflow used for the concurrency group."
9+
required: true
10+
# We pass the list of examples here, but we can't pass an array as argument
11+
# Instead, we pass a String with a valid JSON array.
12+
# The workaround is mentioned here https://github.com/orgs/community/discussions/11692
13+
examples:
14+
type: string
15+
description: "The list of examples to run. Pass a String with a valid JSON array such as \"[ 'Converse', 'ConverseStream' ]\""
16+
required: true
17+
default: ""
18+
examples_enabled:
19+
type: boolean
20+
description: "Boolean to enable the compilation of examples. Defaults to true."
21+
default: true
22+
check_foundation_enabled:
23+
type: boolean
24+
description: "Boolean to enable the check for Foundation dependency. Defaults to true."
25+
default: true
26+
matrix_linux_command:
27+
type: string
28+
description: "The command of the current Swift version linux matrix job to execute."
29+
required: true
30+
31+
## We are cancelling previously triggered workflow runs
32+
concurrency:
33+
group: ${{ github.workflow }}-${{ github.ref }}-${{ inputs.name }}
34+
cancel-in-progress: true
35+
36+
jobs:
37+
test-examples:
38+
name: Test Examples/${{ matrix.examples }} on ${{ matrix.swift.swift_version }}
39+
if: ${{ inputs.examples_enabled }}
40+
runs-on: ubuntu-latest
41+
strategy:
42+
fail-fast: false
43+
matrix:
44+
examples: ${{ fromJson(inputs.examples) }}
45+
steps:
46+
- name: Checkout repository
47+
uses: actions/checkout@v4
48+
49+
- name: Mark the workspace as safe
50+
run: git config --global --add safe.directory ${GITHUB_WORKSPACE}
51+
52+
- name: Run matrix job
53+
env:
54+
COMMAND: ${{ inputs.matrix_linux_command }}
55+
EXAMPLE: ${{ matrix.examples }}
56+
run: |
57+
.github/workflows/scripts/integration_tests.sh
58+
59+
playground-backend:
60+
runs-on: ubuntu-latest
61+
steps:
62+
- name: Checkout repository
63+
uses: actions/checkout@v4
64+
- name: Web playground backend build
65+
working-directory: Examples/web-playground/backend
66+
run: swift build
67+
68+
check-foundation:
69+
name: No dependencies on Foundation
70+
if: ${{ inputs.check_foundation_enabled }}
71+
runs-on: ubuntu-latest
72+
steps:
73+
- name: Checkout repository
74+
uses: actions/checkout@v4
75+
- name: Mark the workspace as safe
76+
# https://github.com/actions/checkout/issues/766
77+
run: git config --global --add safe.directory ${GITHUB_WORKSPACE}
78+
- name: Check for Foundation or ICU dependency
79+
run: |
80+
.github/workflows/scripts/check-link-foundation.sh

.github/workflows/pull_request.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Build, tests & soundness checks
2+
3+
on: [pull_request, workflow_dispatch]
4+
5+
jobs:
6+
swift-bedrock-library:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- name: Checkout repository
10+
uses: actions/checkout@v4
11+
- name: Run tests
12+
run: swift test
13+
14+
soundness:
15+
name: Soundness
16+
uses: swiftlang/github-workflows/.github/workflows/soundness.yml@main
17+
with:
18+
license_header_check_enabled: true
19+
license_header_check_project_name: "Swift Bedrock Library"
20+
shell_check_enabled: false
21+
python_lint_check_enabled: false
22+
api_breakage_check_enabled: false
23+
# api_breakage_check_container_image: "swift:6.1-noble"
24+
docs_check_container_image: "swift:6.1-noble"
25+
format_check_container_image: "swift:6.1-noble"
26+
yamllint_check_enabled: true
27+
28+
integration-tests:
29+
name: Integration Tests
30+
uses: ./.github/workflows/integration_tests.yml
31+
with:
32+
name: "Integration tests"
33+
examples_enabled: true
34+
matrix_linux_command: "swift build"
35+
check_foundation_enabled: true
36+
# We pass the list of examples here, but we can't pass an array as argument
37+
# Instead, we pass a String with a valid JSON array.
38+
# The workaround is mentioned here https://github.com/orgs/community/discussions/11692
39+
examples: "[ 'converse', 'converse-stream' ]"
40+
41+
swift-6-language-mode:
42+
name: Swift 6 Language Mode
43+
uses: ./.github/workflows/swift-6-language-mode.yml
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/bin/bash
2+
##===----------------------------------------------------------------------===##
3+
##
4+
## This source file is part of the Swift Bedrock Library open source project
5+
##
6+
## Copyright (c) 2025 Amazon.com, Inc. or its affiliates
7+
## and the Swift Bedrock Library project authors
8+
## Licensed under Apache License v2.0
9+
##
10+
## See LICENSE.txt for license information
11+
## See CONTRIBUTORS.txt for the list of Swift Bedrock Library project authors
12+
##
13+
## SPDX-License-Identifier: Apache-2.0
14+
##
15+
##===----------------------------------------------------------------------===##
16+
17+
log() { printf -- "** %s\n" "$*" >&2; }
18+
error() { printf -- "** ERROR: %s\n" "$*" >&2; }
19+
fatal() { error "$@"; exit 1; }
20+
21+
EXAMPLE=converse
22+
OUTPUT_DIR=.build/release
23+
OUTPUT_FILE=${OUTPUT_DIR}/converse
24+
LIBS_TO_CHECK="libFoundation.so libFoundationInternationalization.so lib_FoundationICU.so"
25+
26+
pushd Examples/${EXAMPLE} || fatal "Failed to change directory to Examples/${EXAMPLE}."
27+
28+
# recompile the example without the --static-swift-stdlib flag
29+
LAMBDA_USE_LOCAL_DEPS=../.. swift build -c release -Xlinker -s || fatal "Failed to build the example."
30+
31+
# check if the binary exists
32+
if [ ! -f "${OUTPUT_FILE}" ]; then
33+
error "${OUTPUT_FILE} does not exist."
34+
fi
35+
36+
# Checking for Foundation or ICU dependencies
37+
echo "Checking for Foundation or ICU dependencies in ${OUTPUT_DIR}/${OUTPUT_FILE}."
38+
LIBRARIES=$(ldd ${OUTPUT_FILE} | awk '{print $1}')
39+
for LIB in ${LIBS_TO_CHECK}; do
40+
echo -n "Checking for ${LIB}... "
41+
42+
# check if the binary has a dependency on Foundation or ICU
43+
echo "${LIBRARIES}" | grep "${LIB}" # return 1 if not found
44+
45+
# 1 is success (grep failed to find the lib), 0 is failure (grep successly found the lib)
46+
SUCCESS=$?
47+
if [ "$SUCCESS" -eq 0 ]; then
48+
log "${LIB} found." && break
49+
else
50+
log "${LIB} not found."
51+
fi
52+
done
53+
54+
popd || fatal "Failed to change directory back to the root directory."
55+
56+
# exit code is the opposite of the grep exit code
57+
if [ "$SUCCESS" -eq 0 ]; then
58+
fatal "❌ At least one foundation lib was found, reporting the error."
59+
else
60+
log "✅ No foundation lib found, congrats!" && exit 0
61+
fi
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/bin/bash
2+
##===----------------------------------------------------------------------===##
3+
##
4+
## This source file is part of the Swift Bedrock Library open source project
5+
##
6+
## Copyright (c) 2025 Amazon.com, Inc. or its affiliates
7+
## and the Swift Bedrock Library project authors
8+
## Licensed under Apache License v2.0
9+
##
10+
## See LICENSE.txt for license information
11+
## See CONTRIBUTORS.txt for the list of Swift Bedrock Library project authors
12+
##
13+
## SPDX-License-Identifier: Apache-2.0
14+
##
15+
##===----------------------------------------------------------------------===##
16+
17+
set -euo pipefail
18+
19+
log() { printf -- "** %s\n" "$*" >&2; }
20+
error() { printf -- "** ERROR: %s\n" "$*" >&2; }
21+
fatal() { error "$@"; exit 1; }
22+
23+
SWIFT_VERSION=$(swift --version)
24+
test -n "${SWIFT_VERSION:-}" || fatal "SWIFT_VERSION unset"
25+
test -n "${COMMAND:-}" || fatal "COMMAND unset"
26+
test -n "${EXAMPLE:-}" || fatal "EXAMPLE unset"
27+
28+
pushd Examples/"$EXAMPLE" > /dev/null
29+
30+
log "Running command with Swift $SWIFT_VERSION"
31+
eval "$COMMAND"
32+
33+
popd
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Swift 6 language mode
2+
3+
on:
4+
workflow_call:
5+
6+
# We are cancelling previously triggered workflow runs
7+
concurrency:
8+
group: ${{ github.workflow }}-${{ github.ref }}-swift-6-language-mode
9+
cancel-in-progress: true
10+
11+
jobs:
12+
swift-6-language-mode:
13+
name: Swift 6 language mode
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout repository
17+
uses: actions/checkout@v4
18+
with:
19+
persist-credentials: false
20+
submodules: true
21+
- name: Set the language mode
22+
run: swift package tools-version --set 6.0
23+
- name: Build with Swift 6 language mode
24+
run: swift build -Xswiftc -warnings-as-errors

Examples/converse-stream/Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version: 6.1
1+
// swift-tools-version: 6.0
22
// The swift-tools-version declares the minimum version of Swift required to build this package.
33

44
import PackageDescription

Examples/converse/Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version: 6.1
1+
// swift-tools-version: 6.0
22
// The swift-tools-version declares the minimum version of Swift required to build this package.
33

44
import PackageDescription

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version: 6.1
1+
// swift-tools-version: 6.0
22
// The swift-tools-version declares the minimum version of Swift required to build this package.
33

44
import PackageDescription

0 commit comments

Comments
 (0)