Skip to content

Commit ad4be85

Browse files
committed
ci: add test, fmt, lint workflows
1 parent eb61235 commit ad4be85

25 files changed

+277
-138
lines changed

Diff for: .github/workflows/ci.yml

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: ci
2+
3+
on:
4+
pull_request:
5+
paths-ignore:
6+
- "README.md"
7+
push:
8+
branches:
9+
- main
10+
paths-ignore:
11+
- "README.md"
12+
13+
14+
permissions:
15+
contents: read
16+
17+
jobs:
18+
test:
19+
name: test
20+
runs-on: ${{ github.repository_owner == 'coder' && 'depot-macos-latest' || 'macos-latest'}}
21+
steps:
22+
- name: Checkout
23+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
24+
with:
25+
fetch-depth: 1
26+
- name: Switch XCode Version
27+
uses: maxim-lobanov/setup-xcode@v1
28+
with:
29+
xcode-version: '16.0.0'
30+
- run: |
31+
make test
32+
working-directory: Coder Desktop
33+
format:
34+
name: format
35+
runs-on: ${{ github.repository_owner == 'coder' && 'depot-macos-latest' || 'macos-latest'}}
36+
steps:
37+
- name: Checkout
38+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
39+
with:
40+
fetch-depth: 1
41+
- run: |
42+
make fmt
43+
working-directory: Coder Desktop
44+
lint:
45+
name: lint
46+
runs-on: ${{ github.repository_owner == 'coder' && 'depot-macos-latest' || 'macos-latest'}}
47+
steps:
48+
- name: Checkout
49+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
50+
with:
51+
fetch-depth: 1
52+
- name: Install Swiftlint
53+
run: |
54+
brew install swiftlint
55+
- run: |
56+
make lint
57+
working-directory: Coder Desktop

Diff for: Coder Desktop/.swiftlint.yml

+3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
disabled_rules:
22
- todo
33
- trailing_comma
4+
- blanket_disable_command # Used by Protobuf
5+
- opening_brace # Handled by SwiftFormat
46
type_name:
57
allowed_symbols: "_"
68
identifier_name:
79
allowed_symbols: "_"
10+
min_length: 1

Diff for: Coder Desktop/Coder Desktop.xcodeproj/project.pbxproj

+2
Original file line numberDiff line numberDiff line change
@@ -721,6 +721,7 @@
721721
CURRENT_PROJECT_VERSION = 1;
722722
DEVELOPMENT_TEAM = 4399GN35BJ;
723723
GENERATE_INFOPLIST_FILE = YES;
724+
MACOSX_DEPLOYMENT_TARGET = 14.6;
724725
MARKETING_VERSION = 1.0;
725726
PRODUCT_BUNDLE_IDENTIFIER = "com.coder.Coder-DesktopUITests";
726727
PRODUCT_NAME = "$(TARGET_NAME)";
@@ -737,6 +738,7 @@
737738
CURRENT_PROJECT_VERSION = 1;
738739
DEVELOPMENT_TEAM = 4399GN35BJ;
739740
GENERATE_INFOPLIST_FILE = YES;
741+
MACOSX_DEPLOYMENT_TARGET = 14.6;
740742
MARKETING_VERSION = 1.0;
741743
PRODUCT_BUNDLE_IDENTIFIER = "com.coder.Coder-DesktopUITests";
742744
PRODUCT_NAME = "$(TARGET_NAME)";

Diff for: Coder Desktop/Coder Desktop.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"originHash" : "42dc2e0a0e0417a7f4f62b3e875c9559038beef7d2265073dd4fc81f2e11ee13",
2+
"originHash" : "412b6d7f71f5522642086779f22408150d75d59e1ec156964763b059262b879d",
33
"pins" : [
44
{
55
"identity" : "alamofire",

Diff for: Coder Desktop/Coder Desktop.xctestplan

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
}
2626
},
2727
{
28+
"enabled" : false,
2829
"parallelizable" : true,
2930
"target" : {
3031
"containerPath" : "container:Coder Desktop.xcodeproj",

Diff for: Coder Desktop/Coder Desktop/Theme.swift

+1
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@ enum Theme {
88

99
static let rectCornerRadius: CGFloat = 4
1010
}
11+
1112
static let defaultVisibleAgents = 5
1213
}

Diff for: Coder Desktop/Coder Desktop/Views/Agents.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ struct Agents<VPN: VPNService, S: Session>: View {
66
@State private var viewAll = false
77
private let defaultVisibleRows = 5
88

9-
internal let inspection = Inspection<Self>()
9+
let inspection = Inspection<Self>()
1010

1111
var body: some View {
1212
Group {

Diff for: Coder Desktop/Coder Desktop/Views/LoginForm.swift

+5-5
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ struct LoginForm<C: Client, S: Session>: View {
1111
@State private var loading: Bool = false
1212
@FocusState private var focusedField: LoginField?
1313

14-
internal let inspection = Inspection<Self>()
14+
let inspection = Inspection<Self>()
1515

1616
var body: some View {
1717
VStack {
@@ -56,7 +56,7 @@ struct LoginForm<C: Client, S: Session>: View {
5656
.onReceive(inspection.notice) { self.inspection.visit(self, $0) } // ViewInspector
5757
}
5858

59-
internal func submit() async {
59+
func submit() async {
6060
loginError = nil
6161
guard sessionToken != "" else {
6262
loginError = .invalidToken
@@ -67,7 +67,7 @@ struct LoginForm<C: Client, S: Session>: View {
6767
return
6868
}
6969
loading = true
70-
defer { loading = false}
70+
defer { loading = false }
7171
let client = C(url: url, token: sessionToken)
7272
do {
7373
_ = try await client.user("me")
@@ -135,8 +135,8 @@ struct LoginForm<C: Client, S: Session>: View {
135135
Button("Sign In") {
136136
Task { await submit() }
137137
}
138-
.buttonStyle(.borderedProminent)
139-
.keyboardShortcut(.defaultAction)
138+
.buttonStyle(.borderedProminent)
139+
.keyboardShortcut(.defaultAction)
140140
}.padding(.top, 5)
141141
}
142142
}

Diff for: Coder Desktop/Coder Desktop/Views/Util.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import Combine
22

33
// This is required for inspecting stateful views
4-
internal final class Inspection<V> {
4+
final class Inspection<V> {
55
let notice = PassthroughSubject<UInt, Never>()
66
var callbacks = [UInt: (V) -> Void]()
77

Diff for: Coder Desktop/Coder Desktop/Views/VPNMenu.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ struct VPNMenu<VPN: VPNService, S: Session>: View {
44
@EnvironmentObject var vpn: VPN
55
@EnvironmentObject var session: S
66

7-
internal let inspection = Inspection<Self>()
7+
let inspection = Inspection<Self>()
88

99
var body: some View {
1010
// Main stack

Diff for: Coder Desktop/Coder Desktop/Views/VPNState.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import SwiftUI
33
struct VPNState<VPN: VPNService>: View {
44
@EnvironmentObject var vpn: VPN
55

6-
internal let inspection = Inspection<Self>()
6+
let inspection = Inspection<Self>()
77

88
var body: some View {
99
Group {

Diff for: Coder Desktop/Coder DesktopTests/AgentsTests.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
@testable import Coder_Desktop
2+
import SwiftUI
23
import Testing
34
import ViewInspector
4-
import SwiftUI
55

66
@Suite(.timeLimit(.minutes(1)))
77
struct AgentsTests {
@@ -47,7 +47,7 @@ struct AgentsTests {
4747

4848
let forEach = try view.inspect().find(ViewType.ForEach.self)
4949
#expect(forEach.count == Theme.defaultVisibleAgents)
50-
#expect(throws: Never.self) { try view.inspect().find(link: "a1.coder")}
50+
#expect(throws: Never.self) { try view.inspect().find(link: "a1.coder") }
5151
}
5252

5353
@Test

Diff for: Coder Desktop/Coder DesktopTests/LoginFormTests.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
@testable import Coder_Desktop
2-
import ViewInspector
3-
import Testing
42
import SwiftUI
3+
import Testing
4+
import ViewInspector
55

66
@Suite(.timeLimit(.minutes(1)))
77
struct LoginTests {

Diff for: Coder Desktop/Coder DesktopTests/Util.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,10 @@ struct MockClient: Client {
6767
}
6868

6969
struct MockErrorClient: Client {
70-
init(url: URL, token: String?) {}
71-
func user(_ ident: String) async throws -> Coder_Desktop.User {
70+
init(url _: URL, token _: String?) {}
71+
func user(_: String) async throws -> Coder_Desktop.User {
7272
throw ClientError.badResponse
7373
}
7474
}
7575

76-
extension Inspection: @retroactive InspectionEmissary { }
76+
extension Inspection: @retroactive InspectionEmissary {}

Diff for: Coder Desktop/Coder DesktopTests/VPNMenuTests.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
@testable import Coder_Desktop
2+
import SwiftUI
23
import Testing
34
import ViewInspector
4-
import SwiftUI
55

66
@Suite(.timeLimit(.minutes(1)))
77
struct VPNMenuTests {

Diff for: Coder Desktop/Coder DesktopTests/VPNStateTests.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
@testable import Coder_Desktop
2-
import ViewInspector
3-
import Testing
42
import SwiftUI
3+
import Testing
4+
import ViewInspector
55

66
@Suite(.timeLimit(.minutes(1)))
77
struct VPNStateTests {

Diff for: Coder Desktop/Coder DesktopUITests/Coder_DesktopUITests.swift

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ final class Coder_DesktopUITests: XCTestCase {
77
// In UI tests it is usually best to stop immediately when a failure occurs.
88
continueAfterFailure = false
99

10-
// In UI tests it’s important to set the initial state - such as interface orientation - required for your tests before they run. The setUp method is a good place to do this.
10+
// In UI tests it’s important to set the initial state - such as
11+
// interface orientation - required for your tests before they run. The setUp method is a good place to do this.
1112
}
1213

1314
override func tearDownWithError() throws {

Diff for: Coder Desktop/Coder DesktopUITests/Coder_DesktopUITestsLaunchTests.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import XCTest
22

33
final class Coder_DesktopUITestsLaunchTests: XCTestCase {
4-
override class var runsForEachTargetApplicationUIConfiguration: Bool {
4+
override static var runsForEachTargetApplicationUIConfiguration: Bool {
55
true
66
}
77

Diff for: Coder Desktop/Makefile

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
ifdef CI
2+
LINTFLAGS := --reporter github-actions-logging
3+
FMTFLAGS := --lint --reporter github-actions-log
4+
else
5+
LINTFLAGS :=
6+
FMTFLAGS :=
7+
endif
8+
9+
PROJECT := "Coder Desktop.xcodeproj"
10+
SCHEME := "Coder Desktop"
11+
12+
fmt:
13+
swiftformat $(FMTFLAGS) .
14+
15+
test:
16+
xcodebuild test \
17+
-project $(PROJECT) \
18+
-scheme $(SCHEME) \
19+
-testPlan $(SCHEME) \
20+
-skipPackagePluginValidation \
21+
CODE_SIGNING_REQUIRED=NO \
22+
CODE_SIGNING_ALLOWED=NO \
23+
| LC_ALL="en_US.UTF-8" xcpretty
24+
25+
lint:
26+
swiftlint \
27+
--working-directory ../ \
28+
--strict \
29+
--quiet $(LINTFLAGS)
30+
31+
clean:
32+
xcodebuild clean \
33+
-project $(PROJECT)

Diff for: Coder Desktop/Proto/Receiver.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import Foundation
2-
import SwiftProtobuf
32
import os
3+
import SwiftProtobuf
44

55
/// An actor that reads data from a `DispatchIO` channel, and deserializes it into VPN protocol messages.
66
actor Receiver<RecvMsg: Message> {
@@ -19,7 +19,7 @@ actor Receiver<RecvMsg: Message> {
1919
private func readLen() async throws -> UInt32 {
2020
let lenD: Data = try await withCheckedThrowingContinuation { continuation in
2121
var lenData = Data()
22-
dispatch.read(offset: 0, length: 4, queue: queue) {done, data, error in
22+
dispatch.read(offset: 0, length: 4, queue: queue) { done, data, error in
2323
guard error == 0 else {
2424
let errStrPtr = strerror(error)
2525
let errStr = String(validatingUTF8: errStrPtr!)!
@@ -39,7 +39,7 @@ actor Receiver<RecvMsg: Message> {
3939
private func readMsg(_ length: UInt32) async throws -> RecvMsg {
4040
let msgData: Data = try await withCheckedThrowingContinuation { continuation in
4141
var msgData = Data()
42-
dispatch.read(offset: 0, length: Int(length), queue: queue) {done, data, error in
42+
dispatch.read(offset: 0, length: Int(length), queue: queue) { done, data, error in
4343
guard error == 0 else {
4444
let errStrPtr = strerror(error)
4545
let errStr = String(validatingUTF8: errStrPtr!)!

0 commit comments

Comments
 (0)