Skip to content

Commit 77b6407

Browse files
committed
improve ci
1 parent 76ad933 commit 77b6407

File tree

6 files changed

+268
-35
lines changed

6 files changed

+268
-35
lines changed

.github/workflows/build_soundness.yml

Lines changed: 0 additions & 35 deletions
This file was deleted.
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
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+
matrix_linux_swift_container_image:
31+
type: string
32+
description: "Container image for the matrix job. Defaults to matching Swift 6.1 Ubuntu image."
33+
default: "swiftlang/swift:6.1-noble"
34+
35+
## We are cancelling previously triggered workflow runs
36+
concurrency:
37+
group: ${{ github.workflow }}-${{ github.ref }}-${{ inputs.name }}
38+
cancel-in-progress: true
39+
40+
jobs:
41+
test-examples:
42+
name: Test Examples/${{ matrix.examples }} on ${{ matrix.swift.swift_version }}
43+
if: ${{ inputs.examples_enabled }}
44+
runs-on: ubuntu-latest
45+
strategy:
46+
fail-fast: false
47+
matrix:
48+
examples: ${{ fromJson(inputs.examples) }}
49+
50+
# We are using only one Swift version
51+
swift:
52+
- image: ${{ inputs.matrix_linux_swift_container_image }}
53+
container:
54+
image: ${{ matrix.swift.image }}
55+
steps:
56+
57+
- name: Checkout repository
58+
uses: actions/checkout@v4
59+
60+
- name: Mark the workspace as safe
61+
working-directory: ${{ github.event.repository.name }} # until we can use action/checkout@v4
62+
# https://github.com/actions/checkout/issues/766
63+
run: git config --global --add safe.directory ${GITHUB_WORKSPACE}
64+
65+
- name: Run matrix job
66+
working-directory: ${{ github.event.repository.name }} # until we can use action/checkout@v4
67+
env:
68+
COMMAND: ${{ inputs.matrix_linux_command }}
69+
EXAMPLE: ${{ matrix.examples }}
70+
run: |
71+
.github/workflows/scripts/integration_tests.sh
72+
73+
playground-backend:
74+
runs-on: ubuntu-latest
75+
steps:
76+
- name: Checkout repository
77+
uses: actions/checkout@v4
78+
- name: Web playground backend build
79+
working-directory: Examples/web-playground/backend
80+
run: swift build
81+
82+
check-foundation:
83+
name: No dependencies on Foundation
84+
if: ${{ inputs.check_foundation_enabled }}
85+
runs-on: ubuntu-latest
86+
steps:
87+
- name: Install OS dependencies
88+
run: |
89+
apt-get update
90+
apt-get install openssl libssl-dev
91+
- name: Checkout repository
92+
uses: actions/checkout@v4
93+
with:
94+
persist-credentials: false
95+
- name: Mark the workspace as safe
96+
# https://github.com/actions/checkout/issues/766
97+
run: git config --global --add safe.directory ${GITHUB_WORKSPACE}
98+
- name: Check for Foundation or ICU dependency
99+
run: |
100+
.github/workflows/scripts/check-link-foundation.sh

.github/workflows/pull_request.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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', 'ConverseStream' ]"
40+
41+
swift-6-language-mode:
42+
name: Swift 6 Language Mode
43+
uses: ./.github/workflows/swift-6-language-mode.yml
44+
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: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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+
# container:
16+
# image: swift:6.1-noble
17+
steps:
18+
# - name: Install OS dependencies
19+
# run: |
20+
# apt-get update
21+
# apt-get install openssl libssl-dev
22+
- name: Checkout repository
23+
uses: actions/checkout@v4
24+
with:
25+
persist-credentials: false
26+
submodules: true
27+
- name: Set the language mode
28+
run: swift package tools-version --set 6.0
29+
- name: Build with Swift 6 language mode
30+
run: swift build -Xswiftc -warnings-as-errors

0 commit comments

Comments
 (0)