Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .github/workflows/swift_format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: Lint
on: pull_request

jobs:
Lint:
runs-on: macos-latest
steps:
- uses: actions/checkout@v3
- name: SwiftFormat
run: swiftformat --lint . --reporter github-actions-log
2 changes: 1 addition & 1 deletion .swift-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5.8
5.10
37 changes: 37 additions & 0 deletions .swiftformat
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
--allman false
--binarygrouping none
--closingparen balanced
--commas inline
--conflictmarkers reject
--decimalgrouping 3,4
--elseposition same-line
--guardelse auto
--empty void
--exponentcase lowercase
--exponentgrouping disabled
--fractiongrouping disabled
--fragment false
--hexgrouping none
--hexliteralcase uppercase
--ifdef no-indent
--importgrouping alphabetized
--indent 4
--indentcase false
--linebreaks lf
--octalgrouping none
--operatorfunc spaced
--patternlet hoist
--nospaceoperators
--self init-only
--selfrequired
--semicolons inline
--someAny true
--stripunusedargs closure-only
--trailingclosures
--trimwhitespace always
--wraparguments preserve
--wrapcollections preserve
--wrapparameters preserve
--modifierorder public,override
--xcodeindentation enabled
--disable redundantObjc,wrapMultilineStatementBraces,genericExtensions
6 changes: 3 additions & 3 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import PackageDescription
let package = Package(
name: "Cachi",
platforms: [
.macOS(.v13),
.macOS(.v13)
],
dependencies: [
.package(url: "https://github.com/Subito-it/CachiKit", branch: "master"),
.package(url: "https://github.com/Subito-it/Bariloche", branch: "master"),
.package(url: "https://github.com/tcamin/Vaux", branch: "cachi"),
.package(url: "https://github.com/michaeleisel/ZippyJSON", branch: "master"),
.package(url: "https://github.com/vapor/vapor.git", from: "4.77.1"),
.package(url: "https://github.com/vapor/vapor.git", from: "4.77.1")
],
targets: [
.executableTarget(
Expand All @@ -23,6 +23,6 @@ let package = Package(
.testTarget(
name: "CachiTests",
dependencies: ["Cachi"]
),
)
]
)
7 changes: 3 additions & 4 deletions Sources/Cachi/Server/Routes/AttachmentRoute.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,13 @@ struct AttachmentRoute: Routable {
}

var headers = [
("Content-Type", contentType),
("Content-Type", contentType)
]

if let filename = queryItems.first(where: { $0.name == "filename" })?.value?.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed),
let fileAttributes = try? FileManager.default.attributesOfItem(atPath: destinationPath),
let bytes = fileAttributes[.size] as? Int64,
bytes > 100 * 1024
{
bytes > 100 * 1_024 {
headers.append(("Content-Disposition", value: "attachment; filename=\(filename)"))
}

Expand All @@ -71,7 +70,7 @@ struct AttachmentRoute: Routable {
.init(name: "id", value: identifier),
.init(name: "test_id", value: testSummaryIdentifier),
.init(name: "filename", value: filename),
.init(name: "content_type", value: contentType),
.init(name: "content_type", value: contentType)
]

components.queryItems = components.queryItems?.filter { !($0.value?.isEmpty ?? true) }
Expand Down
7 changes: 3 additions & 4 deletions Sources/Cachi/Server/Routes/CSSRoute.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@ struct CSSRoute: Routable {
return Response(status: .notFound, body: Response.Body(stringLiteral: "Not found..."))
}

let cssContent: String?
switch imageIdentifier {
case "main": cssContent = mainCSS()
default: cssContent = nil
let cssContent: String? = switch imageIdentifier {
case "main": mainCSS()
default: nil
}

guard cssContent != nil else {
Expand Down
2 changes: 1 addition & 1 deletion Sources/Cachi/Server/Routes/CoverageFileRouteHTML.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ struct CoverageFileRouteHTML: Routable {
var components = URLComponents(string: path)!
components.queryItems = [
.init(name: "id", value: resultIdentifier),
.init(name: "path", value: path),
.init(name: "path", value: path)
]

components.queryItems = components.queryItems?.filter { !($0.value?.isEmpty ?? true) }
Expand Down
19 changes: 9 additions & 10 deletions Sources/Cachi/Server/Routes/CoverageRouteHTML.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ struct CoverageRouteHTML: Routable {
var components = URLComponents(string: path)!
components.queryItems = [
.init(name: "id", value: resultIdentifier),
.init(name: "back_url", value: backUrl.hexadecimalRepresentation),
.init(name: "back_url", value: backUrl.hexadecimalRepresentation)
]

components.queryItems = components.queryItems?.filter { !($0.value?.isEmpty ?? true) }
Expand Down Expand Up @@ -115,7 +115,7 @@ struct CoverageRouteHTML: Routable {
var components = URLComponents(string: Self.path)!
components.queryItems = [
.init(name: "id", value: result.identifier),
.init(name: "back_url", value: backUrl.hexadecimalRepresentation),
.init(name: "back_url", value: backUrl.hexadecimalRepresentation)
]

components.queryItems = components.queryItems?.filter { !($0.value?.isEmpty ?? true) }
Expand Down Expand Up @@ -143,15 +143,14 @@ private extension CoverageRouteHTML {
init(hexadecimalRepresentation: String?) {
if let hexadecimalRepresentation,
let data = Data(hexadecimalRepresentation: hexadecimalRepresentation),
let state = try? ZippyJSONDecoder().decode(RouteState.self, from: data)
{
showFilter = state.showFilter
filterQuery = state.filterQuery
hideFilters = state.hideFilters
let state = try? ZippyJSONDecoder().decode(RouteState.self, from: data) {
self.showFilter = state.showFilter
self.filterQuery = state.filterQuery
self.hideFilters = state.hideFilters
} else {
showFilter = .files
filterQuery = ""
hideFilters = false
self.showFilter = .files
self.filterQuery = ""
self.hideFilters = false
}
}

Expand Down
27 changes: 13 additions & 14 deletions Sources/Cachi/Server/Routes/ImageRoute.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,19 @@ struct ImageRoute: Routable {
return Response(status: .notFound, body: Response.Body(stringLiteral: "Not found..."))
}

let imageContent: StaticString?
switch imageIdentifier {
case "imageTestPass": imageContent = imageTestPass()
case "imageTestFail": imageContent = imageTestFail()
case "imageTestRetried": imageContent = imageTestRetried()
case "imageTestGray": imageContent = imageTestGray()
case "imageArrowLeft": imageContent = imageArrowLeft()
case "imageArrowRight": imageContent = imageArrowRight()
case "imageArrowDown": imageContent = imageArrowDown()
case "imageLink": imageContent = imageLink()
case "imagePlaceholder": imageContent = imagePlaceholder()
case "imageAttachment": imageContent = imageAttachment()
case "imageEmpty": imageContent = imageEmpty()
default: imageContent = nil
let imageContent: StaticString? = switch imageIdentifier {
case "imageTestPass": imageTestPass()
case "imageTestFail": imageTestFail()
case "imageTestRetried": imageTestRetried()
case "imageTestGray": imageTestGray()
case "imageArrowLeft": imageArrowLeft()
case "imageArrowRight": imageArrowRight()
case "imageArrowDown": imageArrowDown()
case "imageLink": imageLink()
case "imagePlaceholder": imagePlaceholder()
case "imageAttachment": imageAttachment()
case "imageEmpty": imageEmpty()
default: nil
}

if let imageContent {
Expand Down
30 changes: 14 additions & 16 deletions Sources/Cachi/Server/Routes/ResultRouteHTML.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ struct ResultRouteHTML: Routable {
var components = URLComponents(string: path)!
components.queryItems = [
.init(name: "id", value: resultIdentifier),
.init(name: "back_url", value: backUrl.hexadecimalRepresentation),
.init(name: "back_url", value: backUrl.hexadecimalRepresentation)
]

components.queryItems = components.queryItems?.filter { !($0.value?.isEmpty ?? true) }
Expand Down Expand Up @@ -183,16 +183,15 @@ struct ResultRouteHTML: Routable {
}

private func resultsTableHTML(result: ResultBundle, state: RouteState, backUrl: String) -> HTML {
var tests: [ResultBundle.Test]
switch state.showFilter {
var tests: [ResultBundle.Test] = switch state.showFilter {
case .failed:
tests = result.testsFailedExcludingRetries()
result.testsFailedExcludingRetries()
case .passed:
tests = result.testsPassed
result.testsPassed
case .retried:
tests = result.testsFailedRetring
result.testsFailedRetring
default:
tests = result.tests
result.tests
}

if state.showSystemFailures, state.showFilter != .retried {
Expand Down Expand Up @@ -269,7 +268,7 @@ struct ResultRouteHTML: Routable {
var components = URLComponents(string: path)!
components.queryItems = [
.init(name: "id", value: result.identifier),
.init(name: "back_url", value: backUrl.hexadecimalRepresentation),
.init(name: "back_url", value: backUrl.hexadecimalRepresentation)
]

components.queryItems = components.queryItems?.filter { !($0.value?.isEmpty ?? true) }
Expand Down Expand Up @@ -301,15 +300,14 @@ private extension ResultRouteHTML {
init(hexadecimalRepresentation: String?) {
if let hexadecimalRepresentation,
let data = Data(hexadecimalRepresentation: hexadecimalRepresentation),
let state = try? ZippyJSONDecoder().decode(RouteState.self, from: data)
{
showFilter = state.showFilter
showFailureMessage = state.showFailureMessage
showSystemFailures = state.showSystemFailures
let state = try? ZippyJSONDecoder().decode(RouteState.self, from: data) {
self.showFilter = state.showFilter
self.showFailureMessage = state.showFailureMessage
self.showSystemFailures = state.showSystemFailures
} else {
showFilter = .all
showFailureMessage = false
showSystemFailures = false
self.showFilter = .all
self.showFailureMessage = false
self.showSystemFailures = false
}
}

Expand Down
7 changes: 3 additions & 4 deletions Sources/Cachi/Server/Routes/ResultsRouteHTML.swift
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,10 @@ private extension ResultsRouteHTML {
init(hexadecimalRepresentation: String?) {
if let hexadecimalRepresentation,
let data = Data(hexadecimalRepresentation: hexadecimalRepresentation),
let state = try? ZippyJSONDecoder().decode(RouteState.self, from: data)
{
showSystemFailures = state.showSystemFailures
let state = try? ZippyJSONDecoder().decode(RouteState.self, from: data) {
self.showSystemFailures = state.showSystemFailures
} else {
showSystemFailures = false
self.showSystemFailures = false
}
}

Expand Down
4 changes: 2 additions & 2 deletions Sources/Cachi/Server/Routes/ResultsStatRouteHTML.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ struct ResultsStatRouteHTML: Routable {
static func urlString(backUrl: String) -> String {
var components = URLComponents(string: path)!
components.queryItems = [
.init(name: "back_url", value: backUrl.hexadecimalRepresentation),
.init(name: "back_url", value: backUrl.hexadecimalRepresentation)
]

components.queryItems = components.queryItems?.filter { !($0.value?.isEmpty ?? true) }
Expand Down Expand Up @@ -172,7 +172,7 @@ struct ResultsStatRouteHTML: Routable {
.init(name: "target", value: selectedTarget),
.init(name: "device", value: selectedDevice),
.init(name: "back_url", value: backUrl.hexadecimalRepresentation),
.init(name: type(of: statType).queryName, value: statType.rawValue),
.init(name: type(of: statType).queryName, value: statType.rawValue)
]

components.queryItems = components.queryItems?.filter { !($0.value?.isEmpty ?? true) }
Expand Down
8 changes: 3 additions & 5 deletions Sources/Cachi/Server/Routes/ScriptRoute.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,14 @@ struct ScriptRoute: Routable {
let resultBundles = State.shared.resultBundles

if let resultIdentifier = queryItems.first(where: { $0.name == "id" })?.value,
let resultBundle = resultBundles.first(where: { $0.identifier == resultIdentifier })
{
let resultBundle = resultBundles.first(where: { $0.identifier == resultIdentifier }) {
scriptContent = scriptFilesCoverage(resultBundle: resultBundle)
}
case "coverage-folders":
let resultBundles = State.shared.resultBundles

if let resultIdentifier = queryItems.first(where: { $0.name == "id" })?.value,
let resultBundle = resultBundles.first(where: { $0.identifier == resultIdentifier })
{
let resultBundle = resultBundles.first(where: { $0.identifier == resultIdentifier }) {
scriptContent = scriptFoldersCoverage(resultBundle: resultBundle)
}
case "result-stat":
Expand Down Expand Up @@ -68,7 +66,7 @@ struct ScriptRoute: Routable {
var components = URLComponents(string: path)!
components.queryItems = [
.init(name: "id", value: resultIdentifier),
.init(name: "type", value: type),
.init(name: "type", value: type)
]

components.queryItems = components.queryItems?.filter { !($0.value?.isEmpty ?? true) }
Expand Down
3 changes: 1 addition & 2 deletions Sources/Cachi/Server/Routes/TestRoute.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ struct TestRoute: Routable {
defer { os_log("Result bundle with id '%@' fetched in %fms", log: .default, type: .info, testSummaryIdentifier, benchmarkStop(benchId)) }

if let summaries = State.shared.testActionActivitySummaries(summaryIdentifier: testSummaryIdentifier),
let bodyData = try? JSONEncoder().encode(summaries)
{
let bodyData = try? JSONEncoder().encode(summaries) {
return Response(body: Response.Body(data: bodyData))
} else {
return Response(status: .internalServerError, body: Response.Body(stringLiteral: "Ouch..."))
Expand Down
Loading