Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: add CI workflows #1

Merged
merged 10 commits into from
Mar 1, 2024
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
33 changes: 33 additions & 0 deletions .github/workflows/build-app.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Build macOS app
on: [push]
jobs:
build:
name: Build Xcode app project
runs-on: macos-14
env:
APP_NAME: Commandoak
XCODE_VERSION: 15.2
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Select Xcode version
run: sudo xcode-select --switch /Applications/Xcode_${{ env.XCODE_VERSION }}.app

- name: Build macOS app
run: |
xcodebuild \
-project ${{ env.APP_NAME }}.xcodeproj \
-scheme ${{ env.APP_NAME }} \
-configuration Release \
-sdk macosx \
archive -archivePath build/${{ env.APP_NAME }}.xcarchive CODE_SIGNING_ALLOWED=NO

- name: Create ZIP of build output
run: zip -r build-out.zip build

- name: Archive artifacts
uses: actions/upload-artifact@v4
with:
name: ${{ env.APP_NAME }} build output
path: build-out.zip
15 changes: 15 additions & 0 deletions .github/workflows/lint-code.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: Lint app code
on: [push]
jobs:
lint:
name: Run SwiftLint
runs-on: macos-14
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Install SwiftLint
run: brew install swiftlint

- name: Run lint command
run: swiftlint lint
77 changes: 77 additions & 0 deletions Commandoak.xcodeproj/xcshareddata/xcschemes/Commandoak.xcscheme
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1520"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "8B50B1E22B8B8084006CBF57"
BuildableName = "Commandoak.app"
BlueprintName = "Commandoak"
ReferencedContainer = "container:Commandoak.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
shouldAutocreateTestPlan = "YES">
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "8B50B1E22B8B8084006CBF57"
BuildableName = "Commandoak.app"
BlueprintName = "Commandoak"
ReferencedContainer = "container:Commandoak.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "8B50B1E22B8B8084006CBF57"
BuildableName = "Commandoak.app"
BlueprintName = "Commandoak"
ReferencedContainer = "container:Commandoak.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
4 changes: 2 additions & 2 deletions Commandoak/CommandoakApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import SwiftData
struct CommandoakApp: App {
var sharedModelContainer: ModelContainer = {
let schema = Schema([
Command.self,
Command.self
])
let modelConfiguration = ModelConfiguration(schema: schema, isStoredInMemoryOnly: false)

Expand All @@ -20,7 +20,7 @@ struct CommandoakApp: App {
fatalError("Could not create ModelContainer: \(error)")
}
}()

var body: some Scene {
MenuBarExtra("Commandoak", systemImage: "command") {
CommandsMenuBarView()
Expand Down
2 changes: 1 addition & 1 deletion Commandoak/Model/Command.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ final class Command {
var name: String
var icon: String
var execute: String

init(name: String = "New command", icon: String = "🕹️", execute: String = "") {
self.name = name
self.icon = icon
Expand Down
12 changes: 6 additions & 6 deletions Commandoak/View/CommandDetailView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import SwiftUI
struct CommandDetailView: View {
@Environment(\.dismiss) private var dismiss
@Environment(\.modelContext) private var modelContext

var cmd: Command

@State private var name: String = ""
@State private var icon: String = ""
@State private var execute: String = ""

var body: some View {
NavigationStack {
Form {
Expand Down Expand Up @@ -50,17 +50,17 @@ struct CommandDetailView: View {
.id(cmd.id)
}
}

init(cmd: Command) {
self.cmd = cmd
}

private func save() {
cmd.name = name
cmd.icon = icon
cmd.execute = execute
}

private func delete() {
modelContext.delete(cmd)
}
Expand Down
40 changes: 23 additions & 17 deletions Commandoak/View/Menu/CommandsMenuBarView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import SwiftData

struct CommandsMenuBarView: View {
@Environment(\.openWindow) private var openWindow

@Query private var commands: [Command]

var body: some View {
ForEach(Array(commands.enumerated()), id: \.offset) { i, cmd in
self.renderCommand(i: i, cmd: cmd)
ForEach(Array(commands.enumerated()), id: \.offset) { index, cmd in
self.renderCommand(index: index, cmd: cmd)
}
Divider()
Button("Commands") {
Expand All @@ -28,11 +28,11 @@ struct CommandsMenuBarView: View {
}
.keyboardShortcut("q")
}

@ViewBuilder
private func renderCommand(i: Int, cmd: Command) -> some View {
let kbShortcut = findKBShortcutForI(i: i)
private func renderCommand(index: Int, cmd: Command) -> some View {
let kbShortcut = findKBShortcutForI(index: index)

if kbShortcut != nil {
Button("\(cmd.icon) \(cmd.name)") {
runCommand(command: cmd.execute)
Expand All @@ -44,9 +44,9 @@ struct CommandsMenuBarView: View {
}
}
}
private func findKBShortcutForI(i: Int) -> KeyboardShortcut? {
switch i {

private func findKBShortcutForI(index: Int) -> KeyboardShortcut? {
switch index {
case 0:
return KeyboardShortcut("1")
case 1:
Expand All @@ -69,20 +69,26 @@ struct CommandsMenuBarView: View {
return nil
}
}

private func runCommand(command: String) {
guard let url = NSWorkspace.shared.urlForApplication(withBundleIdentifier: "com.apple.Terminal") else {
print("Cannot find Terminal application")

return
}

let conf = NSWorkspace.OpenConfiguration()

let event = NSAppleEventDescriptor(eventClass: kAECoreSuite, eventID: kAEDoScript, targetDescriptor: nil, returnID: AEReturnID(kAutoGenerateReturnID), transactionID: AETransactionID(kAnyTransactionID))

let event = NSAppleEventDescriptor(
eventClass: kAECoreSuite,
eventID: kAEDoScript,
targetDescriptor: nil,
returnID: AEReturnID(kAutoGenerateReturnID),
transactionID: AETransactionID(kAnyTransactionID)
)
event.setParam(NSAppleEventDescriptor(string: command), forKeyword: keyDirectObject)
conf.appleEvent = event

NSWorkspace.shared.openApplication(at: url, configuration: conf)
}
}
Expand Down
14 changes: 7 additions & 7 deletions Commandoak/View/SettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import OSLog

struct SettingsView: View {
@State private var autostart: Bool = false

var body: some View {
Form {
Toggle("Start on login", isOn: $autostart)
Expand All @@ -19,25 +19,25 @@ struct SettingsView: View {
}
.onAppear(perform: load)
}

func load() {
let service = SMAppService.loginItem(identifier: "rocks.jarne.CommandoakLoginHelper")
let status = service.status.rawValue

if status == SMAppService.Status.enabled.rawValue {
autostart = true
} else {
autostart = false
}
}

func save() {
registerAutostart(enabled: autostart)
}

func registerAutostart(enabled: Bool) {
let service = SMAppService.loginItem(identifier: "rocks.jarne.CommandoakLoginHelper")

if enabled {
do {
try service.register()
Expand All @@ -51,7 +51,7 @@ struct SettingsView: View {
Logger().error("Couldn't unregister login service: \(error)")
}
}

load()
}
}
Expand Down
6 changes: 3 additions & 3 deletions CommandoakLoginHelper/CommandoakLoginHelperAppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ class CommandoakLoginHelperAppDelegate: NSObject, NSApplicationDelegate {
let isRunning = runningApps.contains { app in
return app.bundleIdentifier == "rocks.jarne.Commandoak"
}

if isRunning {
return
}

var path = Bundle.main.bundlePath as NSString
path = path.deletingLastPathComponent as NSString
path = path.deletingLastPathComponent as NSString
path = path.deletingLastPathComponent as NSString
path = path.deletingLastPathComponent as NSString

let url = URL(filePath: path as String)
NSWorkspace.shared.open(url, configuration: NSWorkspace.OpenConfiguration())
}
Expand Down