From 87d289e9fd879eef4ab1c51964d983344c49e83d Mon Sep 17 00:00:00 2001 From: adam-fowler Date: Wed, 18 Sep 2024 08:59:12 +0000 Subject: [PATCH] Update from hummingbird-project-template 6c7f44e2f7e58f2d298a177e73421f244f41f90e --- .dockerignore | 2 + .github/workflows/verify-documentation.yml | 35 ++++++ .swiftformat | 4 +- Dockerfile | 18 +++ scripts/validate.sh | 131 +++++++++++++++++++++ 5 files changed, 188 insertions(+), 2 deletions(-) create mode 100644 .dockerignore create mode 100644 .github/workflows/verify-documentation.yml create mode 100644 Dockerfile create mode 100755 scripts/validate.sh diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..2fb3343 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +.build +.git \ No newline at end of file diff --git a/.github/workflows/verify-documentation.yml b/.github/workflows/verify-documentation.yml new file mode 100644 index 0000000..a587e6a --- /dev/null +++ b/.github/workflows/verify-documentation.yml @@ -0,0 +1,35 @@ +name: Verify Documentation + +on: + pull_request: +concurrency: + group: ${{ github.workflow }}-${{ github.ref }}-verifydocs + cancel-in-progress: true + +jobs: + linux: + runs-on: ubuntu-latest + timeout-minutes: 15 + container: + image: swift:latest + steps: + - name: Install rsync 📚 + run: | + apt-get update && apt-get install -y rsync bc + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + path: "package" + - name: Checkout + uses: actions/checkout@v4 + with: + repository: "hummingbird-project/hummingbird-docs" + fetch-depth: 0 + path: "documentation" + - name: Verify + run: | + cd documentation + swift package edit ${GITHUB_REPOSITORY#*/} --path ../package + ./scripts/build-docc.sh -e + diff --git a/.swiftformat b/.swiftformat index beb1d05..14fb33f 100644 --- a/.swiftformat +++ b/.swiftformat @@ -1,5 +1,5 @@ # Minimum swiftformat version ---minversion 0.51.0 +--minversion 0.53.10 # Swift version --swiftversion 5.9 @@ -8,7 +8,7 @@ --exclude .build # rules ---disable redundantReturn, extensionAccessControl, typeSugar, conditionalAssignment +--disable redundantReturn, extensionAccessControl, typeSugar, conditionalAssignment, preferForLoop, redundantInternal, redundantStaticSelf # format options --ifdef no-indent diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..c09c1c7 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,18 @@ +# ================================ +# Build image +# ================================ +FROM swift:6.0 as build + +WORKDIR /build + +# First just resolve dependencies. +# This creates a cached layer that can be reused +# as long as your Package.swift/Package.resolved +# files do not change. +COPY ./Package.* ./ +RUN swift package resolve + +# Copy entire repo into container +COPY . . + +RUN swift test --sanitize=thread diff --git a/scripts/validate.sh b/scripts/validate.sh new file mode 100755 index 0000000..bb67406 --- /dev/null +++ b/scripts/validate.sh @@ -0,0 +1,131 @@ +#!/bin/bash +##===----------------------------------------------------------------------===## +## +## This source file is part of the Hummingbird server framework project +## +## Copyright (c) 2021-2024 the Hummingbird authors +## Licensed under Apache License v2.0 +## +## See LICENSE.txt for license information +## See hummingbird/CONTRIBUTORS.txt for the list of Hummingbird authors +## +## SPDX-License-Identifier: Apache-2.0 +## +##===----------------------------------------------------------------------===## +##===----------------------------------------------------------------------===## +## +## This source file is part of the SwiftNIO open source project +## +## Copyright (c) 2017-2019 Apple Inc. and the SwiftNIO project authors +## Licensed under Apache License v2.0 +## +## See LICENSE.txt for license information +## See CONTRIBUTORS.txt for the list of SwiftNIO project authors +## +## SPDX-License-Identifier: Apache-2.0 +## +##===----------------------------------------------------------------------===## + +SWIFT_FORMAT_VERSION=0.53.10 + +set -eu +here="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +which swiftformat > /dev/null 2>&1 || (echo "swiftformat not installed. You can install it using 'brew install swiftformat'" ; exit -1) + +function replace_acceptable_years() { + # this needs to replace all acceptable forms with 'YEARS' + sed -e 's/20[12][0-9]-20[12][0-9]/YEARS/' -e 's/20[12][0-9]/YEARS/' -e '/^#!/ d' +} + +printf "=> Checking format... " +FIRST_OUT="$(git status --porcelain)" +if [[ -n "${CI-""}" ]]; then + printf "(using v$(mint run NickLockwood/SwiftFormat@"$SWIFT_FORMAT_VERSION" --version)) " + mint run NickLockwood/SwiftFormat@"$SWIFT_FORMAT_VERSION" . > /dev/null 2>&1 +else + printf "(using v$(swiftformat --version)) " + swiftformat . > /dev/null 2>&1 +fi +SECOND_OUT="$(git status --porcelain)" +if [[ "$FIRST_OUT" != "$SECOND_OUT" ]]; then + printf "\033[0;31mformatting issues!\033[0m\n" + git --no-pager diff + exit 1 +else + printf "\033[0;32mokay.\033[0m\n" +fi +exit +printf "=> Checking license headers... " +tmp=$(mktemp /tmp/.soto-core-sanity_XXXXXX) + +for language in swift-or-c; do + declare -a matching_files + declare -a exceptions + expections=( ) + matching_files=( -name '*' ) + case "$language" in + swift-or-c) + exceptions=( -path '*Sources/INIParser/*' -o -path '*Sources/CSotoExpat/*' -o -path '*Benchmark/.build/*' -o -name Package.swift) + matching_files=( -name '*.swift' -o -name '*.c' -o -name '*.h' ) + cat > "$tmp" <<"EOF" +//===----------------------------------------------------------------------===// +// +// This source file is part of the Hummingbird open source project +// +// Copyright (c) YEARS the Hummingbird authors +// Licensed under Apache License v2.0 +// +// See LICENSE.txt for license information +// See CONTRIBUTORS.txt for the list of Hummingbird authors +// +// SPDX-License-Identifier: Apache-2.0 +// +//===----------------------------------------------------------------------===// +EOF + ;; + bash) + matching_files=( -name '*.sh' ) + cat > "$tmp" <<"EOF" +##===----------------------------------------------------------------------===## +## +## This source file is part of the Hummingbird open source project +## +## Copyright (c) YEARS the Hummingbird authors +## Licensed under Apache License v2.0 +## +## See LICENSE.txt for license information +## See CONTRIBUTORS.txt for the list of Hummingbird authors +## +## SPDX-License-Identifier: Apache-2.0 +## +##===----------------------------------------------------------------------===## +EOF + ;; + *) + echo >&2 "ERROR: unknown language '$language'" + ;; + esac + + lines_to_compare=$(cat "$tmp" | wc -l | tr -d " ") + # need to read one more line as we remove the '#!' line + lines_to_read=$(expr "$lines_to_compare" + 1) + expected_sha=$(cat "$tmp" | shasum) + + ( + cd "$here/.." + find . \ + \( \! -path './.build/*' -a \ + \( "${matching_files[@]}" \) -a \ + \( \! \( "${exceptions[@]}" \) \) \) | while read line; do + if [[ "$(cat "$line" | head -n $lines_to_read | replace_acceptable_years | head -n $lines_to_compare | shasum)" != "$expected_sha" ]]; then + printf "\033[0;31mmissing headers in file '$line'!\033[0m\n" + diff -u <(cat "$line" | head -n $lines_to_read | replace_acceptable_years | head -n $lines_to_compare) "$tmp" + exit 1 + fi + done + printf "\033[0;32mokay.\033[0m\n" + ) +done + +rm "$tmp"