From 576602bcefa5fbe7445db590afde46990dd38681 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Stormacq?= <sebastien.stormacq@gmail.com> Date: Tue, 15 Oct 2024 16:40:48 +0200 Subject: [PATCH 01/15] add a github action --- .github/workflows/pull_request.yaml | 32 +++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 .github/workflows/pull_request.yaml diff --git a/.github/workflows/pull_request.yaml b/.github/workflows/pull_request.yaml new file mode 100644 index 0000000..bf00832 --- /dev/null +++ b/.github/workflows/pull_request.yaml @@ -0,0 +1,32 @@ +# This workflow will build a Swift project on macOS and Linux +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-swift +name: swift-openapi-lambda-build + +on: + push: + branches: [ "main" ] + pull_request: + types: [opened, reopened, synchronize] + +jobs: + build-macos: + env: + # https://github.com/actions/runner-images/tree/main/images/macos + DEVELOPER_DIR: /Applications/Xcode_16.app/Contents/Developer + + runs-on: macos-15-arm64 + # runs-on: macos-15 + steps: + - uses: actions/checkout@v4 + - name: Build + run: swift build -v + - name: Run tests + run: swift test -v + build-linux: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Build + run: swift build -v + - name: Run tests + run: swift test -v \ No newline at end of file From cc0ec86713b44f9ca190d42e46a98895f84b37b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Stormacq?= <sebastien.stormacq@gmail.com> Date: Tue, 15 Oct 2024 16:49:34 +0200 Subject: [PATCH 02/15] use swiftlang CI workflow --- .github/workflows/pull_request.yaml | 45 +++++++++++++++-------------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/.github/workflows/pull_request.yaml b/.github/workflows/pull_request.yaml index bf00832..b7431c9 100644 --- a/.github/workflows/pull_request.yaml +++ b/.github/workflows/pull_request.yaml @@ -9,24 +9,27 @@ on: types: [opened, reopened, synchronize] jobs: - build-macos: - env: - # https://github.com/actions/runner-images/tree/main/images/macos - DEVELOPER_DIR: /Applications/Xcode_16.app/Contents/Developer - - runs-on: macos-15-arm64 - # runs-on: macos-15 - steps: - - uses: actions/checkout@v4 - - name: Build - run: swift build -v - - name: Run tests - run: swift test -v - build-linux: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - name: Build - run: swift build -v - - name: Run tests - run: swift test -v \ No newline at end of file + soundness: + name: Soundness + uses: swiftlang/github-workflows/.github/workflows/soundness.yml@main + with: + license_header_check_project_name: "Swift OpenAPI Lambda" + shell_check_enabled: false + python_lint_check_enabled: false + api_breakage_check_container_image: "swift:6.0-noble" + docs_check_container_image: "swift:6.0-noble" + format_check_container_image: "swiftlang/swift:nightly-6.0-jammy" + + unit-tests: + name: Unit tests + uses: apple/swift-nio/.github/workflows/unit_tests.yml@main + with: + linux_5_8_enabled: false + linux_5_9_enabled: false + linux_5_10_enabled: true + linux_nightly_6_0_arguments_override: "--explicit-target-dependency-import-check error" + linux_nightly_main_arguments_override: "--explicit-target-dependency-import-check error" + + swift-6-language-mode: + name: Swift 6 Language Mode + uses: apple/swift-nio/.github/workflows/swift_6_language_mode.yml@main \ No newline at end of file From 6bbde21cb37376a897534d7c37fdb59bf1e4f00d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Stormacq?= <sebastien.stormacq@gmail.com> Date: Tue, 15 Oct 2024 16:50:37 +0200 Subject: [PATCH 03/15] fix --- .github/workflows/pull_request.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/pull_request.yaml b/.github/workflows/pull_request.yaml index b7431c9..814bd88 100644 --- a/.github/workflows/pull_request.yaml +++ b/.github/workflows/pull_request.yaml @@ -24,7 +24,6 @@ jobs: name: Unit tests uses: apple/swift-nio/.github/workflows/unit_tests.yml@main with: - linux_5_8_enabled: false linux_5_9_enabled: false linux_5_10_enabled: true linux_nightly_6_0_arguments_override: "--explicit-target-dependency-import-check error" From f7f202752d7c2068d2f1699576118dbc6d6d7fe5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Stormacq?= <sebastien.stormacq@gmail.com> Date: Tue, 15 Oct 2024 16:52:18 +0200 Subject: [PATCH 04/15] cleanup --- docker/Dockerfile | 26 ----- docker/docker-compose.2204.510.yaml | 18 --- docker/docker-compose.2204.59.yaml | 18 --- docker/docker-compose.2204.590.yaml | 18 --- docker/docker-compose.2204.main.yaml | 18 --- docker/docker-compose.yaml | 47 -------- scripts/check-for-broken-symlinks.sh | 53 --------- scripts/check-for-docc-warnings.sh | 55 --------- scripts/check-for-unacceptable-language.sh | 53 --------- scripts/check-license-headers.sh | 123 --------------------- scripts/run-swift-format.sh | 65 ----------- scripts/soundness.sh | 71 ------------ scripts/unacceptable-language.txt | 15 --- 13 files changed, 580 deletions(-) delete mode 100644 docker/Dockerfile delete mode 100644 docker/docker-compose.2204.510.yaml delete mode 100644 docker/docker-compose.2204.59.yaml delete mode 100644 docker/docker-compose.2204.590.yaml delete mode 100644 docker/docker-compose.2204.main.yaml delete mode 100644 docker/docker-compose.yaml delete mode 100755 scripts/check-for-broken-symlinks.sh delete mode 100755 scripts/check-for-docc-warnings.sh delete mode 100755 scripts/check-for-unacceptable-language.sh delete mode 100755 scripts/check-license-headers.sh delete mode 100755 scripts/run-swift-format.sh delete mode 100755 scripts/soundness.sh delete mode 100755 scripts/unacceptable-language.txt diff --git a/docker/Dockerfile b/docker/Dockerfile deleted file mode 100644 index 5040ad9..0000000 --- a/docker/Dockerfile +++ /dev/null @@ -1,26 +0,0 @@ -ARG swift_version=5.9 -ARG ubuntu_version=jammy -ARG base_image=swift:${swift_version}-${ubuntu_version} - -FROM ${base_image} -ARG swift_version -ARG ubuntu_version - -# set as UTF-8 -RUN apt-get update && apt-get install -y locales locales-all -ENV LC_ALL en_US.UTF-8 -ENV LANG en_US.UTF-8 -ENV LANGUAGE en_US.UTF-8 - -# tools -RUN mkdir -p $HOME/.tools -RUN echo 'export PATH="$HOME/.tools:$PATH"' >> $HOME/.profile - -# swift-format -ARG swiftformat_version=509.0.0 -RUN git clone --branch $swiftformat_version --depth 1 https://github.com/apple/swift-format $HOME/.tools/swift-format-source -RUN cd $HOME/.tools/swift-format-source && swift build -c release -RUN ln -s $HOME/.tools/swift-format-source/.build/release/swift-format $HOME/.tools/swift-format - -# jq -RUN apt-get install -y jq diff --git a/docker/docker-compose.2204.510.yaml b/docker/docker-compose.2204.510.yaml deleted file mode 100644 index 22c3ba8..0000000 --- a/docker/docker-compose.2204.510.yaml +++ /dev/null @@ -1,18 +0,0 @@ -version: "3" - -services: - runtime-setup: - image: &image swift-openapi-lambda:22.04-5.10 - build: - args: - ubuntu_version: "jammy" - swift_version: "5.10" - - test: - image: *image - - shell: - image: *image - - soundness: - image: *image diff --git a/docker/docker-compose.2204.59.yaml b/docker/docker-compose.2204.59.yaml deleted file mode 100644 index 107b0d0..0000000 --- a/docker/docker-compose.2204.59.yaml +++ /dev/null @@ -1,18 +0,0 @@ -version: "3" - -services: - runtime-setup: - image: &image swift-openapi-lambda:22.04-5.9 - build: - args: - ubuntu_version: "jammy" - swift_version: "5.9" - - test: - image: *image - - shell: - image: *image - - soundness: - image: *image diff --git a/docker/docker-compose.2204.590.yaml b/docker/docker-compose.2204.590.yaml deleted file mode 100644 index 283d2ae..0000000 --- a/docker/docker-compose.2204.590.yaml +++ /dev/null @@ -1,18 +0,0 @@ -version: "3" - -services: - runtime-setup: - image: &image swift-openapi-lambda:22.04-5.9.0 - build: - args: - ubuntu_version: "jammy" - swift_version: "5.9.0" - - test: - image: *image - - shell: - image: *image - - soundness: - image: *image diff --git a/docker/docker-compose.2204.main.yaml b/docker/docker-compose.2204.main.yaml deleted file mode 100644 index 0152f26..0000000 --- a/docker/docker-compose.2204.main.yaml +++ /dev/null @@ -1,18 +0,0 @@ -version: "3" - -services: - - runtime-setup: - image: &image swift-openapi-lambda:22.04-main - build: - args: - base_image: "swiftlang/swift:nightly-main-jammy" - - test: - image: *image - - shell: - image: *image - - soundness: - image: *image \ No newline at end of file diff --git a/docker/docker-compose.yaml b/docker/docker-compose.yaml deleted file mode 100644 index c9c6706..0000000 --- a/docker/docker-compose.yaml +++ /dev/null @@ -1,47 +0,0 @@ -# NOTE: This file is not designed to be run independently. -# -# Instead, use it with a file for a specific OS and Swift version, for example: -# -# % docker-compose \ -# -f docker/docker-compose.yaml \ -# -f docker/docker-compose.2204.59.yaml \ -# run test -# -version: "3" - -services: - runtime-setup: - image: &image swift-openapi-lambda:default - build: - context: . - dockerfile: Dockerfile - - common: &common - image: *image - depends_on: [runtime-setup] - volumes: - - ~/.ssh:/root/.ssh - - ..:/code:z - working_dir: /code - - soundness: - <<: *common - command: /bin/bash -xcl "swift -version && uname -a && ./scripts/soundness.sh" - - test: - <<: *common - command: /bin/bash -xcl "swift test" - - shell: - <<: *common - entrypoint: /bin/bash - - compatibility-test: - <<: *common - command: /bin/bash -xcl "cat /proc/cpuinfo && cat /proc/meminfo && swift test" - - docc-test: - <<: *common - command: /bin/bash -xcl "swift -version && uname -a && bash ./scripts/check-for-docc-warnings.sh" - environment: - DOCC_TARGET: OpenAPILambda diff --git a/scripts/check-for-broken-symlinks.sh b/scripts/check-for-broken-symlinks.sh deleted file mode 100755 index 4f14f98..0000000 --- a/scripts/check-for-broken-symlinks.sh +++ /dev/null @@ -1,53 +0,0 @@ -#!/usr/bin/env bash -##===----------------------------------------------------------------------===## -## -## This source file is part of the Swift OpenAPI Lambda open source project -## -## Copyright (c) 2023 Amazon.com, Inc. or its affiliates -## and the Swift OpenAPI Lambda project authors -## Licensed under Apache License v2.0 -## -## See LICENSE.txt for license information -## See CONTRIBUTORS.txt for the list of Swift OpenAPI Lambda project authors -## -## SPDX-License-Identifier: Apache-2.0 -## -##===----------------------------------------------------------------------===## - -##===----------------------------------------------------------------------===## -## -## 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; } - -CURRENT_SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -REPO_ROOT="$(git -C "${CURRENT_SCRIPT_DIR}" rev-parse --show-toplevel)" - -log "Checking for broken symlinks..." -NUM_BROKEN_SYMLINKS=0 -while read -r -d '' file; do - if ! test -e "${REPO_ROOT}/${file}"; then - error "Broken symlink: ${file}" - ((NUM_BROKEN_SYMLINKS++)) - fi -done < <(git -C "${REPO_ROOT}" ls-files -z) - -if [ "${NUM_BROKEN_SYMLINKS}" -gt 0 ]; then - fatal "❌ Found ${NUM_BROKEN_SYMLINKS} symlinks." -fi - -log "✅ Found 0 symlinks." diff --git a/scripts/check-for-docc-warnings.sh b/scripts/check-for-docc-warnings.sh deleted file mode 100755 index 6b04103..0000000 --- a/scripts/check-for-docc-warnings.sh +++ /dev/null @@ -1,55 +0,0 @@ -#!/usr/bin/env bash -##===----------------------------------------------------------------------===## -## -## This source file is part of the Swift OpenAPI Lambda open source project -## -## Copyright (c) 2023 Amazon.com, Inc. or its affiliates -## and the Swift OpenAPI Lambda project authors -## Licensed under Apache License v2.0 -## -## See LICENSE.txt for license information -## See CONTRIBUTORS.txt for the list of Swift OpenAPI Lambda project authors -## -## SPDX-License-Identifier: Apache-2.0 -## -##===----------------------------------------------------------------------===## - -##===----------------------------------------------------------------------===## -## -## 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 environment variables..." -test -n "${DOCC_TARGET:-}" || fatal "DOCC_TARGET unset" - -CURRENT_SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -REPO_ROOT="$(git -C "${CURRENT_SCRIPT_DIR}" rev-parse --show-toplevel)" - -# --warnings-as-errors \ -swift package --package-path "${REPO_ROOT}" plugin generate-documentation \ - --product "${DOCC_TARGET}" \ - --analyze \ - --level detailed \ - && DOCC_PLUGIN_RC=$? || DOCC_PLUGIN_RC=$? - -if [ "${DOCC_PLUGIN_RC}" -ne 0 ]; then - fatal "❌ Generating documentation produced warnings and/or errors." - exit "${DOCC_PLUGIN_RC}" -fi - -log "✅ Generated documentation with no warnings." diff --git a/scripts/check-for-unacceptable-language.sh b/scripts/check-for-unacceptable-language.sh deleted file mode 100755 index d33ec33..0000000 --- a/scripts/check-for-unacceptable-language.sh +++ /dev/null @@ -1,53 +0,0 @@ -#!/usr/bin/env bash -##===----------------------------------------------------------------------===## -## -## This source file is part of the Swift OpenAPI Lambda open source project -## -## Copyright (c) 2023 Amazon.com, Inc. or its affiliates -## and the Swift OpenAPI Lambda project authors -## Licensed under Apache License v2.0 -## -## See LICENSE.txt for license information -## See CONTRIBUTORS.txt for the list of Swift OpenAPI Lambda project authors -## -## SPDX-License-Identifier: Apache-2.0 -## -##===----------------------------------------------------------------------===## - -##===----------------------------------------------------------------------===## -## -## 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; } - -CURRENT_SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -REPO_ROOT="$(git -C "${CURRENT_SCRIPT_DIR}" rev-parse --show-toplevel)" -UNACCEPTABLE_LANGUAGE_PATTERNS_PATH="${CURRENT_SCRIPT_DIR}/unacceptable-language.txt" - -log "Checking for unacceptable language..." -PATHS_WITH_UNACCEPTABLE_LANGUAGE=$(git -C "${REPO_ROOT}" grep \ - -l -F -w \ - -f "${UNACCEPTABLE_LANGUAGE_PATTERNS_PATH}" \ - -- \ - ":(exclude)${UNACCEPTABLE_LANGUAGE_PATTERNS_PATH}" \ -) || true | /usr/bin/paste -s -d " " - - -if [ -n "${PATHS_WITH_UNACCEPTABLE_LANGUAGE}" ]; then - fatal "❌ Found unacceptable language in files: ${PATHS_WITH_UNACCEPTABLE_LANGUAGE}." -fi - -log "✅ Found no unacceptable language." diff --git a/scripts/check-license-headers.sh b/scripts/check-license-headers.sh deleted file mode 100755 index 0ac57b6..0000000 --- a/scripts/check-license-headers.sh +++ /dev/null @@ -1,123 +0,0 @@ -#!/usr/bin/env bash -##===----------------------------------------------------------------------===## -## -## This source file is part of the Swift OpenAPI Lambda open source project -## -## Copyright (c) 2023 Amazon.com, Inc. or its affiliates -## and the Swift OpenAPI Lambda project authors -## Licensed under Apache License v2.0 -## -## See LICENSE.txt for license information -## See CONTRIBUTORS.txt for the list of Swift OpenAPI Lambda project authors -## -## SPDX-License-Identifier: Apache-2.0 -## -##===----------------------------------------------------------------------===## - -##===----------------------------------------------------------------------===## -## -## 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; } - -CURRENT_SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -REPO_ROOT="$(git -C "${CURRENT_SCRIPT_DIR}" rev-parse --show-toplevel)" - -EXPECTED_FILE_HEADER_TEMPLATE="@@===----------------------------------------------------------------------===@@ -@@ -@@ This source file is part of the Swift OpenAPI Lambda open source project -@@ -@@ Copyright (c) YEARS Amazon.com, Inc. or its affiliates -@@ and the Swift OpenAPI Lambda project authors -@@ Licensed under Apache License v2.0 -@@ -@@ See LICENSE.txt for license information -@@ See CONTRIBUTORS.txt for the list of Swift OpenAPI Lambda project authors -@@ -@@ SPDX-License-Identifier: Apache-2.0 -@@ -@@===----------------------------------------------------------------------===@@" - -PATHS_WITH_MISSING_LICENSE=( ) - -read -ra PATHS_TO_CHECK_FOR_LICENSE <<< "$( \ - git -C "${REPO_ROOT}" ls-files -z \ - ":(exclude).gitignore" \ - ":(exclude).spi.yml" \ - ":(exclude).swift-format" \ - ":(exclude).github/*" \ - ":(exclude)CODE_OF_CONDUCT.md" \ - ":(exclude)CONTRIBUTING.md" \ - ":(exclude)CONTRIBUTORS.txt" \ - ":(exclude)LICENSE.txt" \ - ":(exclude)NOTICE.txt" \ - ":(exclude)Package.swift" \ - ":(exclude)Package.resolved" \ - ":(exclude)README.md" \ - ":(exclude)SECURITY.md" \ - ":(exclude)scripts/unacceptable-language.txt" \ - ":(exclude)docker/*" \ - ":(exclude)**/*.docc/*" \ - ":(exclude)**/.gitignore" \ - ":(exclude)**/Package.swift" \ - ":(exclude)**/Package.resolved" \ - ":(exclude)**/README.md" \ - ":(exclude)**/openapi.yaml" \ - ":(exclude)**/openapi.yml" \ - ":(exclude)**/openapi-generator-config.yaml" \ - ":(exclude)**/openapi-generator-config.yml" \ - ":(exclude)**/docker-compose.yaml" \ - ":(exclude)**/docker/*" \ - ":(exclude)**/.dockerignore" \ - ":(exclude)**/Makefile" \ - ":(exclude)**/*.html" \ - ":(exclude)**/*.gif" \ - ":(exclude)**/*.json" \ - | xargs -0 \ -)" - -for FILE_PATH in "${PATHS_TO_CHECK_FOR_LICENSE[@]}"; do - FILE_BASENAME=$(basename -- "${FILE_PATH}") - FILE_EXTENSION="${FILE_BASENAME##*.}" - - case "${FILE_EXTENSION}" in - swift) EXPECTED_FILE_HEADER=$(sed -e 's|@@|//|g' <<<"${EXPECTED_FILE_HEADER_TEMPLATE}") ;; - yml) EXPECTED_FILE_HEADER=$(sed -e 's|@@|##|g' <<<"${EXPECTED_FILE_HEADER_TEMPLATE}") ;; - sh) EXPECTED_FILE_HEADER=$(cat <(echo '#!/usr/bin/env bash') <(sed -e 's|@@|##|g' <<<"${EXPECTED_FILE_HEADER_TEMPLATE}")) ;; - *) fatal "Unsupported file extension for file (exclude or update this script): ${FILE_PATH}" ;; - esac - EXPECTED_FILE_HEADER_LINECOUNT=$(wc -l <<<"${EXPECTED_FILE_HEADER}") - - FILE_HEADER=$(head -n "${EXPECTED_FILE_HEADER_LINECOUNT}" "${FILE_PATH}") - NORMALIZED_FILE_HEADER=$( - echo "${FILE_HEADER}" \ - | sed -e 's/202[3]-202[3]/YEARS/' -e 's/202[3]/YEARS/' \ - ) - - if ! diff -u \ - --label "Expected header" <(echo "${EXPECTED_FILE_HEADER}") \ - --label "${FILE_PATH}" <(echo "${NORMALIZED_FILE_HEADER}") - then - PATHS_WITH_MISSING_LICENSE+=("${FILE_PATH} ") - fi -done - -if [ "${#PATHS_WITH_MISSING_LICENSE[@]}" -gt 0 ]; then - fatal "❌ Found missing license header in files: ${PATHS_WITH_MISSING_LICENSE[*]}." -fi - -log "✅ Found no files with missing license header." diff --git a/scripts/run-swift-format.sh b/scripts/run-swift-format.sh deleted file mode 100755 index 20a8698..0000000 --- a/scripts/run-swift-format.sh +++ /dev/null @@ -1,65 +0,0 @@ -#!/usr/bin/env bash -##===----------------------------------------------------------------------===## -## -## This source file is part of the Swift OpenAPI Lambda open source project -## -## Copyright (c) 2023 Amazon.com, Inc. or its affiliates -## and the Swift OpenAPI Lambda project authors -## Licensed under Apache License v2.0 -## -## See LICENSE.txt for license information -## See CONTRIBUTORS.txt for the list of Swift OpenAPI Lambda project authors -## -## SPDX-License-Identifier: Apache-2.0 -## -##===----------------------------------------------------------------------===## - -##===----------------------------------------------------------------------===## -## -## 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; } - -CURRENT_SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -REPO_ROOT="$(git -C "${CURRENT_SCRIPT_DIR}" rev-parse --show-toplevel)" - -FORMAT_COMMAND=(lint --strict) -for arg in "$@"; do - if [ "$arg" == "--fix" ]; then - FORMAT_COMMAND=(format --in-place) - fi -done - -SWIFTFORMAT_BIN=${SWIFTFORMAT_BIN:-$(command -v swift-format)} || fatal "❌ SWIFTFORMAT_BIN unset and no swift-format on PATH" - -"${SWIFTFORMAT_BIN}" lint \ - --parallel --recursive --strict \ - "${REPO_ROOT}/Sources" \ - "${REPO_ROOT}/Tests" \ - && SWIFT_FORMAT_RC=$? || SWIFT_FORMAT_RC=$? - -if [ "${SWIFT_FORMAT_RC}" -ne 0 ]; then - fatal "❌ Running swift-format produced errors. - - To fix, run the following command: - - % swift-format format --parallel --recursive --in-place Sources Tests - " - exit "${SWIFT_FORMAT_RC}" -fi - -log "✅ Ran swift-format with no errors." diff --git a/scripts/soundness.sh b/scripts/soundness.sh deleted file mode 100755 index 7bf7f16..0000000 --- a/scripts/soundness.sh +++ /dev/null @@ -1,71 +0,0 @@ -#!/usr/bin/env bash -##===----------------------------------------------------------------------===## -## -## This source file is part of the Swift OpenAPI Lambda open source project -## -## Copyright (c) 2023 Amazon.com, Inc. or its affiliates -## and the Swift OpenAPI Lambda project authors -## Licensed under Apache License v2.0 -## -## See LICENSE.txt for license information -## See CONTRIBUTORS.txt for the list of Swift OpenAPI Lambda project authors -## -## SPDX-License-Identifier: Apache-2.0 -## -##===----------------------------------------------------------------------===## - -##===----------------------------------------------------------------------===## -## -## 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; } - -CURRENT_SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -NUM_CHECKS_FAILED=0 - -FIX_FORMAT="" -for arg in "$@"; do - if [ "$arg" == "--fix" ]; then - FIX_FORMAT="--fix" - fi -done - -SCRIPT_PATHS=( - "${CURRENT_SCRIPT_DIR}/check-for-broken-symlinks.sh" - "${CURRENT_SCRIPT_DIR}/check-for-unacceptable-language.sh" - "${CURRENT_SCRIPT_DIR}/check-license-headers.sh" -) - -for SCRIPT_PATH in "${SCRIPT_PATHS[@]}"; do - log "Running ${SCRIPT_PATH}..." - if ! bash "${SCRIPT_PATH}"; then - ((NUM_CHECKS_FAILED+=1)) - fi -done - -log "Running swift-format..." -bash "${CURRENT_SCRIPT_DIR}"/run-swift-format.sh $FIX_FORMAT > /dev/null -FORMAT_EXIT_CODE=$? -if [ $FORMAT_EXIT_CODE -ne 0 ]; then - ((NUM_CHECKS_FAILED+=1)) -fi - -if [ "${NUM_CHECKS_FAILED}" -gt 0 ]; then - fatal "❌ ${NUM_CHECKS_FAILED} soundness check(s) failed." -fi - -log "✅ All soundness check(s) passed." diff --git a/scripts/unacceptable-language.txt b/scripts/unacceptable-language.txt deleted file mode 100755 index 6ac4a98..0000000 --- a/scripts/unacceptable-language.txt +++ /dev/null @@ -1,15 +0,0 @@ -blacklist -whitelist -slave -master -sane -sanity -insane -insanity -kill -killed -killing -hang -hung -hanged -hanging From bc2c501eef9d0022d9188ccdbcf2ddff5bfc29e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Stormacq?= <sebastien.stormacq@gmail.com> Date: Tue, 15 Oct 2024 16:52:51 +0200 Subject: [PATCH 05/15] add license ignore --- .licenseignore | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 .licenseignore diff --git a/.licenseignore b/.licenseignore new file mode 100644 index 0000000..796c53d --- /dev/null +++ b/.licenseignore @@ -0,0 +1,34 @@ +.gitignore +.licenseignore +.swiftformatignore +.spi.yml +.swift-format +.github/* +*.md +**/*.md +CONTRIBUTORS.txt +LICENSE.txt +NOTICE.txt +Package.swift +Package@swift-*.swift +Package.resolved +**/*.docc/* +**/.gitignore +**/Package.swift +**/Package.resolved +**/docker-compose*.yaml +**/docker/* +**/.dockerignore +**/Dockerfile +**/Makefile +**/*.html +**/*-template.yml +**/*.xcworkspace/* +**/*.xcodeproj/* +**/*.xcassets/* +**/*.appiconset/* +**/ResourcePackaging/hello.txt +.mailmap +.swiftformat +*.yaml +*.yml From a66c08ecd852cd13818ccb411354305701110386 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Stormacq?= <sebastien.stormacq@gmail.com> Date: Tue, 15 Oct 2024 16:56:08 +0200 Subject: [PATCH 06/15] fix yaml lint --- .github/workflows/pull_request.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/pull_request.yaml b/.github/workflows/pull_request.yaml index 814bd88..21c7a70 100644 --- a/.github/workflows/pull_request.yaml +++ b/.github/workflows/pull_request.yaml @@ -1,10 +1,10 @@ -# This workflow will build a Swift project on macOS and Linux +# This workflow will build a Swift project on macOS and Linux # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-swift name: swift-openapi-lambda-build on: push: - branches: [ "main" ] + branches: ["main"] pull_request: types: [opened, reopened, synchronize] @@ -31,4 +31,4 @@ jobs: swift-6-language-mode: name: Swift 6 Language Mode - uses: apple/swift-nio/.github/workflows/swift_6_language_mode.yml@main \ No newline at end of file + uses: apple/swift-nio/.github/workflows/swift_6_language_mode.yml@main From 38d61cbf5a0c6871923a4609e45100329e900eaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Stormacq?= <sebastien.stormacq@gmail.com> Date: Tue, 15 Oct 2024 19:05:49 +0200 Subject: [PATCH 07/15] fix license --- .github/workflows/pull_request.yaml | 3 +- scripts/check-license-header.sh | 99 +++++++++++++++++++++++++++ scripts/generate-contributors-list.sh | 2 +- 3 files changed, 102 insertions(+), 2 deletions(-) create mode 100755 scripts/check-license-header.sh diff --git a/.github/workflows/pull_request.yaml b/.github/workflows/pull_request.yaml index 21c7a70..3da3278 100644 --- a/.github/workflows/pull_request.yaml +++ b/.github/workflows/pull_request.yaml @@ -13,7 +13,8 @@ jobs: name: Soundness uses: swiftlang/github-workflows/.github/workflows/soundness.yml@main with: - license_header_check_project_name: "Swift OpenAPI Lambda" + # do not use SwiftLang's license header check because the copyright for this project is Amazon.com + contributors + license_header_check_enabled: false shell_check_enabled: false python_lint_check_enabled: false api_breakage_check_container_image: "swift:6.0-noble" diff --git a/scripts/check-license-header.sh b/scripts/check-license-header.sh new file mode 100755 index 0000000..ddaf852 --- /dev/null +++ b/scripts/check-license-header.sh @@ -0,0 +1,99 @@ +#!/bin/bash +##===----------------------------------------------------------------------===## +## +## This source file is part of the Swift OpenAPI Lambda open source project +## +## Copyright (c) 2023 Amazon.com, Inc. or its affiliates +## and the Swift OpenAPI Lambda project authors +## Licensed under Apache License v2.0 +## +## See LICENSE.txt for license information +## See CONTRIBUTORS.txt for the list of Swift OpenAPI Lambda project authors +## +## SPDX-License-Identifier: Apache-2.0 +## +##===----------------------------------------------------------------------===## + +# ===----------------------------------------------------------------------===// +# +# This source file is part of the Swift.org open source project +# +# Copyright (c) 2024 Apple Inc. and the Swift project authors +# Licensed under Apache License v2.0 with Runtime Library Exception +# +# See https://swift.org/LICENSE.txt for license information +# See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors +# +# ===----------------------------------------------------------------------===// + +set -euo pipefail + +log() { printf -- "** %s\n" "$*" >&2; } +error() { printf -- "** ERROR: %s\n" "$*" >&2; } +fatal() { error "$@"; exit 1; } + +test -n "${PROJECT_NAME:-}" || fatal "PROJECT_NAME unset" + +expected_file_header_template="@@===----------------------------------------------------------------------===@@ +@@ +@@ This source file is part of the ${PROJECT_NAME} open source project +@@ +@@ Copyright (c) YEARS Amazon.com, Inc. or its affiliates +@@ and the ${PROJECT_NAME} project authors +@@ Licensed under Apache License v2.0 +@@ +@@ See LICENSE.txt for license information +@@ See CONTRIBUTORS.txt for the list of ${PROJECT_NAME} project authors +@@ +@@ SPDX-License-Identifier: Apache-2.0 +@@ +@@===----------------------------------------------------------------------===@@" + +paths_with_missing_license=( ) + +file_paths=$(tr '\n' '\0' < .licenseignore | xargs -0 -I% printf '":(exclude)%" '| xargs git ls-files) + +while IFS= read -r file_path; do + file_basename=$(basename -- "${file_path}") + file_extension="${file_basename##*.}" + + # shellcheck disable=SC2001 # We prefer to use sed here instead of bash search/replace + case "${file_extension}" in + swift) expected_file_header=$(sed -e 's|@@|//|g' <<<"${expected_file_header_template}") ;; + h) expected_file_header=$(sed -e 's|@@|//|g' <<<"${expected_file_header_template}") ;; + c) expected_file_header=$(sed -e 's|@@|//|g' <<<"${expected_file_header_template}") ;; + sh) expected_file_header=$(cat <(echo '#!/bin/bash') <(sed -e 's|@@|##|g' <<<"${expected_file_header_template}")) ;; + kts) expected_file_header=$(sed -e 's|@@|//|g' <<<"${expected_file_header_template}") ;; + gradle) expected_file_header=$(sed -e 's|@@|//|g' <<<"${expected_file_header_template}") ;; + groovy) expected_file_header=$(sed -e 's|@@|//|g' <<<"${expected_file_header_template}") ;; + java) expected_file_header=$(sed -e 's|@@|//|g' <<<"${expected_file_header_template}") ;; + py) expected_file_header=$(cat <(echo '#!/usr/bin/env python3') <(sed -e 's|@@|##|g' <<<"${expected_file_header_template}")) ;; + rb) expected_file_header=$(cat <(echo '#!/usr/bin/env ruby') <(sed -e 's|@@|##|g' <<<"${expected_file_header_template}")) ;; + in) expected_file_header=$(sed -e 's|@@|##|g' <<<"${expected_file_header_template}") ;; + cmake) expected_file_header=$(sed -e 's|@@|##|g' <<<"${expected_file_header_template}") ;; + *) + error "Unsupported file extension ${file_extension} for file (exclude or update this script): ${file_path}" + paths_with_missing_license+=("${file_path} ") + ;; + esac + expected_file_header_linecount=$(wc -l <<<"${expected_file_header}") + + file_header=$(head -n "${expected_file_header_linecount}" "${file_path}") + normalized_file_header=$( + echo "${file_header}" \ + | sed -e 's/20[12][0123456789]-20[12][0123456789]/YEARS/' -e 's/20[12][0123456789]/YEARS/' \ + ) + + if ! diff -u \ + --label "Expected header" <(echo "${expected_file_header}") \ + --label "${file_path}" <(echo "${normalized_file_header}") + then + paths_with_missing_license+=("${file_path} ") + fi +done <<< "$file_paths" + +if [ "${#paths_with_missing_license[@]}" -gt 0 ]; then + fatal "❌ Found missing license header in files: ${paths_with_missing_license[*]}." +fi + +log "✅ Found no files with missing license header." \ No newline at end of file diff --git a/scripts/generate-contributors-list.sh b/scripts/generate-contributors-list.sh index f3bd228..724b5c3 100755 --- a/scripts/generate-contributors-list.sh +++ b/scripts/generate-contributors-list.sh @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +#!/bin/bash ##===----------------------------------------------------------------------===## ## ## This source file is part of the Swift OpenAPI Lambda open source project From ef1c60f59617da562aa0a3ab19a1b1f2b77ee92e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Stormacq?= <sebastien.stormacq@gmail.com> Date: Tue, 15 Oct 2024 19:08:44 +0200 Subject: [PATCH 08/15] add license check --- .github/workflows/pull_request.yaml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/pull_request.yaml b/.github/workflows/pull_request.yaml index 3da3278..7d1e696 100644 --- a/.github/workflows/pull_request.yaml +++ b/.github/workflows/pull_request.yaml @@ -21,6 +21,12 @@ jobs: docs_check_container_image: "swift:6.0-noble" format_check_container_image: "swiftlang/swift:nightly-6.0-jammy" + license: + name: License headers check + needs: soundness + run: | + ./scripts/check_license_headers.sh + unit-tests: name: Unit tests uses: apple/swift-nio/.github/workflows/unit_tests.yml@main From cea0c3bb54c0a5b02922798436feb68be30ddc32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Stormacq?= <sebastien.stormacq@gmail.com> Date: Tue, 15 Oct 2024 19:09:52 +0200 Subject: [PATCH 09/15] fix --- .github/workflows/pull_request.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/pull_request.yaml b/.github/workflows/pull_request.yaml index 7d1e696..6a1bc6d 100644 --- a/.github/workflows/pull_request.yaml +++ b/.github/workflows/pull_request.yaml @@ -15,6 +15,7 @@ jobs: with: # do not use SwiftLang's license header check because the copyright for this project is Amazon.com + contributors license_header_check_enabled: false + license_header_check_project_name: "Swift OpenAPI Lambda" shell_check_enabled: false python_lint_check_enabled: false api_breakage_check_container_image: "swift:6.0-noble" From 68dfb9e4a8c850b32c9ab8fd6ceb20dee6b23212 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Stormacq?= <sebastien.stormacq@gmail.com> Date: Tue, 15 Oct 2024 19:11:47 +0200 Subject: [PATCH 10/15] fix --- .github/workflows/pull_request.yaml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pull_request.yaml b/.github/workflows/pull_request.yaml index 6a1bc6d..414e54e 100644 --- a/.github/workflows/pull_request.yaml +++ b/.github/workflows/pull_request.yaml @@ -25,8 +25,10 @@ jobs: license: name: License headers check needs: soundness - run: | - ./scripts/check_license_headers.sh + steps: + - name: "License headers check" + run: | + ./scripts/check_license_headers.sh unit-tests: name: Unit tests From 3e83688d50e3ad49aa863b96c391662710f5836c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Stormacq?= <sebastien.stormacq@gmail.com> Date: Tue, 15 Oct 2024 19:13:29 +0200 Subject: [PATCH 11/15] fix --- .github/workflows/pull_request.yaml | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/.github/workflows/pull_request.yaml b/.github/workflows/pull_request.yaml index 414e54e..7a2bed3 100644 --- a/.github/workflows/pull_request.yaml +++ b/.github/workflows/pull_request.yaml @@ -24,11 +24,20 @@ jobs: license: name: License headers check - needs: soundness + runs-on: ubuntu-latest + strategy: + fail-fast: false steps: - - name: "License headers check" - run: | - ./scripts/check_license_headers.sh + - name: Checkout repository + uses: actions/checkout@v4 + with: + persist-credentials: false + - name: Mark the workspace as safe + # https://github.com/actions/checkout/issues/766 + run: git config --global --add safe.directory ${GITHUB_WORKSPACE} + - name: License headers check + run: | + ./scripts/check_license_headers.sh unit-tests: name: Unit tests From c74e92386c75fcb65cc53c5f2de422a5dbee4a78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Stormacq?= <sebastien.stormacq@gmail.com> Date: Tue, 15 Oct 2024 19:15:22 +0200 Subject: [PATCH 12/15] fix --- .github/workflows/pull_request.yaml | 4 ++-- .licenseignore | 2 ++ scripts/{check-license-header.sh => check-license-headers.sh} | 0 3 files changed, 4 insertions(+), 2 deletions(-) rename scripts/{check-license-header.sh => check-license-headers.sh} (100%) diff --git a/.github/workflows/pull_request.yaml b/.github/workflows/pull_request.yaml index 7a2bed3..7b70e2b 100644 --- a/.github/workflows/pull_request.yaml +++ b/.github/workflows/pull_request.yaml @@ -34,10 +34,10 @@ jobs: persist-credentials: false - name: Mark the workspace as safe # https://github.com/actions/checkout/issues/766 - run: git config --global --add safe.directory ${GITHUB_WORKSPACE} + run: git config --global --add safe.directory ${GITHUB_WORKSPACE} - name: License headers check run: | - ./scripts/check_license_headers.sh + ./scripts/check-license-headers.sh unit-tests: name: Unit tests diff --git a/.licenseignore b/.licenseignore index 796c53d..87baffa 100644 --- a/.licenseignore +++ b/.licenseignore @@ -32,3 +32,5 @@ Package.resolved .swiftformat *.yaml *.yml +*.json +*.gif diff --git a/scripts/check-license-header.sh b/scripts/check-license-headers.sh similarity index 100% rename from scripts/check-license-header.sh rename to scripts/check-license-headers.sh From e860df9582942bf78869b558982c648def2cfb2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Stormacq?= <sebastien.stormacq@gmail.com> Date: Tue, 15 Oct 2024 19:16:24 +0200 Subject: [PATCH 13/15] fix --- .github/workflows/pull_request.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/pull_request.yaml b/.github/workflows/pull_request.yaml index 7b70e2b..8c592b8 100644 --- a/.github/workflows/pull_request.yaml +++ b/.github/workflows/pull_request.yaml @@ -36,6 +36,8 @@ jobs: # https://github.com/actions/checkout/issues/766 run: git config --global --add safe.directory ${GITHUB_WORKSPACE} - name: License headers check + env: + PROJECT_NAME: "Swift OpenAPI Lambda" run: | ./scripts/check-license-headers.sh From 2909161857811eb167f1f2d72758ec094b2d685c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Stormacq?= <sebastien.stormacq@gmail.com> Date: Tue, 15 Oct 2024 19:17:24 +0200 Subject: [PATCH 14/15] fix --- .github/workflows/pull_request.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pull_request.yaml b/.github/workflows/pull_request.yaml index 8c592b8..54b11b8 100644 --- a/.github/workflows/pull_request.yaml +++ b/.github/workflows/pull_request.yaml @@ -37,7 +37,7 @@ jobs: run: git config --global --add safe.directory ${GITHUB_WORKSPACE} - name: License headers check env: - PROJECT_NAME: "Swift OpenAPI Lambda" + PROJECT_NAME: "Swift OpenAPI Lambda" run: | ./scripts/check-license-headers.sh From aa848c680d9aff27cad53003582174653e7dd97a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Stormacq?= <sebastien.stormacq@gmail.com> Date: Tue, 15 Oct 2024 19:22:32 +0200 Subject: [PATCH 15/15] add build badge to readme --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 7e91e98..98151a7 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,9 @@ +[](https://github.com/swift-server/swift-openapi-lambda/actions/workflows//pull_request.yaml) + +  + +   [](LICENSE)