From 06e680b66f22d4468b683f64b02e63ac89aa9e18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Stormacq?= Date: Thu, 17 Oct 2024 18:03:23 +0200 Subject: [PATCH 1/4] use SwiftLang's license header check with https://github.com/swiftlang/github-workflows/pull/36 --- .github/workflows/pull_request.yaml | 22 +------ .license_header_template | 14 ++++ scripts/check-license-headers.sh | 99 ----------------------------- 3 files changed, 15 insertions(+), 120 deletions(-) create mode 100644 .license_header_template delete mode 100755 scripts/check-license-headers.sh 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..8828b32 --- /dev/null +++ b/.license_header_template @@ -0,0 +1,14 @@ +@@===----------------------------------------------------------------------===@@ +@@ +@@ 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 +@@ +@@===----------------------------------------------------------------------===@@ \ No newline at end of file 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 From 87f71fd8c2ac20cb48af9ff7802c529f71774011 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Stormacq?= Date: Thu, 17 Oct 2024 19:39:14 +0200 Subject: [PATCH 2/4] remove .licenseignore fril from .licenseignore --- .licenseignore | 1 - 1 file changed, 1 deletion(-) 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 From 87d4cf6d86486582650e1834efb8bc5cbced8913 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Stormacq?= Date: Thu, 17 Oct 2024 19:47:08 +0200 Subject: [PATCH 3/4] licenseignore --- .licenseignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.licenseignore b/.licenseignore index 57732c4..ad71466 100644 --- a/.licenseignore +++ b/.licenseignore @@ -1,3 +1,4 @@ + .gitignore .swiftformatignore .spi.yml From 6ee3428f80d135f0132ff33cea8e1ad055b5a301 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Stormacq?= Date: Thu, 17 Oct 2024 20:19:00 +0200 Subject: [PATCH 4/4] change license header file --- .license_header_template | 6 +++--- .licenseignore | 1 - 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/.license_header_template b/.license_header_template index 8828b32..4c55a26 100644 --- a/.license_header_template +++ b/.license_header_template @@ -1,13 +1,13 @@ @@===----------------------------------------------------------------------===@@ @@ -@@ This source file is part of the ${PROJECT_NAME} open source project +@@ This source file is part of the Swift OpenAPI Lambda open source project @@ @@ Copyright (c) YEARS Amazon.com, Inc. or its affiliates -@@ and the ${PROJECT_NAME} project authors +@@ 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 ${PROJECT_NAME} project authors +@@ See CONTRIBUTORS.txt for the list of Swift OpenAPI Lambda project authors @@ @@ SPDX-License-Identifier: Apache-2.0 @@ diff --git a/.licenseignore b/.licenseignore index ad71466..57732c4 100644 --- a/.licenseignore +++ b/.licenseignore @@ -1,4 +1,3 @@ - .gitignore .swiftformatignore .spi.yml