Skip to content

Commit

Permalink
Merge pull request #18 from GNMoseke/feat/add-ci
Browse files Browse the repository at this point in the history
Add CI
  • Loading branch information
GNMoseke authored Jul 10, 2024
2 parents d4426bc + 60847be commit f004b0d
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 19 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Test
on:
pull_request:
push:
branches: [ "main" ]

jobs:
lint:
name: Check Formatting
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: SwiftFormat lint
run: swift package plugin --allow-writing-to-package-directory swiftformat --lint

test-macos:
name: Test macOS using Xcode latest-stable
runs-on: macos-latest
steps:
- uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: latest-stable
- uses: actions/checkout@v3
- name: Run tests
run: swift test -Xswiftc -warnings-as-errors -Xcc -Werror

test-ubuntu:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Run tests
run: swift test -Xswiftc -warnings-as-errors -Xcc -Werror
19 changes: 9 additions & 10 deletions Package.resolved
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"originHash" : "c7255001446bd98c112bebfa74fcc93a637a4396e1766caea89b32ebc901334f",
"pins" : [
{
"identity" : "puppy",
Expand All @@ -24,17 +23,17 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-async-algorithms",
"state" : {
"revision" : "da4e36f86544cdf733a40d59b3a2267e3a7bbf36",
"version" : "1.0.0"
"revision" : "6ae9a051f76b81cc668305ceed5b0e0a7fd93d20",
"version" : "1.0.1"
}
},
{
"identity" : "swift-collections",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-collections.git",
"state" : {
"revision" : "94cf62b3ba8d4bed62680a282d4c25f9c63c2efb",
"version" : "1.1.0"
"revision" : "3d2dc41a01f9e49d84f0a3925fb858bed64f702d",
"version" : "1.1.2"
}
},
{
Expand All @@ -51,8 +50,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-system",
"state" : {
"revision" : "f9266c85189c2751589a50ea5aec72799797e471",
"version" : "1.3.0"
"revision" : "6a9e38e7bd22a3b8ba80bddf395623cf68f57807",
"version" : "1.3.1"
}
},
{
Expand All @@ -69,10 +68,10 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/nicklockwood/SwiftFormat",
"state" : {
"revision" : "4bf475154c1c98dcdf751037f930f8e5c72597a4",
"version" : "0.53.10"
"revision" : "dd989a46d0c6f15c016484bab8afe5e7a67a4022",
"version" : "0.54.0"
}
}
],
"version" : 3
"version" : 2
}
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version: 5.10
// swift-tools-version: 5.9

import PackageDescription

Expand Down
29 changes: 27 additions & 2 deletions Sources/Logging.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@
import Foundation
import Puppy

func configureLogging(_ level: LogLevel) throws -> Puppy {
func configureLogging(_ level: String, testing: Bool = false) throws -> Puppy {
if testing {
return Puppy()
}

// TODO: logfile per project
// And also make this nicer for unit tests
let logFormat = LogFormatter()
let fileLogger = try FileLogger(
"com.peregrine",
logLevel: level,
logLevel: LogLevel(from: level),
logFormat: logFormat,
fileURL: URL(fileURLWithPath: "/tmp/peregrine.log").absoluteURL
)
Expand All @@ -21,6 +25,27 @@ func configureLogging(_ level: LogLevel) throws -> Puppy {
return logger
}

extension LogLevel {
init(from string: String) {
switch string {
case "trace":
self = .trace
case "debug":
self = .debug
case "verbose":
self = .verbose
case "warning":
self = .warning
case "error":
self = .error
case "critical":
self = .critical
default:
self = .info
}
}
}

func cleanupLogFile(logger: Puppy) throws {
// ensure we fully flush anything left before removing the file
_ = logger.flush()
Expand Down
8 changes: 4 additions & 4 deletions Sources/Peregrine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@ struct Peregrine: AsyncParsableCommand {
@Flag(help: "Supress toolchain information & progress output")
var quiet: Bool = false

@Option(help: "Control Peregrine's log level (1-7, with 1 being the most granular)")
var logLevel: LogLevel = .debug
@Option(
help: "Control Peregrine's log level. Default is 'info'. Options: [trace, verbose, debug, info, warning, error, critical]"
)
var logLevel: String = "info"
}
}

Expand Down Expand Up @@ -234,5 +236,3 @@ private func tputCnorm() {
enum PeregrineError: Error {
case couldNotFindSwiftExecutable
}

extension LogLevel: ExpressibleByArgument {}
2 changes: 1 addition & 1 deletion Sources/TestRunner.swift
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ private func parseTestFromName(_ testName: String, line: String) throws -> Test
// example line:
// Test Case 'PeregrineTests.testRunSingleFail' passed (0.459 seconds)
let nameComponents = testName.split(separator: ".")
guard var testSuite = nameComponents.first, var testName = nameComponents.last else {
guard let testSuite = nameComponents.first, let testName = nameComponents.last else {
throw TestParseError.unexpectedLineFormat("could not parse test name from line: \(line)")
}
#endif
Expand Down
2 changes: 1 addition & 1 deletion Tests/PeregrineTests/PeregrineTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class PeregrineTests: XCTestCase {
)
)

runner = try PeregrineRunner(options: testOptions, logger: configureLogging(.debug))
runner = try PeregrineRunner(options: testOptions, logger: configureLogging("", testing: true))
}

func testParseList() async throws {
Expand Down

0 comments on commit f004b0d

Please sign in to comment.