Skip to content

Commit

Permalink
Merge branch 'main' into deployment-target-macos-12
Browse files Browse the repository at this point in the history
  • Loading branch information
F1248 committed Feb 9, 2025
2 parents 33ef959 + 05a8159 commit 70654be
Show file tree
Hide file tree
Showing 20 changed files with 225 additions and 34 deletions.
77 changes: 62 additions & 15 deletions .github/workflows/Build-Genius.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,69 @@ on:
- GeniusTests/**
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
permissions: {}

env:
GH_TOKEN: ${{ github.token }}
NSUnbufferedIO: YES

defaults:
run:
shell: bash

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
Run-CodeQL:
name: Run CodeQL
permissions:
security-events: write
runs-on: macos-15

steps:
- name: Select Xcode Version
uses: maxim-lobanov/setup-xcode@master
with:
xcode-version: latest

- name: Checkout
uses: actions/checkout@main

- name: Install xcbeautify
run: |
latest_xcbeautify_tag=$(gh release --repo cpisciotta/xcbeautify list --json tagName --limit 1 | cut -d "\"" -f 4)
curl --location https://github.com/cpisciotta/xcbeautify/releases/download/"$latest_xcbeautify_tag"/xcbeautify-"$latest_xcbeautify_tag"-arm64-apple-macosx.zip --output xcbeautify.zip
unzip xcbeautify.zip
echo "xcbeautify $(./xcbeautify --version) installed"
- name: Work around https://github.com/github/codeql-action/issues/2506
run: |
xcode_developer_directory=$(xcode-select --print-path)
ln "$xcode_developer_directory"/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/host/*.dylib "$xcode_developer_directory"/Toolchains/XcodeDefault.xctoolchain/usr/lib
sudo mkdir /usr/local/lib
sudo ln "$xcode_developer_directory"/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/host/*.dylib /usr/local/lib
- name: Initialize CodeQL
uses: github/codeql-action/init@main
with:
languages: swift
queries: security-and-quality

- name: Build Genius
run: xcodebuild build-for-testing -scheme Genius -destination generic/platform=macOS -skipPackagePluginValidation | ./xcbeautify --disable-logging --renderer github-actions

- name: Run CodeQL
uses: github/codeql-action/analyze@main

- name: Evaluate CodeQL results
run: |
if [[ $(jq ".runs[0].results | length == 0" ../results/swift.sarif) != true ]]; then
echo "CodeQL alerts found!"
exit 1
fi
Run-Periphery:
name: Run Periphery
runs-on: macos-15
Expand Down Expand Up @@ -104,9 +158,7 @@ jobs:
echo "xcbeautify $(./xcbeautify --version) installed"
- name: Build Genius
run: |
set -o pipefail
xcodebuild build -scheme Genius -destination generic/platform=macOS -skipPackagePluginValidation | tee xcodebuild.log | ./xcbeautify --disable-logging --renderer github-actions
run: xcodebuild build-for-testing -scheme Genius -destination generic/platform=macOS -skipPackagePluginValidation | tee xcodebuild.log | ./xcbeautify --disable-logging --renderer github-actions

- name: Run SwiftLint Analyzer Rules
run: ./swiftlint analyze --strict --reporter github-actions-logging --compiler-log-path xcodebuild.log
Expand All @@ -132,17 +184,14 @@ jobs:
echo "xcbeautify $(./xcbeautify --version) installed"
- name: Run Tests
run: |
set -o pipefail
xcodebuild test -scheme Genius -destination platform=macOS,arch=arm64 -skipPackagePluginValidation | ./xcbeautify --disable-logging --renderer github-actions
run: xcodebuild test -scheme Genius -destination platform=macOS,arch=arm64 -skipPackagePluginValidation | ./xcbeautify --disable-logging --renderer github-actions

Build-Genius:
name: Build Genius
runs-on: macos-15

permissions:
id-token: write
attestations: write
id-token: write
runs-on: macos-15

steps:
- name: Select Xcode Version
Expand All @@ -161,9 +210,7 @@ jobs:
echo "xcbeautify $(./xcbeautify --version) installed"
- name: Build Genius
run: |
set -o pipefail
xcodebuild archive -scheme Genius -destination generic/platform=macOS -archivePath Genius -skipPackagePluginValidation | ./xcbeautify --disable-logging --renderer github-actions
run: xcodebuild archive -scheme Genius -destination generic/platform=macOS -archivePath Genius -skipPackagePluginValidation | ./xcbeautify --disable-logging --renderer github-actions

- name: Zip Genius
run: |
Expand Down
46 changes: 46 additions & 0 deletions .github/workflows/Run-CodeQL-GitHub-Actions-Workflows.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Run CodeQL on GitHub Actions Workflows

on:
push:
paths:
- .github/workflows/**
pull_request:
paths:
- .github/workflows/**
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
Run-CodeQL-GitHub-Actions-Workflows:
name: Run CodeQL on GitHub Actions Workflows
permissions:
security-events: write
runs-on: macos-15

steps:
- name: Checkout
uses: actions/checkout@main

- name: Initialize CodeQL
uses: github/codeql-action/init@main
with:
languages: actions
config: |
query-filters:
- exclude:
id:
- actions/unpinned-tag
queries: security-and-quality

- name: Run CodeQL
uses: github/codeql-action/analyze@main

- name: Evaluate CodeQL results
run: |
if [[ $(jq ".runs[0].results | length == 0" ../results/actions.sarif) != true ]]; then
echo "CodeQL alerts found!"
exit 1
fi
2 changes: 2 additions & 0 deletions .github/workflows/Trigger-Deploy-to-Pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

permissions: {}

jobs:
Trigger-Deploy-to-Pages:
name: Trigger Deploy to Pages
Expand Down
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
xcuserdata/
*.xcworkspace
/Genius.xcodeproj/project.xcworkspace
/Genius.xcodeproj/xcuserdata
14 changes: 14 additions & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,20 @@ trailing_comma:
mandatory_comma: true
trailing_whitespace:
ignores_comments: false
type_contents_order:
order:
- case
- type_alias
- associated_type
- subtype
- type_property
- instance_property
- initializer
- deinitializer
- type_method
- view_life_cycle_method
- other_method
- subscript
type_name:
excluded:
- T
Expand Down
2 changes: 1 addition & 1 deletion Genius/Extensions/Foundation/Measurement.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ extension Measurement: MeasurementProtocol {
return MeasurementFormatter().string(
from: value.isZero ?
self.converted(to: .baseUnit()) :
{ $0.first { $0.value >= 1 } ?? $0.last }(units.lazy.map(self.converted)) ?? self
{ $0.first { $0.value >= 1 } ?? $0.last }(units.lazy.map(self.converted)).safeForceUnwrapped(fallback: self)
)
case let self as InformationStorage:
let formatter = ByteCountFormatter()
Expand Down
4 changes: 2 additions & 2 deletions Genius/Extensions/Foundation/Process.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ extension Process {
self.arguments = [
"-e",
"""
do shell script \"\(executable) \(arguments.joined(separator: " "))\"\
with prompt \"\("Genius requires administrator privileges.".localized)\"\
do shell script \"\(executable) \(arguments.joined(separator: " "))\" \
with prompt \"\("Genius requires administrator privileges.".localized)\" \
with administrator privileges
""",
]
Expand Down
3 changes: 2 additions & 1 deletion Genius/Extensions/Swift/Bool.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ extension Bool: DataInitializable {
)
}

// swiftlint:disable vertical_parameter_alignment_on_call
// swiftformat:disable indent wrap wrapArguments
// swiftlint:disable vertical_parameter_alignment_on_call

init?(fdesetupOutput: String?) {
self.init(
Expand All @@ -61,6 +61,7 @@ extension Bool: DataInitializable {
)
}

// swiftformat:enable indent wrap wrapArguments
// swiftlint:enable vertical_parameter_alignment_on_call

init?(socketfilterfwOutput: String?) {
Expand Down
2 changes: 1 addition & 1 deletion Genius/Extensions/Swift/CaseIterable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@

extension CaseIterable where Self: Equatable, AllCases.Index == Int {

var index: AllCases.Index { Self.allCases.firstIndex(of: self) ?? 0 }
var index: AllCases.Index { Self.allCases.firstIndex(of: self).safeForceUnwrapped() }
}
2 changes: 1 addition & 1 deletion Genius/Extensions/Swift/Int.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import Foundation

extension Int: DataInitializable {
extension Int: DefaultInitializable, DataInitializable {

init(_ data: Data) {
self = data.reversed().reduce(0) { $0 << 8 | Int($1) }
Expand Down
47 changes: 47 additions & 0 deletions Genius/Extensions/Swift/Optional.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,53 @@
// See LICENSE.txt for license information.
//

import os

extension Optional where Wrapped: DefaultInitializable {

func safeForceUnwrapped(
file: String = #file,
line: Int = #line,
column: Int = #column,
function: String = #function
) -> Wrapped {
guard let self else {
Logger().error(
"Unexpectedly found nil while unwrapping an Optional value",
file: file,
line: line,
column: column,
function: function
)
return Wrapped()
}
return self
}
}

extension Optional {

func safeForceUnwrapped(
fallback: @autoclosure () -> Wrapped,
file: String = #file,
line: Int = #line,
column: Int = #column,
function: String = #function
) -> Wrapped {
guard let self else {
Logger().error(
"Unexpectedly found nil while unwrapping an Optional value",
file: file,
line: line,
column: column,
function: function
)
return fallback()
}
return self
}
}

extension Optional where Wrapped: Equatable {

static func ==? (lhs: Self, rhs: Self) -> Bool? {
Expand Down
5 changes: 2 additions & 3 deletions Genius/Extensions/Swift/String.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import Defaults
import Foundation

extension String: DataInitializable {
extension String: DefaultInitializable, DataInitializable {

var isContainedInDefaultLocalizationTable: Bool {
NSLocalizedString(self, value: " ", comment: "") == " "
Expand Down Expand Up @@ -61,8 +61,7 @@ extension String: DataInitializable {
.localized
case let systemInformationData as VersionNumber: systemInformationData.versions.map(String.init).joined(separator: ".")
default: nil
// swiftlint:disable:next statement_position
}
} // swiftformat:enable indent
else { return nil }
self = string
}
Expand Down
2 changes: 1 addition & 1 deletion Genius/Extensions/SwiftUICore/LocalizedStringKey.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ import SwiftUICore
extension LocalizedStringKey {

var key: String {
Mirror(reflecting: self).children.first { $0.label == "key" }?.value as? String ?? ""
(Mirror(reflecting: self).children.first { $0.label == "key" }?.value as? String).safeForceUnwrapped()
}
}
22 changes: 22 additions & 0 deletions Genius/Extensions/os/Logger.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// Logger.swift
// Genius
//
// © 2025 F1248 <[email protected]>
// See LICENSE.txt for license information.
//

import os

extension Logger {

func error(
_ message: String,
file: String,
line: Int,
column: Int,
function: String
) {
error("\(file):\(line):\(column) in function \(function): Error: \(message)")
}
}
12 changes: 12 additions & 0 deletions Genius/Models/DefaultInitializable.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//
// DefaultInitializable.swift
// Genius
//
// © 2025 F1248 <[email protected]>
// See LICENSE.txt for license information.
//

protocol DefaultInitializable {

init()
}
9 changes: 4 additions & 5 deletions Genius/Models/Helpers/IORegistry.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ struct IORegistry: ~Copyable {
self.matchingDictionary = IOServiceNameMatching(name)
}

deinit {
if let service { IOObjectRelease(service) }
}

func serviceExists() -> Bool? {
service >? 0
}
Expand All @@ -41,9 +45,4 @@ struct IORegistry: ~Copyable {
guard serviceExists() ?? false, let service else { return nil }
return IORegistryEntryCreateCFProperty(service, key as CFString, kCFAllocatorDefault, 0) != nil
}

// swiftformat:disable organizeDeclarations
deinit {
if let service { IOObjectRelease(service) }
}
}
2 changes: 1 addition & 1 deletion Genius/Models/Helpers/Sysctl.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ enum Sysctl {
guard sysctlbyname(name, nil, &size, nil, 0) == 0, size > 0 else { return nil }
var result = [UInt8](repeating: 0, count: size)
guard sysctlbyname(name, &result, &size, nil, 0) == 0 else { return nil }
return W(Data(bytes: result, count: result.lastIndex { $0 != 0 }.map(result.index(after:)) ?? size))
return W(Data(bytes: result, count: result.lastIndex { $0 != 0 }.map(result.index(after:)) ?? 1))
}
}
Loading

0 comments on commit 70654be

Please sign in to comment.