From e5cf01b0c3f2c1b0bc1ce20887248d97f7125412 Mon Sep 17 00:00:00 2001 From: Franz Busch Date: Wed, 16 Oct 2024 12:57:51 +0100 Subject: [PATCH] [CI] Adopt GitHub actions # Motivation We want to migrate all of repositories to use GitHub Actions. # Modification This PR adopts GH actions in this repo. # Result New and shiny CI. --- .github/workflows/main.yml | 20 ++ .github/workflows/pull_request.yml | 33 +++ .github/workflows/pull_request_label.yml | 18 ++ .github/workflows/scheduled.yml | 20 ++ docker/Dockerfile | 44 ---- docker/docker-compose.2204.510.yaml | 25 --- docker/docker-compose.2204.59.yaml | 25 --- docker/docker-compose.2204.main.yaml | 21 -- docker/docker-compose.yaml | 47 ---- scripts/check-cmake-lists.sh | 33 +++ scripts/check_no_api_breakages.sh | 54 ----- scripts/cxx-interop-compatibility.sh | 62 ------ scripts/generate_contributors_list.sh | 40 ---- scripts/generate_docs.sh | 109 ---------- scripts/soundness.sh | 204 ------------------ ...te_cmakelists.sh => update-cmake-lists.sh} | 0 16 files changed, 124 insertions(+), 631 deletions(-) create mode 100644 .github/workflows/main.yml create mode 100644 .github/workflows/pull_request.yml create mode 100644 .github/workflows/pull_request_label.yml create mode 100644 .github/workflows/scheduled.yml 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.main.yaml delete mode 100644 docker/docker-compose.yaml create mode 100755 scripts/check-cmake-lists.sh delete mode 100755 scripts/check_no_api_breakages.sh delete mode 100755 scripts/cxx-interop-compatibility.sh delete mode 100755 scripts/generate_contributors_list.sh delete mode 100755 scripts/generate_docs.sh delete mode 100755 scripts/soundness.sh rename scripts/{update_cmakelists.sh => update-cmake-lists.sh} (100%) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 00000000..24859f4b --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,20 @@ +name: Main + +on: + push: + branches: [main] + +jobs: + unit-tests: + name: Unit tests + uses: apple/swift-nio/.github/workflows/unit_tests.yml@main + with: + linux_5_9_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error" + linux_5_10_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error" + linux_6_0_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error" + linux_nightly_6_0_arguments_override: "--explicit-target-dependency-import-check error" + linux_nightly_main_arguments_override: "--explicit-target-dependency-import-check error" + + cxx-interop: + name: Cxx interop + uses: apple/swift-nio/.github/workflows/cxx_interop.yml@main diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml new file mode 100644 index 00000000..e07873ec --- /dev/null +++ b/.github/workflows/pull_request.yml @@ -0,0 +1,33 @@ +name: PR + +on: + pull_request: + types: [opened, reopened, synchronize] + +jobs: + soundness: + name: Soundness + uses: swiftlang/github-workflows/.github/workflows/soundness.yml@main + with: + license_header_check_project_name: "SwiftCrypto" + + cmake-lists: + name: Check cmake lists + uses: apple/swift-nio/.github/workflows/swift_matrix.yml@main + with: + name: "Check cmake lists" + matrix_linux_command: ./scripts/check-cmake-lists.sh + + unit-tests: + name: Unit tests + uses: apple/swift-nio/.github/workflows/unit_tests.yml@main + with: + linux_5_9_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error" + linux_5_10_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error" + linux_6_0_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error" + linux_nightly_6_0_arguments_override: "--explicit-target-dependency-import-check error" + linux_nightly_main_arguments_override: "--explicit-target-dependency-import-check error" + + cxx-interop: + name: Cxx interop + uses: apple/swift-nio/.github/workflows/cxx_interop.yml@main diff --git a/.github/workflows/pull_request_label.yml b/.github/workflows/pull_request_label.yml new file mode 100644 index 00000000..86f199f3 --- /dev/null +++ b/.github/workflows/pull_request_label.yml @@ -0,0 +1,18 @@ +name: PR label + +on: + pull_request: + types: [labeled, unlabeled, opened, reopened, synchronize] + +jobs: + semver-label-check: + name: Semantic Version label check + runs-on: ubuntu-latest + timeout-minutes: 1 + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + persist-credentials: false + - name: Check for Semantic Version label + uses: apple/swift-nio/.github/actions/pull_request_semver_label_checker@main diff --git a/.github/workflows/scheduled.yml b/.github/workflows/scheduled.yml new file mode 100644 index 00000000..2e233df3 --- /dev/null +++ b/.github/workflows/scheduled.yml @@ -0,0 +1,20 @@ +name: Scheduled + +on: + schedule: + - cron: "0 8,20 * * *" + +jobs: + unit-tests: + name: Unit tests + uses: apple/swift-nio/.github/workflows/unit_tests.yml@main + with: + linux_5_9_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error" + linux_5_10_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error" + linux_6_0_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error" + linux_nightly_6_0_arguments_override: "--explicit-target-dependency-import-check error" + linux_nightly_main_arguments_override: "--explicit-target-dependency-import-check error" + + cxx-interop: + name: Cxx interop + uses: apple/swift-nio/.github/workflows/cxx_interop.yml@main diff --git a/docker/Dockerfile b/docker/Dockerfile deleted file mode 100644 index d86e4614..00000000 --- a/docker/Dockerfile +++ /dev/null @@ -1,44 +0,0 @@ -ARG swift_version=5.7 -ARG ubuntu_version=jammy -ARG base_image=swift:$swift_version-$ubuntu_version -FROM $base_image -# needed to do again after FROM due to docker limitation -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 - -# Get lldb out of the way -RUN if [ -d /usr/lib/python2.7/site-packages ]; then mv /usr/lib/python2.7/site-packages/* /usr/lib/python2.7/dist-packages && rmdir /usr/lib/python2.7/site-packages && ln -s /usr/lib/python2.7/dist-packages /usr/lib/python2.7/site-packages; fi - -# dependencies -RUN apt-get update && apt-get install -y wget -RUN apt-get update && apt-get install -y lsof dnsutils netcat-openbsd net-tools curl jq python2.7 # used by integration tests - -# ruby and jazzy for docs generation -RUN apt-get update && apt-get install -y ruby ruby-dev libsqlite3-dev build-essential -# jazzy no longer works on xenial as ruby is too old. -RUN if [ "${ubuntu_version}" = "focal" ] ; then echo "gem: --no-document" > ~/.gemrc; fi -RUN if [ "${ubuntu_version}" = "focal" ] ; then gem install jazzy; fi - -# cmake build -RUN apt-get update && apt-get install -y cmake ninja-build - -# tools -RUN mkdir -p $HOME/.tools -RUN echo 'export PATH="$HOME/.tools:$PATH"' >> $HOME/.profile - -# script to allow mapping framepointers on linux (until part of the toolchain) -RUN wget -q https://raw.githubusercontent.com/apple/swift/main/utils/symbolicate-linux-fatal -O $HOME/.tools/symbolicate-linux-fatal -RUN chmod 755 $HOME/.tools/symbolicate-linux-fatal - -# swiftformat (until part of the toolchain) - -ARG swiftformat_version=0.44.6 -RUN git clone --branch $swiftformat_version --depth 1 https://github.com/nicklockwood/SwiftFormat $HOME/.tools/swift-format -RUN cd $HOME/.tools/swift-format && swift build -c release -RUN ln -s $HOME/.tools/swift-format/.build/release/swiftformat $HOME/.tools/swiftformat diff --git a/docker/docker-compose.2204.510.yaml b/docker/docker-compose.2204.510.yaml deleted file mode 100644 index 2bc0139c..00000000 --- a/docker/docker-compose.2204.510.yaml +++ /dev/null @@ -1,25 +0,0 @@ -version: "3" - -services: - - runtime-setup: - image: swift-crypto:22.04-5.10 - build: - args: - ubuntu_version: "jammy" - swift_version: "5.10" - - test: - image: swift-crypto:22.04-5.10 - environment: - - IMPORT_CHECK_ARG=--explicit-target-dependency-import-check error - #- SANITIZER_ARG=--sanitize=thread - - cmake: - image: swift-crypto:22.04-5.10 - - cxx-interop-build: - image: swift-crypto:22.04-5.10 - - shell: - image: swift-crypto:22.04-5.10 diff --git a/docker/docker-compose.2204.59.yaml b/docker/docker-compose.2204.59.yaml deleted file mode 100644 index 8ba18910..00000000 --- a/docker/docker-compose.2204.59.yaml +++ /dev/null @@ -1,25 +0,0 @@ -version: "3" - -services: - - runtime-setup: - image: swift-crypto:22.04-5.9 - build: - args: - ubuntu_version: "jammy" - swift_version: "5.9" - - test: - image: swift-crypto:22.04-5.9 - environment: - - IMPORT_CHECK_ARG=--explicit-target-dependency-import-check error - #- SANITIZER_ARG=--sanitize=thread - - cmake: - image: swift-crypto:22.04-5.9 - - cxx-interop-build: - image: swift-crypto:22.04-5.9 - - shell: - image: swift-crypto:22.04-5.9 diff --git a/docker/docker-compose.2204.main.yaml b/docker/docker-compose.2204.main.yaml deleted file mode 100644 index d5fb6a15..00000000 --- a/docker/docker-compose.2204.main.yaml +++ /dev/null @@ -1,21 +0,0 @@ -version: "3" - -services: - - runtime-setup: - image: swift-crypto:22.04-main - build: - args: - base_image: "swiftlang/swift:nightly-main-jammy" - - test: - image: swift-crypto:22.04-main - environment: - - IMPORT_CHECK_ARG=--explicit-target-dependency-import-check error - #- SANITIZER_ARG=--sanitize=thread - - cmake: - image: swift-crypto:22.04-main - - shell: - image: swift-crypto:22.04-main diff --git a/docker/docker-compose.yaml b/docker/docker-compose.yaml deleted file mode 100644 index e66669e4..00000000 --- a/docker/docker-compose.yaml +++ /dev/null @@ -1,47 +0,0 @@ -# this file is not designed to be run directly -# instead, use the docker-compose.. files -# eg docker-compose -f docker/docker-compose.yaml -f docker/docker-compose.1804.51.yaml run test -version: "3" - -services: - - runtime-setup: - image: swift-crypto:default - build: - context: . - dockerfile: Dockerfile - - common: &common - image: swift-crypto:default - depends_on: [runtime-setup] - volumes: - - ~/.ssh:/root/.ssh - - ..:/swift-crypto:z - working_dir: /swift-crypto - cap_drop: - - CAP_NET_RAW - - CAP_NET_BIND_SERVICE - - soundness: - <<: *common - command: /bin/bash -xcl "./scripts/soundness.sh" - - test: - <<: *common - # FIXME: get rid of existing warnings - #command: /bin/bash -xcl "swift test --enable-test-discovery -Xswiftc -warnings-as-errors $${SANITIZER_ARG-} $${IMPORT_CHECK_ARG-}" - command: /bin/bash -xcl "swift test --enable-test-discovery $${IMPORT_CHECK_ARG-}" - - cmake: - <<: *common - command: /bin/bash -xcl "cmake -G Ninja -D CMAKE_BUILD_TYPE=Release -B out -S . && ninja -C out" - - cxx-interop-build: - <<: *common - command: /bin/bash -xcl "./scripts/cxx-interop-compatibility.sh" - - # util - - shell: - <<: *common - entrypoint: /bin/bash diff --git a/scripts/check-cmake-lists.sh b/scripts/check-cmake-lists.sh new file mode 100755 index 00000000..f50d4550 --- /dev/null +++ b/scripts/check-cmake-lists.sh @@ -0,0 +1,33 @@ +#!/bin/bash +##===----------------------------------------------------------------------===## +## +## This source file is part of the SwiftCertificates open source project +## +## Copyright (c) 2024 Apple Inc. and the SwiftCertificates project authors +## Licensed under Apache License v2.0 +## +## See LICENSE.txt for license information +## See CONTRIBUTORS.txt for the list of SwiftCertificates 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 if the cmake files are up-to-date..." + +here="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +FIRST_OUT="$(git status --porcelain)" +_=$("$here"/update-cmake-lists.sh 2>&1) +SECOND_OUT="$(git status --porcelain)" +if [[ "$FIRST_OUT" != "$SECOND_OUT" ]]; then + error "Changes in the cmake files detected. Please run the update-cmake-lists.sh script." + exit 1 +fi + +log "✅ cmake files are up-to-date." diff --git a/scripts/check_no_api_breakages.sh b/scripts/check_no_api_breakages.sh deleted file mode 100755 index 86a9a6d0..00000000 --- a/scripts/check_no_api_breakages.sh +++ /dev/null @@ -1,54 +0,0 @@ -#!/bin/bash -##===----------------------------------------------------------------------===## -## -## This source file is part of the SwiftCrypto open source project -## -## Copyright (c) 2019-2022 Apple Inc. and the SwiftCrypto project authors -## Licensed under Apache License v2.0 -## -## See LICENSE.txt for license information -## See CONTRIBUTORS.md for the list of SwiftCrypto project authors -## -## SPDX-License-Identifier: Apache-2.0 -## -##===----------------------------------------------------------------------===## - -set -eu - -function usage() { - echo >&2 "Usage: $0 REPO-GITHUB-URL NEW-VERSION OLD-VERSIONS..." - echo >&2 - echo >&2 "This script requires a Swift 5.6+ toolchain." - echo >&2 - echo >&2 "Examples:" - echo >&2 - echo >&2 "Check between main and tag 2.0.5 of swift-crypto:" - echo >&2 " $0 https://github.com/apple/swift-crypto main 2.0.5" - echo >&2 - echo >&2 "Check between HEAD and commit 64cf63d7 using the provided toolchain:" - echo >&2 " xcrun --toolchain org.swift.5120190702a $0 ../some-local-repo HEAD 64cf63d7" -} - -if [[ $# -lt 3 ]]; then - usage - exit 1 -fi - -tmpdir=$(mktemp -d /tmp/.check-api_XXXXXX) -repo_url=$1 -new_tag=$2 -shift 2 - -repodir="$tmpdir/repo" -git clone "$repo_url" "$repodir" -git -C "$repodir" fetch -q origin '+refs/pull/*:refs/remotes/origin/pr/*' -cd "$repodir" -git checkout -q "$new_tag" - -for old_tag in "$@"; do - echo "Checking public API breakages from $old_tag to $new_tag" - - swift package diagnose-api-breaking-changes "$old_tag" -done - -echo done diff --git a/scripts/cxx-interop-compatibility.sh b/scripts/cxx-interop-compatibility.sh deleted file mode 100755 index b6e6c7b0..00000000 --- a/scripts/cxx-interop-compatibility.sh +++ /dev/null @@ -1,62 +0,0 @@ -#!/bin/bash -##===----------------------------------------------------------------------===## -## -## This source file is part of the SwiftCrypto open source project -## -## Copyright (c) 2023 Apple Inc. and the SwiftCrypto project authors -## Licensed under Apache License v2.0 -## -## See LICENSE.txt for license information -## See CONTRIBUTORS.md for the list of SwiftCrypto project authors -## -## SPDX-License-Identifier: Apache-2.0 -## -##===----------------------------------------------------------------------===## - -set -eu - -sourcedir=$(dirname "$(readlink -f $0)")/.. -workingdir=$(mktemp -d) -projectname=$(basename $workingdir) - -cd $workingdir -swift package init - -cat << EOF > Package.swift -// swift-tools-version: 5.9 - -import PackageDescription - -let package = Package( - name: "interop", - platforms: [.macOS(.v10_15)], - products: [ - .library( - name: "interop", - targets: ["interop"] - ), - ], - dependencies: [ - .package(path: "$sourcedir") - ], - targets: [ - .target( - name: "interop", - // Depend on all products of swift-crypto to make sure they're all - // compatible with cxx interop. - dependencies: [ - .product(name: "Crypto", package: "swift-crypto"), - .product(name: "_CryptoExtras", package: "swift-crypto") - ], - swiftSettings: [.interoperabilityMode(.Cxx)] - ) - ] -) -EOF - -cat << EOF > Sources/$projectname/$(echo $projectname | tr . _).swift -import Crypto -import _CryptoExtras -EOF - -swift build diff --git a/scripts/generate_contributors_list.sh b/scripts/generate_contributors_list.sh deleted file mode 100755 index 79cbe3b8..00000000 --- a/scripts/generate_contributors_list.sh +++ /dev/null @@ -1,40 +0,0 @@ -#!/bin/bash -##===----------------------------------------------------------------------===## -## -## This source file is part of the SwiftCrypto open source project -## -## Copyright (c) 2019 Apple Inc. and the SwiftCrypto project authors -## Licensed under Apache License v2.0 -## -## See LICENSE.txt for license information -## See CONTRIBUTORS.md for the list of SwiftCrypto project authors -## -## SPDX-License-Identifier: Apache-2.0 -## -##===----------------------------------------------------------------------===## - -set -eu -here="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -contributors=$( cd "$here"/.. && git shortlog -es | cut -f2 | sed 's/^/- /' ) - -cat > "$here/../CONTRIBUTORS.md" <<- EOF - For the purpose of tracking copyright, this is the list of individuals and - organizations who have contributed source code to SwiftCrypto. - - For employees of an organization/company where the copyright of work done - by employees of that company is held by the company itself, only the company - needs to be listed here. - - ## COPYRIGHT HOLDERS - - - Apple Inc. (all contributors with '@apple.com') - - ### Contributors - - $contributors - - ## Updating this list - - Please do not edit this file manually. It is generated using \`./scripts/generate_contributors_list.sh\`. - If a name is misspelled or appearing multiple times: add an entry in \`./.mailmap\` (see [docs](https://git-scm.com/docs/git-shortlog#_mapping_authors)) -EOF diff --git a/scripts/generate_docs.sh b/scripts/generate_docs.sh deleted file mode 100755 index 23131867..00000000 --- a/scripts/generate_docs.sh +++ /dev/null @@ -1,109 +0,0 @@ -#!/bin/bash -##===----------------------------------------------------------------------===## -## -## This source file is part of the SwiftCrypto open source project -## -## Copyright (c) 2018-2019 Apple Inc. and the SwiftCrypto project authors -## Licensed under Apache License v2.0 -## -## See LICENSE.txt for license information -## See CONTRIBUTORS.md for the list of SwiftCrypto project authors -## -## SPDX-License-Identifier: Apache-2.0 -## -##===----------------------------------------------------------------------===## - -set -e - -my_path="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -root_path="$my_path/.." -version=$(git describe --abbrev=0 --tags || echo "0.0.0") -modules=(Crypto) - -if [[ "$(uname -s)" == "Linux" ]]; then - # build code if required - if [[ ! -d "$root_path/.build/x86_64-unknown-linux" ]]; then - swift build - fi - # setup source-kitten if required - mkdir -p "$root_path/.build/sourcekitten" - source_kitten_source_path="$root_path/.build/sourcekitten/source" - if [[ ! -d "$source_kitten_source_path" ]]; then - git clone https://github.com/jpsim/SourceKitten.git "$source_kitten_source_path" - fi - source_kitten_path="$source_kitten_source_path/.build/debug" - if [[ ! -d "$source_kitten_path" ]]; then - rm -rf "$source_kitten_source_path/.swift-version" - cd "$source_kitten_source_path" && swift build && cd "$root_path" - fi - # generate - for module in "${modules[@]}"; do - if [[ ! -f "$root_path/.build/sourcekitten/$module.json" ]]; then - "$source_kitten_path/sourcekitten" doc --spm --module-name $module > "$root_path/.build/sourcekitten/$module.json" - fi - done -fi - -jazzy_dir="$root_path/.build/jazzy" -rm -rf "$jazzy_dir" -mkdir -p "$jazzy_dir" - -# prep index -module_switcher="$jazzy_dir/README.md" -cat > "$module_switcher" <<"EOF" -# SwiftCrypto Docs - -SwiftCrypto is a SwiftCrypto package. - -To get started with SwiftCrypto, [`import Crypto`](../Crypto/index.html). -EOF - -# run jazzy -if ! command -v jazzy > /dev/null; then - gem install jazzy --no-ri --no-rdoc -fi - -jazzy_args=(--clean - --author 'SwiftCrypto team' - --readme "$module_switcher" - --author_url https://github.com/apple/swift-crypto - --github_url https://github.com/apple/swift-crypto - --github-file-prefix https://github.com/apple/swift-crypto/tree/$version - --theme fullwidth - --swift-build-tool spm) - -for module in "${modules[@]}"; do - args=("${jazzy_args[@]}" --output "$jazzy_dir/docs/$version/$module" --docset-path "$jazzy_dir/docset/$version/$module" - --module "$module" --module-version $version - --root-url "https://apple.github.io/swift-crypto/docs/$version/$module/") - if [[ "$(uname -s)" == "Linux" ]]; then - args+=(--sourcekitten-sourcefile "$root_path/.build/sourcekitten/$module.json") - fi - jazzy "${args[@]}" -done - -# push to github pages -if [[ $PUSH == true ]]; then - BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD) - GIT_AUTHOR=$(git --no-pager show -s --format='%an <%ae>' HEAD) - git fetch origin +gh-pages:gh-pages - git checkout gh-pages - rm -rf "docs/$version" - rm -rf "docs/current" - cp -r "$jazzy_dir/docs/$version" docs/ - cp -r "docs/$version" docs/current - git add --all docs - echo '' > index.html - git add index.html - touch .nojekyll - git add .nojekyll - changes=$(git diff-index --name-only HEAD) - if [[ -n "$changes" ]]; then - echo -e "changes detected\n$changes" - git commit --author="$GIT_AUTHOR" -m "publish $version docs" - git push origin gh-pages - else - echo "no changes detected" - fi - git checkout -f $BRANCH_NAME -fi diff --git a/scripts/soundness.sh b/scripts/soundness.sh deleted file mode 100755 index 2eefb986..00000000 --- a/scripts/soundness.sh +++ /dev/null @@ -1,204 +0,0 @@ -#!/bin/bash -##===----------------------------------------------------------------------===## -## -## This source file is part of the SwiftCrypto open source project -## -## Copyright (c) 2019-2023 Apple Inc. and the SwiftCrypto project authors -## Licensed under Apache License v2.0 -## -## See LICENSE.txt for license information -## See CONTRIBUTORS.md for the list of SwiftCrypto project authors -## -## SPDX-License-Identifier: Apache-2.0 -## -##===----------------------------------------------------------------------===## - -set -eu -here="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -function replace_acceptable_years() { - # this needs to replace all acceptable forms with 'YEARS' - sed -e 's/20[12][8901]-20[12][90123]/YEARS/' -e 's/20[12][901234]/YEARS/' -} - -printf "=> Checking for unacceptable language... " -# This greps for unacceptable terminology. The square bracket[s] are so that -# "git grep" doesn't find the lines that greps :). -# We exclude the vendored BoringSSL copy from this check. -unacceptable_terms=( - -e blacklis[t] - -e whitelis[t] - -e slav[e] - -e sanit[y] -) -if git grep --color=never -i "${unacceptable_terms[@]}" ':(exclude)Sources/CCryptoBoringSSL*' > /dev/null; then - printf "\033[0;31mUnacceptable language found.\033[0m\n" - git grep -i "${unacceptable_terms[@]}" ':(exclude)Sources/CCryptoBoringSSL*' - exit 1 -fi -printf "\033[0;32mokay.\033[0m\n" - -# Run gyb, if generated files was changed -> fail -printf "=> Detecting manual edits in generated Swift files by comparing to gyb output\n" -FIRST_OUT="$(git status --porcelain)" -out=$($here/generate_boilerplate_files_with_gyb.sh 2>&1) -SECOND_OUT="$(git status --porcelain)" -if [ "$out" == *"error"* ]; then - printf "\033[0;31merror!\033[0m\n" - echo $out - exit 1 -fi -if [[ "$FIRST_OUT" != "$SECOND_OUT" ]]; then - printf "\033[0;31mRunning gyb results in changes! Have you manually edited the generated Swift files? Or did you forget to run gyb and commit changes?\033[0m\n" - exit 1 -fi -printf "\033[0;32mokay.\033[0m\n" - -printf "=> Detecting changes in source files for CMake build\n" -FIRST_OUT="$(git status --porcelain)" -out=$($here/update_cmakelists.sh 2>&1) -SECOND_OUT="$(git status --porcelain)" -if [[ "$FIRST_OUT" != "$SECOND_OUT" ]]; then - printf "\033[0;31mThere are source file changes! Have you added or renamed source files? Or did you forget to run 'update_cmakelists.sh' and commit changes?\033[0m\n" - exit 1 -fi -printf "\033[0;32mokay.\033[0m\n" - -printf "=> Checking format\n" -FIRST_OUT="$(git status --porcelain)" -# only checking directory named BoringSSL, rest is shared code and we need to preserve original format -shopt -u dotglob -find Sources/* Tests/* -name BoringSSL -type d | while IFS= read -r d; do - printf " * checking $d... " - out=$(swiftformat "$d" 2>&1) - SECOND_OUT="$(git status --porcelain)" - if [[ "$out" == *"error"*] && ["$out" != "*No eligible files" ]]; then - printf "\033[0;31merror!\033[0m\n" - echo $out - exit 1 - fi - if [[ "$FIRST_OUT" != "$SECOND_OUT" ]]; then - printf "\033[0;31mformatting issues!\033[0m\n" - git --no-pager diff - exit 1 - fi - printf "\033[0;32mokay.\033[0m\n" -done - -printf "=> Checking #defines..." -if grep 'development = true' Package.swift > /dev/null; then - printf "\033[0;31mstill in development mode!\033[0m Comment out CRYPTO_IN_SWIFTPM_FORCE_BUILD_API.\n" - exit 1 -else - printf "\033[0;32mokay.\033[0m\n" -fi - -printf "=> Checking license headers\n" -tmp=$(mktemp /tmp/.swift-crypto-soundness_XXXXXX) - -for language in swift-or-c bash dtrace cmake; do - printf " * $language... " - declare -a matching_files - declare -a exceptions - expections=( ) - matching_files=( -name '*' ) - case "$language" in - swift-or-c) - exceptions=( -path '*Sources/CCryptoBoringSSL/*' -o -name 'Package.swift' ) - matching_files=( -name '*.swift' -o -name '*.c' -o -name '*.h' ) - cat > "$tmp" <<"EOF" -//===----------------------------------------------------------------------===// -// -// This source file is part of the SwiftCrypto open source project -// -// Copyright (c) YEARS Apple Inc. and the SwiftCrypto project authors -// Licensed under Apache License v2.0 -// -// See LICENSE.txt for license information -// See CONTRIBUTORS.md for the list of SwiftCrypto project authors -// -// SPDX-License-Identifier: Apache-2.0 -// -//===----------------------------------------------------------------------===// -EOF - ;; - bash) - matching_files=( -name '*.sh' ) - cat > "$tmp" <<"EOF" -#!/bin/bash -##===----------------------------------------------------------------------===## -## -## This source file is part of the SwiftCrypto open source project -## -## Copyright (c) YEARS Apple Inc. and the SwiftCrypto project authors -## Licensed under Apache License v2.0 -## -## See LICENSE.txt for license information -## See CONTRIBUTORS.md for the list of SwiftCrypto project authors -## -## SPDX-License-Identifier: Apache-2.0 -## -##===----------------------------------------------------------------------===## -EOF - ;; - dtrace) - matching_files=( -name '*.d' ) - cat > "$tmp" <<"EOF" -#!/usr/sbin/dtrace -q -s -/*===----------------------------------------------------------------------===* - * - * This source file is part of the SwiftCrypto open source project - * - * Copyright (c) YEARS Apple Inc. and the SwiftCrypto project authors - * Licensed under Apache License v2.0 - * - * See LICENSE.txt for license information - * See CONTRIBUTORS.md for the list of SwiftCrypto project authors - * - * SPDX-License-Identifier: Apache-2.0 - * - *===----------------------------------------------------------------------===*/ -EOF - ;; - cmake) - matching_files=( -name 'SwiftSupport.cmake' -o -name 'CMakeLists.txt' ) - cat > "$tmp" <<"EOF" -##===----------------------------------------------------------------------===## -## -## This source file is part of the SwiftCrypto open source project -## -## Copyright (c) YEARS Apple Inc. and the SwiftCrypto project authors -## Licensed under Apache License v2.0 -## -## See LICENSE.txt for license information -## See CONTRIBUTORS.md for the list of SwiftCrypto project authors -## -## SPDX-License-Identifier: Apache-2.0 -## -##===----------------------------------------------------------------------===## -EOF - ;; - *) - echo >&2 "ERROR: unknown language '$language'" - ;; - esac - - expected_lines=$(cat "$tmp" | wc -l) - expected_sha=$(cat "$tmp" | shasum) - - ( - cd "$here/.." - find . \ - \( \! -path './.build/*' -a \ - \( "${matching_files[@]}" \) -a \ - \( \! \( "${exceptions[@]}" \) \) \) | while read line; do - if [[ "$(cat "$line" | replace_acceptable_years | head -n $expected_lines | shasum)" != "$expected_sha" ]]; then - printf "\033[0;31mmissing headers in file '$line'!\033[0m\n" - diff -u <(cat "$line" | replace_acceptable_years | head -n $expected_lines) "$tmp" - exit 1 - fi - done - printf "\033[0;32mokay.\033[0m\n" - ) -done - -rm "$tmp" diff --git a/scripts/update_cmakelists.sh b/scripts/update-cmake-lists.sh similarity index 100% rename from scripts/update_cmakelists.sh rename to scripts/update-cmake-lists.sh