diff --git a/.github/workflows/pull_request.yaml b/.github/workflows/pull_request.yaml index 34df3c6..d03c2e6 100644 --- a/.github/workflows/pull_request.yaml +++ b/.github/workflows/pull_request.yaml @@ -13,8 +13,7 @@ jobs: name: Soundness uses: swiftlang/github-workflows/.github/workflows/soundness.yml@main 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_enabled: true license_header_check_project_name: "Swift OpenAPI Lambda" shell_check_enabled: false python_lint_check_enabled: false @@ -22,25 +21,6 @@ jobs: docs_check_container_image: "swift:6.0-noble" format_check_container_image: "swiftlang/swift:nightly-6.0-jammy" - license: - name: License headers check - runs-on: ubuntu-latest - strategy: - fail-fast: false - steps: - - 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 - env: - PROJECT_NAME: "Swift OpenAPI Lambda" - run: | - ./scripts/check-license-headers.sh - unit-tests: name: Unit tests uses: apple/swift-nio/.github/workflows/unit_tests.yml@main diff --git a/.license_header_template b/.license_header_template new file mode 100644 index 0000000..4c55a26 --- /dev/null +++ b/.license_header_template @@ -0,0 +1,14 @@ +@@===----------------------------------------------------------------------===@@ +@@ +@@ 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 +@@ +@@===----------------------------------------------------------------------===@@ \ No newline at end of file diff --git a/.licenseignore b/.licenseignore index 87baffa..57732c4 100644 --- a/.licenseignore +++ b/.licenseignore @@ -1,5 +1,4 @@ .gitignore -.licenseignore .swiftformatignore .spi.yml .swift-format diff --git a/scripts/check-license-headers.sh b/scripts/check-license-headers.sh deleted file mode 100755 index ddaf852..0000000 --- a/scripts/check-license-headers.sh +++ /dev/null @@ -1,99 +0,0 @@ -#!/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