Skip to content

Commit

Permalink
Merge pull request #89 from MatsMoll/develop
Browse files Browse the repository at this point in the history
More open access to Kognita
  • Loading branch information
MatsMoll authored Dec 16, 2020
2 parents bb913c8 + 3147f82 commit 8acbc12
Show file tree
Hide file tree
Showing 8 changed files with 354 additions and 80 deletions.
72 changes: 72 additions & 0 deletions .github/workflows/master-job.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: MasterAction

on:
push:
branches:
- master

jobs:
check-doc-coverage:
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected]
- name: Calculate Documentation Coverage
uses: MatsMoll/swift-doc@master
with:
inputs: "Sources"
output: "dcov.json"
- name: Check Documentation Percent
run: sudo bash CI/check-percentage.sh dcov.json 1

bionic-tests:
needs: check-doc-coverage
services:
postgres:
image: postgres
ports:
- 5432:5432
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: postgres
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected]
- name: Run unit tests master
run: swift test --enable-test-discovery
env:
DATABASE_USER: postgres
DATABASE_PASSWORD: postgres
DATABASE_DB: postgres
DATABASE_HOSTNAME: localhost

release-docs:
needs: bionic-tests
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected]
- name: Generate Documentation
uses: SwiftDocOrg/swift-doc@master
with:
inputs: "Sources"
module-name: KognitaWeb
output: "Documentation"
- name: Upload Documentation to Wiki
uses: SwiftDocOrg/github-wiki-publish-action@v1
with:
path: "Documentation"
env:
GH_PERSONAL_ACCESS_TOKEN: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}

release-version:
needs: release-docs
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected]
- name: Release new version
uses: MatsMoll/action-finch@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_REPOSITORY: ${{ secrets.GITHUB_REPOSITORY }}
GITHUB_SHA: ${{ secrets.GITHUB_SHA }}
FINCH_CONFIG: CI/finch-config.yml
49 changes: 18 additions & 31 deletions .github/workflows/swift.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,30 @@
name: Swift
name: DevelopAction

on:
pull_request:
branches:
- master
- develop
push:
branches:
- master
- develop
- rc/*
- 1.*

jobs:
bionic-job:
check-doc-coverage:
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected]
- name: Calculate Documentation Coverage
uses: MatsMoll/swift-doc@master
with:
inputs: "Sources"
output: "dcov.json"
- name: Check Documentation Percent
run: sudo bash CI/check-percentage.sh dcov.json 1

bionic-tests:
needs: check-doc-coverage
services:
psql:
postgres:
image: postgres
ports:
- 5432:5432
Expand All @@ -26,33 +35,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected]
- name: GitHub Action for SwiftLint
uses: norio-nomura/[email protected]
- name: Run unit tests
if: github.ref != 'refs/heads/master'
run: swift test --enable-test-discovery
env:
BUILD_TYPE: DEV
DATABASE_USER: postgres
DATABASE_PASSWORD: postgres
DATABASE_DB: postgres
DATABASE_HOSTNAME: localhost
run: swift test
- name: Run unit tests master
if: github.ref == 'refs/heads/master'
env:
DATABASE_USER: postgres
DATABASE_PASSWORD: postgres
DATABASE_DB: postgres
DATABASE_HOSTNAME: localhost
run: swift test
- name: Build library in release mode
if: github.ref == 'refs/heads/master'
run: swift build -c release
- name: Release new version
uses: MatsMoll/action-finch@master
if: github.ref == 'refs/heads/master'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_REPOSITORY: ${{ secrets.GITHUB_REPOSITORY }}
GITHUB_SHA: ${{ secrets.GITHUB_SHA }}
FINCH_CONFIG: CI/finch-config.yml
DATABASE_HOSTNAME: localhost
11 changes: 11 additions & 0 deletions CI/check-percentage.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/sh
PERCENT="$(cat "$1" | jq ".data.totals.percent")"
THRESHOLD="$2"
if [ "${PERCENT%.*}" -ge "$THRESHOLD" ]
then
echo "Looking good with $PERCENT% coverage"
exit 0
else
echo "Only $PERCENT% coverage. Needs $THRESHOLD% or more"
exit 1
fi
15 changes: 15 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ var dependencies: [Package.Dependency] = [
.package(name: "vapor", url: "https://github.com/vapor/vapor.git", from: "4.29.0"),

.package(name: "HTMLKitVaporProvider", url: "https://github.com/MatsMoll/htmlkit-vapor-provider.git", from: "1.0.1"),

.package(url: "https://github.com/vapor-community/HTMLKit.git", from: "2.1.0"),
]

// Kognita Core
Expand All @@ -27,6 +29,19 @@ case "DEV":
]
)
default:
#if os(macOS)
if ProcessInfo.processInfo.environment["CUSTOM_SETTINGS"] == nil {
dependencies.append(contentsOf: [
.package(path: "../KognitaAPI"),
.package(path: "../KognitaCore"),
.package(path: "../KognitaViews"),
.package(path: "../KognitaModels")
]
)
break
}

#endif
let coreVersion = ProcessInfo.processInfo.environment["KOGNITA_CORE"] ?? "2.0.0"
let pagesVersion = ProcessInfo.processInfo.environment["KOGNITA_PAGES"] ?? "2.0.0"
let apiVersion = ProcessInfo.processInfo.environment["KOGNITA_API"] ?? "2.0.0"
Expand Down
1 change: 1 addition & 0 deletions Public/robots.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
User-agent: *
172 changes: 169 additions & 3 deletions Sources/App/HTMLKitErrorMiddleware.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,177 @@

import Vapor
import HTMLKit


//import Combine
//
///// Can represent a path e.g a `String` or a `Identifiable` object
//protocol EndpointPathItem {
// var pathDescription: String { get }
// var pathIdentifier: String { get }
//}
//
//extension String: EndpointPathItem {
// var pathDescription: String { self }
// var pathIdentifier: String { self }
//}
//
//struct SimpleGet: Endpoint {
// let method: Method = .get
// var pathComponents: [String]
//}
//
//struct SimplePost: Endpoint {
// let method: Method = .post
// var pathComponents: [String]
//
// func with<C: Codable>(content: C.Type) -> PostWithContent<C> { .init(pathComponents: pathComponents) }
//}
//
//struct PostWithContent<Content: Codable>: Endpoint {
// let method: Method = .get
// var pathComponents: [String]
//}
//
//enum Method {
// case post
// case get
// case put
// case delete
//}
//
//protocol Endpoint {
// var method: Method { get }
// var pathComponents: [String] { get }
//}
//
//struct ParameterPost<T: Identifiable>: Endpoint {
// let method: Method = .post
// var pathComponents: [String]
//
// func request<C: Codable>(body: C.Type) -> ParameterContentPost<T, C> { .init(pathComponents: pathComponents) }
//}
//
//struct ParameterContentPost<T: Identifiable, Content: Codable>: Endpoint {
// let method: Method = .post
// var pathComponents: [String]
//
// func respone<R: Codable>(body: R.Type) -> ParameterContentPostWithResponse<T, Content, R> {
// .init(pathComponents: pathComponents)
// }
//}
//
//struct ParameterContentPostWithResponse<T: Identifiable, Content: Codable, Response: Codable>: Endpoint {
// let method: Method = .post
// var pathComponents: [String]
//}
//
//enum EndpointBuilder {
// static func post<P: Identifiable>(to paths: String, _ parameter: P.Type) -> ParameterPost<P> {
// ParameterPost(pathComponents: [paths, ":\(String(reflecting: P.self))"])
// }
//}
//
//// Some extensions only available in the Vapor code
//extension Endpoint {
// var vaporPathComponents: [PathComponent] {
// pathComponents.map { path in
// if path.hasPrefix(":") {
// return .parameter(String(path.dropFirst()))
// } else {
// return .constant(path)
// }
// }
// }
//}
//
//extension ParameterContentPostWithResponse {
// func resolve(req: Request, implementation: (T.ID, Content, Request) -> EventLoopFuture<Response>) -> EventLoopFuture<Response> {
// let id = req.parameters.get(String(reflecting: T.self)) as! T.ID // Needs some String literal init for the ID
// let content = try! req.content.decode(Content.self)
// return implementation(id, content, req)
// }
//}
//
//extension ParameterContentPostWithResponse where Response: Vapor.Response {
//
// func register(in route: RoutesBuilder, _ implementation: (T.ID, Content, Request) -> EventLoopFuture<Response>) {
// route.on(.POST, vaporPathComponents) { (req) -> EventLoopFuture<Response> in
// resolve(req: req, implementation: implementation)
// }
// }
//}
//
//// Some extensions only available in the iOS code
//extension ParameterContentPostWithResponse {
// func request(with id: T.ID, content: Content, baseURL: URL) -> AnyPublisher<Response, Error> {
// let url = baseURL.appendingPathComponent(pathComponents.first! + "/\(id)")
// var urlRequest = URLRequest(url: url)
// urlRequest.httpMethod = "POST"
// urlRequest.httpBody = try! JSONEncoder().encode(content)
// return URLSession.shared.dataTaskPublisher(for: urlRequest)
// .map(\.data)
// .decode(type: Response.self, decoder: JSONDecoder())
// .eraseToAnyPublisher()
// }
//}
//
//extension ParameterPost {
// func resolve(req: Request, function: (T.ID, Request) -> EventLoopFuture<Void>) -> EventLoopFuture<Void> {
// let id = req.parameters.get(String(reflecting: T.self))
// return function(id as! T.ID, req)
// }
//}
//
//extension ParameterContentPost {
// func resolve(req: Request, implementation: (T.ID, Content, Request) -> EventLoopFuture<Void>) -> EventLoopFuture<Void> {
// let id = req.parameters.get(String(reflecting: T.self)) as! T.ID // Needs some string literal init for the ID
// let content = try! req.content.decode(Content.self)
// return implementation(id, content, req)
// }
//
// func register(in route: RoutesBuilder, _ implementation: (T.ID, Content, Request) -> EventLoopFuture<Void>) {
// route.on(.POST, vaporPathComponents) { (req) -> EventLoopFuture<HTTPStatus> in
// self.resolve(req: req, implementation: implementation)
// .transform(to: .ok)
// }
// }
//}
//
//extension PostWithContent {
// func resolve(req: Request, function: (Content, Request) -> EventLoopFuture<Void>) -> EventLoopFuture<Void> {
// let content = try! req.content.decode(Content.self)
// return function(content, req)
// }
//}
//
//
//extension ParameterPost {
// func request(with id: T.ID, baseURL: URL) -> URLSession.DataTaskPublisher {
// let url = baseURL.appendingPathComponent(pathComponents.first! + "/\(id)")
// return URLSession.shared.dataTaskPublisher(for: url)
// }
//}
//
//extension ParameterContentPost {
// func request(with id: T.ID, content: Content, baseURL: URL) -> URLSession.DataTaskPublisher {
// let url = baseURL.appendingPathComponent(pathComponents.first! + "/\(id)")
// var urlRequest = URLRequest(url: url)
// urlRequest.httpBody = try! JSONEncoder().encode(content)
// return URLSession.shared.dataTaskPublisher(for: urlRequest)
// }
//}
//
//extension PostWithContent {
// func makeRequest(with content: Content, baseURL: URL) -> URLSession.DataTaskPublisher {
// let url = baseURL.appendingPathComponent(pathComponents.first!)
// var urlRequest = URLRequest(url: url)
// urlRequest.httpMethod = "POST"
// urlRequest.httpBody = try! JSONEncoder().encode(content)
// return URLSession.shared.dataTaskPublisher(for: urlRequest)
// }
//}
/// Captures all errors and transforms them into an internal server error.
public struct HTMLKitErrorMiddleware<F: HTMLPage, S: HTMLPage>: Middleware {

/// A path to ignore
let ignorePath: String

Expand Down
Loading

0 comments on commit 8acbc12

Please sign in to comment.