From b7245f96632bf168fb0fa7e408475067961c273e Mon Sep 17 00:00:00 2001 From: winebarrel Date: Mon, 4 Nov 2024 17:26:49 +0900 Subject: [PATCH 1/2] Add SwiftLint Analyse to CI --- .github/workflows/ci.yml | 16 ++++++++++------ .gitignore | 1 + .swiftlint.yml | 3 +++ Makefile | 18 +++++++++++++----- 4 files changed, 27 insertions(+), 11 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4460964..3367d75 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -28,6 +28,12 @@ jobs: uses: actions/checkout@v4 - name: Switch Xcode run: sudo xcode-select -s /Applications/Xcode_16.app + - name: Install SwiftLint + env: + SWIFTLINT_VERSION: 0.57.0 + run: | + curl -sSfLO https://github.com/realm/SwiftLint/releases/download/${SWIFTLINT_VERSION}/portable_swiftlint.zip + unzip portable_swiftlint.zip swiftlint - name: Install the Apple certificate and provisioning profile env: BUILD_CERTIFICATE_BASE64: ${{ secrets.BUILD_CERTIFICATE_BASE64 }} @@ -56,11 +62,9 @@ jobs: # apply provisioning profile mkdir -p ~/Library/MobileDevice/Provisioning\ Profiles cp $PP_PATH ~/Library/MobileDevice/Provisioning\ Profiles - - name: Restore cache - uses: irgaly/xcode-cache@v1 - with: - key: xcode-cache-deriveddata-${{ github.workflow }}-${{ github.sha }} - restore-keys: xcode-cache-deriveddata-${{ github.workflow }}- - name: Build and Analyse run: | - xcodebuild build analyze -scheme PagerCall -destination 'generic/platform=macOS' -allowProvisioningUpdates + xcodebuild build analyze -scheme PagerCall -destination 'generic/platform=macOS' -allowProvisioningUpdates -configuration Debug | tee build.log + - name: SwiftLint Analyse + run: | + ./swiftlint analyze --compiler-log-path build.log diff --git a/.gitignore b/.gitignore index fbc8c29..e3862fd 100644 --- a/.gitignore +++ b/.gitignore @@ -31,6 +31,7 @@ playground.xcworkspace .build/ build/ +build.log # CocoaPods # diff --git a/.swiftlint.yml b/.swiftlint.yml index 6a9869a..88538c2 100644 --- a/.swiftlint.yml +++ b/.swiftlint.yml @@ -1,3 +1,6 @@ disabled_rules: - line_length - nesting +analyzer_rules: + - unused_declaration + - unused_import diff --git a/Makefile b/Makefile index deffbde..88be73e 100644 --- a/Makefile +++ b/Makefile @@ -1,14 +1,22 @@ -BUILD_DIR = ./build -APP_NAME = PagerCall -ARCHIVE_PATH = $(BUILD_DIR)/$(APP_NAME).xcarchive +BUILD_DIR = ./build +APP_NAME = PagerCall +ARCHIVE_PATH = $(BUILD_DIR)/$(APP_NAME).xcarchive +CONFIGURATION = Release +BUILD_LOG = ./build.log .PHONY: build build: clean xcodebuild build analyze archive \ -destination "generic/platform=macOS" \ -scheme $(APP_NAME) \ - -configuration Release \ - -archivePath $(ARCHIVE_PATH) + -configuration $(CONFIGURATION) \ + -archivePath $(ARCHIVE_PATH) \ + | tee $(BUILD_LOG) + +.PHONY: swiftlint-analyze +swiftlint-analyze: + $(MAKE) build CONFIGURATION=Debug + swiftlint analyze --compiler-log-path $(BUILD_LOG) .PHONY: clean clean: From 241b3e03a4aa864a23c430862caeab0d156bb4fd Mon Sep 17 00:00:00 2001 From: winebarrel Date: Mon, 4 Nov 2024 17:53:27 +0900 Subject: [PATCH 2/2] Fix for SwiftLint --- PagerCall/MouseHandlerView.swift | 2 +- PagerCall/Notification.swift | 2 +- PagerCall/PagerCallApp.swift | 3 ++- PagerCall/PagerDutyAPI.swift | 9 --------- PagerCall/PagerDutyModel.swift | 1 - 5 files changed, 4 insertions(+), 13 deletions(-) diff --git a/PagerCall/MouseHandlerView.swift b/PagerCall/MouseHandlerView.swift index c8ed91a..5c73001 100644 --- a/PagerCall/MouseHandlerView.swift +++ b/PagerCall/MouseHandlerView.swift @@ -1,5 +1,5 @@ // from https://github.com/orchetect/MenuBarExtraAccess/discussions/2#discussioncomment-5744323 -import SwiftUI +import AppKit class MouseHandlerView: NSView { var onRightMouseDown: (() -> Void)? diff --git a/PagerCall/Notification.swift b/PagerCall/Notification.swift index 72da4ea..3b7b32a 100644 --- a/PagerCall/Notification.swift +++ b/PagerCall/Notification.swift @@ -1,4 +1,4 @@ -import SwiftUI +import AppKit import UserNotifications enum Notification { diff --git a/PagerCall/PagerCallApp.swift b/PagerCall/PagerCallApp.swift index 24cc040..ed73b98 100644 --- a/PagerCall/PagerCallApp.swift +++ b/PagerCall/PagerCallApp.swift @@ -1,7 +1,6 @@ import AsyncAlgorithms import MenuBarExtraAccess import SwiftUI -import UserNotifications @main struct PagerCallApp: App { @@ -13,7 +12,9 @@ struct PagerCallApp: App { @AppStorage("interval") private var interval = Constants.defaultInterval @StateObject private var pagerDuty = PagerDuty() + // swiftlint:disable unused_declaration @NSApplicationDelegateAdaptor(AppDelegate.self) var appDelegate + // swiftlint:enable unused_declaration private var popover: NSPopover = { let pop = NSPopover() diff --git a/PagerCall/PagerDutyAPI.swift b/PagerCall/PagerDutyAPI.swift index f87e4dc..e8dfd70 100644 --- a/PagerCall/PagerDutyAPI.swift +++ b/PagerCall/PagerDutyAPI.swift @@ -29,15 +29,6 @@ struct PagerDutyAPI { @AppStorage("userID") private var userID: String = "" - private struct UsersMeResp: Codable { - let user: User - - struct User: Codable { - let id: String - let htmlUrl: String - } - } - private struct OncallsResp: Codable { let oncalls: [Oncall] struct Oncall: Codable {} diff --git a/PagerCall/PagerDutyModel.swift b/PagerCall/PagerDutyModel.swift index 9ad7eba..8f07db9 100644 --- a/PagerCall/PagerDutyModel.swift +++ b/PagerCall/PagerDutyModel.swift @@ -10,7 +10,6 @@ enum Status: String { @MainActor class PagerDuty: ObservableObject { - private let endpoint = URL(string: "https://api.pagerduty.com/")! private let api = PagerDutyAPI() @Published var incidents: Incidents = []