From 33e82da0842973f7f94ed4ab9994cc49f927c09c Mon Sep 17 00:00:00 2001 From: Adam Fowler Date: Wed, 13 Nov 2024 09:54:34 +0000 Subject: [PATCH] Add GH action files from swift-server/swift-openapi-async-http-client --- .editorconfig | 8 +++++ .github/workflows/main.yml | 18 ++++++++++ .github/workflows/pull_request.yml | 27 ++++++++++++++ .github/workflows/pull_request_label.yml | 18 ++++++++++ .licenseignore | 36 +++++++++++++++++++ .spi.yml | 5 +++ .swift-format | 8 ++--- .../OpenAPIHummingbird/OpenAPITransport.swift | 9 ++++- docker/Dockerfile | 23 ------------ docker/docker-compose.2204.59.yaml | 16 --------- docker/docker-compose.2204.main.yaml | 15 -------- docker/docker-compose.yaml | 35 ------------------ 12 files changed, 124 insertions(+), 94 deletions(-) create mode 100644 .editorconfig 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 .licenseignore create mode 100644 .spi.yml delete mode 100644 docker/Dockerfile 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 diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..e753483 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,8 @@ +root = true + +[*] +indent_style = space +indent_size = 4 +end_of_line = lf +insert_final_newline = true +trim_trailing_whitespace = true diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..c51a3a9 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,18 @@ +name: Main + +on: + push: + branches: [main] + 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 -Xswiftc -require-explicit-sendable" + linux_nightly_6_0_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable" + linux_nightly_main_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable" \ No newline at end of file diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml new file mode 100644 index 0000000..d65fd99 --- /dev/null +++ b/.github/workflows/pull_request.yml @@ -0,0 +1,27 @@ +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: "Hummingbird server framework" + + 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 -Xswiftc -strict-concurrency=complete" + # TODO: `enable -Xswiftc -strict-concurrency=complete` + 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 -Xswiftc -require-explicit-sendable -Xswiftc -strict-concurrency=complete" + linux_nightly_6_0_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable" + linux_nightly_main_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable" + + cxx-interop: + name: Cxx interop + uses: apple/swift-nio/.github/workflows/cxx_interop.yml@main \ No newline at end of file diff --git a/.github/workflows/pull_request_label.yml b/.github/workflows/pull_request_label.yml new file mode 100644 index 0000000..26ce2fc --- /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 \ No newline at end of file diff --git a/.licenseignore b/.licenseignore new file mode 100644 index 0000000..faaee3c --- /dev/null +++ b/.licenseignore @@ -0,0 +1,36 @@ +.gitignore +**/.gitignore +.licenseignore +.gitattributes +.git-blame-ignore-revs +.mailfilter +.mailmap +.spi.yml +.swift-format +.swiftformatignore +.editorconfig +.github/* +*.md +*.txt +*.yml +*.yaml +*.json +Package.swift +**/Package.swift +Package@-*.swift +**/Package@-*.swift +Package.resolved +**/Package.resolved +Makefile +*.modulemap +**/*.modulemap +**/*.docc/* +*.xcprivacy +**/*.xcprivacy +*.symlink +**/*.symlink +Dockerfile +**/Dockerfile +Snippets/* +dev/git.commit.template +.unacceptablelanguageignore \ No newline at end of file diff --git a/.spi.yml b/.spi.yml new file mode 100644 index 0000000..89bbb70 --- /dev/null +++ b/.spi.yml @@ -0,0 +1,5 @@ +version: 1 +builder: + configs: + - documentation_targets: + - OpenAPIHummingbird \ No newline at end of file diff --git a/.swift-format b/.swift-format index e6a70ed..1c71362 100644 --- a/.swift-format +++ b/.swift-format @@ -14,9 +14,9 @@ "lineLength" : 120, "maximumBlankLines" : 1, "prioritizeKeepingFunctionOutputTogether" : false, - "respectsExistingLineBreaks" : true, + "respectsExistingLineBreaks" : false, "rules" : { - "AllPublicDeclarationsHaveDocumentation" : false, + "AllPublicDeclarationsHaveDocumentation" : true, "AlwaysUseLowerCamelCase" : false, "AmbiguousTrailingClosureOverload" : true, "BeginDocumentationCommentWithOneLineSummary" : false, @@ -50,9 +50,9 @@ "UseSynthesizedInitializer" : true, "UseTripleSlashForDocumentationComments" : true, "UseWhereClausesInForLoops" : false, - "ValidateDocumentationComments" : false + "ValidateDocumentationComments" : true }, "spacesAroundRangeFormationOperators" : false, "tabWidth" : 8, "version" : 1 -} +} \ No newline at end of file diff --git a/Sources/OpenAPIHummingbird/OpenAPITransport.swift b/Sources/OpenAPIHummingbird/OpenAPITransport.swift index 2001cb6..c740d60 100644 --- a/Sources/OpenAPIHummingbird/OpenAPITransport.swift +++ b/Sources/OpenAPIHummingbird/OpenAPITransport.swift @@ -18,6 +18,10 @@ import Hummingbird import NIOHTTP1 import OpenAPIRuntime +struct TaskLocalRequestContext { + @TaskLocal static var instance: Context? +} + extension RouterMethods { /// Registers an HTTP operation handler at the provided path and method. /// - Parameters: @@ -39,7 +43,10 @@ extension RouterMethods { ) { request, context in let (openAPIRequest, openAPIRequestBody) = try request.makeOpenAPIRequest(context: context) let openAPIRequestMetadata = context.makeOpenAPIRequestMetadata() - let (openAPIResponse, openAPIResponseBody) = try await handler(openAPIRequest, openAPIRequestBody, openAPIRequestMetadata) + let (openAPIResponse, openAPIResponseBody) = try await TaskLocalRequestContext.$instance.withValue(context) { + TaskLocalRequestContext.instance?.logger.info("Yeah") + try await handler(openAPIRequest, openAPIRequestBody, openAPIRequestMetadata) + } return Response(openAPIResponse, body: openAPIResponseBody) } } diff --git a/docker/Dockerfile b/docker/Dockerfile deleted file mode 100644 index 080dd58..0000000 --- a/docker/Dockerfile +++ /dev/null @@ -1,23 +0,0 @@ -ARG swift_version=5.9 -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 - -# 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 diff --git a/docker/docker-compose.2204.59.yaml b/docker/docker-compose.2204.59.yaml deleted file mode 100644 index 4027ea4..0000000 --- a/docker/docker-compose.2204.59.yaml +++ /dev/null @@ -1,16 +0,0 @@ -version: "3" - -services: - - runtime-setup: - image: swift-openapi-hummingbird:22.04-5.9 - build: - args: - ubuntu_version: "jammy" - swift_version: "5.9" - - test: - image: swift-openapi-hummingbird:22.04-5.9 - - shell: - image: swift-openapi-hummingbird:22.04-5.9 \ No newline at end of file diff --git a/docker/docker-compose.2204.main.yaml b/docker/docker-compose.2204.main.yaml deleted file mode 100644 index 58c97f2..0000000 --- a/docker/docker-compose.2204.main.yaml +++ /dev/null @@ -1,15 +0,0 @@ -version: "3" - -services: - - runtime-setup: - image: swift-openapi-hummingbird:22.04-main - build: - args: - base_image: "swiftlang/swift:nightly-main-jammy" - - test: - image: swift-openapi-hummingbird:22.04-main - - shell: - image: swift-openapi-hummingbird:22.04-main \ No newline at end of file diff --git a/docker/docker-compose.yaml b/docker/docker-compose.yaml deleted file mode 100644 index 872e04c..0000000 --- a/docker/docker-compose.yaml +++ /dev/null @@ -1,35 +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.50.yaml run test -version: "3" - -services: - - runtime-setup: - image: swift-openapi-hummingbird:default - build: - context: . - dockerfile: Dockerfile - - common: &common - image: swift-openapi-hummingbird:default - depends_on: [runtime-setup] - volumes: - - ~/.ssh:/root/.ssh - - ..:/code:z - working_dir: /code - cap_drop: - - CAP_NET_RAW - - CAP_NET_BIND_SERVICE - - soundness: - <<: *common - command: /bin/bash -xcl "./scripts/soundness.sh" - - test: - <<: *common - command: /bin/bash -xcl "swift test --parallel -Xswiftc -warnings-as-errors --enable-test-discovery $${SANITIZER_ARG-} $${IMPORT_CHECK_ARG-}" - - shell: - <<: *common - entrypoint: /bin/bash