diff --git a/.github/workflows/documentation.yml b/.github/workflows/documentation.yml
deleted file mode 100644
index 4b575a9..0000000
--- a/.github/workflows/documentation.yml
+++ /dev/null
@@ -1,45 +0,0 @@
-name: Pages Deploy
-
-on:
- push:
- branches: [main]
-
-# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
-permissions:
- contents: read
- pages: write
- id-token: write
-
-# Allow one concurrent deployment
-concurrency:
- group: "pages"
- cancel-in-progress: true
-
-jobs:
- # Single deploy job since we're just deploying
- deploy:
- environment:
- # Must be set to this for deploying to GitHub Pages
- name: github-pages
- url: ${{ steps.deployment.outputs.page_url }}
- runs-on: macos-latest
- steps:
- - name: Checkout 🛎️
- uses: actions/checkout@v3
- - name: Build DocC
- run: |
- swift package --allow-writing-to-directory ./docs \
- generate-documentation --target HPNetwork \
- --transform-for-static-hosting \
- --hosting-base-path HPNetwork \
- --output-path ./docs
- - name: Fix Root Path
- run: echo "" > docs/index.html
- - name: Upload artifact
- uses: actions/upload-pages-artifact@v1
- with:
- # Upload only docs directory
- path: 'docs'
- - name: Deploy to GitHub Pages
- id: deployment
- uses: actions/deploy-pages@v1
\ No newline at end of file
diff --git a/.github/workflows/swift.yml b/.github/workflows/swift.yml
index a13f7a3..c8f6b0d 100644
--- a/.github/workflows/swift.yml
+++ b/.github/workflows/swift.yml
@@ -1,4 +1,4 @@
-name: Code Testing
+name: Swift
on:
push:
@@ -7,13 +7,100 @@ on:
branches: [main]
jobs:
- build:
- runs-on: macos-latest
-
+ test-swift:
+ name: Test Swift Code
+ runs-on: macos-14
steps:
- - name: Checkout 🛎️
- uses: actions/checkout@v3
+ - name: Configure Xcode
+ uses: maxim-lobanov/setup-xcode@v1
+ with:
+ xcode-version: latest-stable
+ - name: Checkout Code
+ uses: actions/checkout@v4
+ - name: Cache SPM dependencies
+ uses: actions/cache@v4
+ with:
+ path: .build
+ key: ${{ runner.os }}-spm-${{ hashFiles('**/Package.resolved') }}
+ restore-keys: |
+ ${{ runner.os }}-spm-
- name: Build
run: swift build -v
- name: Run tests
- run: swift test -v
+ run: swift test --enable-code-coverage -v
+ - name: Convert coverage report
+ run: Scripts/convert-coverage-report --target HPNetworkPackageTests
+ - name: Upload coverage reports to Codecov
+ uses: codecov/codecov-action@v4
+ with:
+ token: ${{ secrets.CODECOV_TOKEN }}
+ slug: henrik-dmg/HPNetwork
+
+ lint-code:
+ name: Lint Swift Code
+ runs-on: macos-14
+ steps:
+ - name: Configure Xcode
+ uses: maxim-lobanov/setup-xcode@v1
+ with:
+ xcode-version: latest-stable
+ - name: Checkout Code
+ uses: actions/checkout@v4
+ - name: Cache SPM dependencies
+ uses: actions/cache@v4
+ with:
+ path: .build
+ key: ${{ runner.os }}-spm-${{ hashFiles('**/Package.resolved') }}
+ restore-keys: |
+ ${{ runner.os }}-spm-
+ - name: Install SwiftLint
+ run: brew install swift-format peripheryapp/periphery/periphery
+ - name: Lint code
+ run: Scripts/lint-swift-code
+ - name: Scan for dead code
+ run: periphery scan --strict
+
+ deploy-pages:
+ name: Deploy Documentation to GitHub Pages
+ runs-on: macos-14
+ if: github.event_name != 'pull_request'
+ environment:
+ name: github-pages
+ url: ${{ steps.deployment.outputs.page_url }}
+ permissions:
+ pages: write # to deploy to Pages
+ id-token: write # to verify the deployment originates from an appropriate source
+ needs:
+ - test-swift
+ steps:
+ - name: Configure Xcode
+ uses: maxim-lobanov/setup-xcode@v1
+ with:
+ xcode-version: latest-stable
+ - name: Checkout Code
+ uses: actions/checkout@v4
+ - name: Cache SPM dependencies
+ uses: actions/cache@v4
+ with:
+ path: .build
+ key: ${{ runner.os }}-spm-${{ hashFiles('**/Package.resolved') }}
+ restore-keys: |
+ ${{ runner.os }}-spm-
+ - name: Build DocC
+ run: |
+ swift package \
+ --allow-writing-to-directory "$RUNNER_TEMP/docs" \
+ generate-documentation \
+ --target HPNetwork \
+ --transform-for-static-hosting \
+ --hosting-base-path HPNetwork \
+ --output-path "$RUNNER_TEMP/docs"
+ - name: Fix Root Path
+ run: echo "" > "$RUNNER_TEMP/docs/index.html"
+ - name: Upload artifact
+ uses: actions/upload-pages-artifact@v3
+ with:
+ path: ${{ runner.temp }}/docs
+ - name: Deploy to GitHub Pages
+ id: deployment
+ uses: actions/deploy-pages@v4
diff --git a/.gitignore b/.gitignore
index 0ca1966..709748f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -5,4 +5,5 @@
xcuserdata/
.swiftpm
icon-configuration.json
-.vscode
\ No newline at end of file
+.vscode
+/coverage
diff --git a/.periphery.yml b/.periphery.yml
new file mode 100644
index 0000000..85b884a
--- /dev/null
+++ b/.periphery.yml
@@ -0,0 +1 @@
+retain_public: true
diff --git a/.swift-format b/.swift-format.json
similarity index 69%
rename from .swift-format
rename to .swift-format.json
index 06530a2..e7bcf68 100644
--- a/.swift-format
+++ b/.swift-format.json
@@ -9,48 +9,59 @@
"indentSwitchCaseLabels": false,
"lineBreakAroundMultilineExpressionChainComponents": false,
"lineBreakBeforeControlFlowKeywords": false,
- "lineBreakBeforeEachArgument": false,
+ "lineBreakBeforeEachArgument": true,
"lineBreakBeforeEachGenericRequirement": false,
- "lineLength": 160,
+ "lineLength": 140,
"maximumBlankLines": 1,
+ "multiElementCollectionTrailingCommas": true,
+ "noAssignmentInExpressions": {
+ "allowedFunctions": ["XCTAssertNoThrow"]
+ },
"prioritizeKeepingFunctionOutputTogether": false,
"respectsExistingLineBreaks": true,
"rules": {
"AllPublicDeclarationsHaveDocumentation": false,
+ "AlwaysUseLiteralForEmptyCollectionInit": true,
"AlwaysUseLowerCamelCase": true,
"AmbiguousTrailingClosureOverload": true,
- "BeginDocumentationCommentWithOneLineSummary": false,
+ "BeginDocumentationCommentWithOneLineSummary": true,
"DoNotUseSemicolons": true,
"DontRepeatTypeInStaticProperties": true,
"FileScopedDeclarationPrivacy": true,
"FullyIndirectEnum": true,
"GroupNumericLiterals": true,
"IdentifiersMustBeASCII": true,
- "NeverForceUnwrap": false,
- "NeverUseForceTry": false,
+ "NeverForceUnwrap": true,
+ "NeverUseForceTry": true,
"NeverUseImplicitlyUnwrappedOptionals": false,
- "NoAccessLevelOnExtensionDeclaration": false,
+ "NoAccessLevelOnExtensionDeclaration": true,
+ "NoAssignmentInExpressions": true,
"NoBlockComments": true,
"NoCasesWithOnlyFallthrough": true,
"NoEmptyTrailingClosureParentheses": true,
"NoLabelsInCasePatterns": true,
"NoLeadingUnderscores": false,
"NoParensAroundConditions": true,
+ "NoPlaygroundLiterals": true,
"NoVoidReturnOnFunctionSignature": true,
+ "OmitExplicitReturns": true,
"OneCasePerLine": true,
"OneVariableDeclarationPerLine": true,
"OnlyOneTrailingClosureArgument": true,
"OrderedImports": true,
+ "ReplaceForEachWithForLoop": true,
"ReturnVoidInsteadOfEmptyTuple": true,
+ "TypeNamesShouldBeCapitalized": true,
"UseEarlyExits": false,
"UseLetInEveryBoundCaseVariable": true,
"UseShorthandTypeNames": true,
"UseSingleLinePropertyGetter": true,
"UseSynthesizedInitializer": true,
"UseTripleSlashForDocumentationComments": true,
- "UseWhereClausesInForLoops": false,
- "ValidateDocumentationComments": false
+ "UseWhereClausesInForLoops": true,
+ "ValidateDocumentationComments": true
},
+ "spacesAroundRangeFormationOperators": true,
"tabWidth": 4,
"version": 1
}
diff --git a/Assets/Banner.png b/Assets/Banner.png
deleted file mode 100644
index 3842afa..0000000
Binary files a/Assets/Banner.png and /dev/null differ
diff --git a/Assets/Logo.png b/Assets/Logo.png
deleted file mode 100644
index ee566b8..0000000
Binary files a/Assets/Logo.png and /dev/null differ
diff --git a/HPNetwork.podspec b/HPNetwork.podspec
deleted file mode 100644
index af2cc88..0000000
--- a/HPNetwork.podspec
+++ /dev/null
@@ -1,22 +0,0 @@
-Pod::Spec.new do |s|
- s.name = 'HPNetwork'
- s.version = '4.0.0-alpha.2'
- s.summary = 'A lightweight but customisable networking stack written in Swift'
-
- s.homepage = 'https://panhans.dev/opensource/hpnetwork'
- s.license = 'MIT'
- s.author = { 'Henrik Panhans' => 'henrik@panhans.dev' }
- s.social_media_url = 'https://twitter.com/henrik_dmg'
-
- s.ios.deployment_target = '13.0'
- s.watchos.deployment_target = '6.0'
- s.tvos.deployment_target = '13.0'
- s.osx.deployment_target = '10.15'
-
- s.source = { git: 'https://github.com/henrik-dmg/HPNetwork.git', tag: s.version }
- s.source_files = 'Sources/HPNetwork/**/*.swift'
- s.framework = 'Foundation'
-
- s.swift_version = '5.5'
- s.requires_arc = true
-end
diff --git a/Package.resolved b/Package.resolved
index 3c0709b..a5393b7 100644
--- a/Package.resolved
+++ b/Package.resolved
@@ -5,8 +5,17 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-argument-parser.git",
"state" : {
- "revision" : "9f39744e025c7d377987f30b03770805dcb0bcd1",
- "version" : "1.1.4"
+ "revision" : "fee6933f37fde9a5e12a1e4aeaa93fe60116ff2a",
+ "version" : "1.2.2"
+ }
+ },
+ {
+ "identity" : "swift-cmark",
+ "kind" : "remoteSourceControl",
+ "location" : "https://github.com/apple/swift-cmark.git",
+ "state" : {
+ "revision" : "29d9c97e6310b87c4799268eaa2fc76164b2dbd8",
+ "version" : "0.2.0"
}
},
{
@@ -15,7 +24,7 @@
"location" : "https://github.com/apple/swift-docc-plugin",
"state" : {
"branch" : "main",
- "revision" : "e013865138b53db901825fe4c002c9ec827a4109"
+ "revision" : "26ac5758409154cc448d7ab82389c520fa8a8247"
}
},
{
@@ -23,8 +32,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-docc-symbolkit",
"state" : {
- "branch" : "main",
- "revision" : "b45d1f2ed151d057b54504d653e0da5552844e34"
+ "revision" : "b45d1f2ed151d057b54504d653e0da5552844e34",
+ "version" : "1.0.0"
}
},
{
@@ -33,34 +42,34 @@
"location" : "https://github.com/apple/swift-format",
"state" : {
"branch" : "main",
- "revision" : "e5875f32d37d0de760bd4ca3b988f42373866f96"
+ "revision" : "235667552abb69db75ba9c45bdff901b1626c71d"
}
},
{
- "identity" : "swift-syntax",
+ "identity" : "swift-http-types",
"kind" : "remoteSourceControl",
- "location" : "https://github.com/apple/swift-syntax.git",
+ "location" : "https://github.com/apple/swift-http-types.git",
"state" : {
- "branch" : "main",
- "revision" : "f9985dda45b883f750f2fc0d47ee10893572cc22"
+ "revision" : "12358d55a3824bd5fed310b999ea8cf83a9a1a65",
+ "version" : "1.0.3"
}
},
{
- "identity" : "swift-system",
+ "identity" : "swift-markdown",
"kind" : "remoteSourceControl",
- "location" : "https://github.com/apple/swift-system.git",
+ "location" : "https://github.com/apple/swift-markdown.git",
"state" : {
- "revision" : "836bc4557b74fe6d2660218d56e3ce96aff76574",
- "version" : "1.1.1"
+ "revision" : "68b2fed9fb12fb71ac81e537f08bed430b189e35",
+ "version" : "0.2.0"
}
},
{
- "identity" : "swift-tools-support-core",
+ "identity" : "swift-syntax",
"kind" : "remoteSourceControl",
- "location" : "https://github.com/apple/swift-tools-support-core.git",
+ "location" : "https://github.com/apple/swift-syntax.git",
"state" : {
- "revision" : "284a41800b7c5565512ec6ae21ee818aac1f84ac",
- "version" : "0.4.0"
+ "branch" : "main",
+ "revision" : "09119754db685e6762d70e670567f522bd8828dd"
}
}
],
diff --git a/Package.swift b/Package.swift
index 916f44a..7e1337a 100644
--- a/Package.swift
+++ b/Package.swift
@@ -6,7 +6,7 @@ import PackageDescription
let package = Package(
name: "HPNetwork",
platforms: [
- .iOS(.v13), .tvOS(.v13), .watchOS(.v6), .macOS(.v10_15),
+ .iOS(.v15), .tvOS(.v15), .watchOS(.v6), .macOS(.v12),
],
products: [
.library(
@@ -14,27 +14,34 @@ let package = Package(
targets: ["HPNetwork"]
),
.library(
- name: "HPNetwork-Dynamic",
- type: .dynamic,
- targets: ["HPNetwork"]
- ),
- .library(
- name: "HPNetwork-Static",
- type: .static,
- targets: ["HPNetwork"]
+ name: "HPNetworkMock",
+ targets: ["HPNetworkMock"]
),
],
dependencies: [
.package(url: "https://github.com/apple/swift-docc-plugin", branch: "main"),
- .package(url: "https://github.com/apple/swift-format", branch: "main")
+ .package(url: "https://github.com/apple/swift-format", branch: "main"),
+ .package(url: "https://github.com/apple/swift-http-types.git", from: "1.0.0"),
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
// Targets can depend on other targets in this package, and on products in packages which this package depends on.
- .target(name: "HPNetwork"),
+ .target(
+ name: "HPNetwork",
+ dependencies: [
+ .product(name: "HTTPTypes", package: "swift-http-types"),
+ .product(name: "HTTPTypesFoundation", package: "swift-http-types"),
+ ]
+ ),
+ .target(
+ name: "HPNetworkMock",
+ dependencies: [
+ "HPNetwork"
+ ]
+ ),
.testTarget(
name: "HPNetworkTests",
- dependencies: ["HPNetwork"]
+ dependencies: ["HPNetwork", "HPNetworkMock"]
),
]
)
diff --git a/README.md b/README.md
index 0c2632a..7fac908 100644
--- a/README.md
+++ b/README.md
@@ -1,22 +1,16 @@
# HPNetwork
-![HPNetwork](/Assets/Banner.png)
-
-![Swift](https://github.com/henrik-dmg/HPNetwork/workflows/Swift/badge.svg)
+![Swift](https://github.com/henrik-dmg/HPNetwork/workflows/Swift/badge.svg) [![codecov](https://codecov.io/gh/henrik-dmg/HPNetwork/graph/badge.svg?token=WZU3LZK4VD)](https://codecov.io/gh/henrik-dmg/HPNetwork)
`HPNetwork` is a protocol-based networking stack written in pure Swift
## Installation
-### SPM
-
-Add a new dependency for `https://github.com/henrik-dmg/HPNetwork` to your Xcode project or `.package(url: "https://github.com/henrik-dmg/HPNetwork/tree/feature/async", from: "3.0.0")` to your `Package.swift`
+Starting with v4 HPNetwork is only available via Swift Package Manager.
-### CocoaPods
+Add a new dependency for `https://github.com/henrik-dmg/HPNetwork` to your Xcode project or `.package(url: "https://github.com/henrik-dmg/HPNetwork", from: "4.0.0")` to your `Package.swift`
-Add `pod 'HPNetwork'` to your Podfile and run `pod install`
-
-## Posting Request
+## Scheduling Requests
Scheduling a request is as easy as this:
@@ -26,17 +20,24 @@ let response = try await request.response()
The `response` is a `NetworkResponse