diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3f6f529e..f28ce36c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -106,6 +106,12 @@ jobs: command -v rg >/dev/null || brew install ripgrep ./scripts/vocab-check.sh + # swift format lint (#1165) with Xcode's own swift-format: about a second, and every finding fails the leg. + # .swift-format has the rules; scripts/swift-format-lint.sh says which are off and why. + - name: swift format lint + if: matrix.check == 'package tests' + run: ./scripts/swift-format-lint.sh + - name: Package tests if: matrix.check == 'package tests' working-directory: Packages/ShowRecorderKit diff --git a/.swift-format b/.swift-format new file mode 100644 index 00000000..c00d99da --- /dev/null +++ b/.swift-format @@ -0,0 +1,53 @@ +{ + "version" : 1, + "indentation" : { + "spaces" : 4 + }, + "lineLength" : 130, + "indentConditionalCompilationBlocks" : false, + "rules" : { + "AllPublicDeclarationsHaveDocumentation" : false, + "AlwaysUseLiteralForEmptyCollectionInit" : false, + "AlwaysUseLowerCamelCase" : true, + "AmbiguousTrailingClosureOverload" : true, + "AvoidRetroactiveConformances" : true, + "BeginDocumentationCommentWithOneLineSummary" : false, + "DoNotUseSemicolons" : false, + "DontRepeatTypeInStaticProperties" : true, + "FileScopedDeclarationPrivacy" : true, + "FullyIndirectEnum" : true, + "GroupNumericLiterals" : true, + "IdentifiersMustBeASCII" : true, + "NeverForceUnwrap" : false, + "NeverUseForceTry" : false, + "NeverUseImplicitlyUnwrappedOptionals" : false, + "NoAccessLevelOnExtensionDeclaration" : false, + "NoAssignmentInExpressions" : true, + "NoBlockComments" : true, + "NoCasesWithOnlyFallthrough" : true, + "NoEmptyLinesOpeningClosingBraces" : false, + "NoEmptyTrailingClosureParentheses" : true, + "NoLabelsInCasePatterns" : true, + "NoLeadingUnderscores" : false, + "NoParensAroundConditions" : true, + "NoPlaygroundLiterals" : true, + "NoVoidReturnOnFunctionSignature" : true, + "OmitExplicitReturns" : false, + "OneCasePerLine" : true, + "OneVariableDeclarationPerLine" : false, + "OnlyOneTrailingClosureArgument" : true, + "OrderedImports" : false, + "ReplaceForEachWithForLoop" : true, + "ReturnVoidInsteadOfEmptyTuple" : true, + "TypeNamesShouldBeCapitalized" : true, + "UseEarlyExits" : false, + "UseExplicitNilCheckInConditions" : true, + "UseLetInEveryBoundCaseVariable" : true, + "UseShorthandTypeNames" : true, + "UseSingleLinePropertyGetter" : true, + "UseSynthesizedInitializer" : true, + "UseTripleSlashForDocumentationComments" : true, + "UseWhereClausesInForLoops" : false, + "ValidateDocumentationComments" : false + } +} diff --git a/App/RecordScreen.swift b/App/RecordScreen.swift index 6351dc00..2db92b6b 100644 --- a/App/RecordScreen.swift +++ b/App/RecordScreen.swift @@ -906,7 +906,7 @@ final class RecordScreenModel { self.takeTelemetry.handle(event, context: TakeContext( recorder: self.recorder, mixerFamily: self.mixer.family.map { String(describing: $0) })) // The App Store rating prompt counts clean Takes here; it asks later, when the screen is idle. - if case let .takeEnded(end) = event { self.countForRating(end) } + if case .takeEnded(let end) = event { self.countForRating(end) } let followUp = TakeFollowUp(event) if followUp.contains(.liveActivity) { followLiveActivity() } if followUp.contains(.proOffer) { offerProAfterTake() } diff --git a/Packages/ShowRecorderKit/Sources/Recording/DriveOnlyMoveOffer.swift b/Packages/ShowRecorderKit/Sources/Recording/DriveOnlyMoveOffer.swift index b7b96ca4..72dc77fc 100644 --- a/Packages/ShowRecorderKit/Sources/Recording/DriveOnlyMoveOffer.swift +++ b/Packages/ShowRecorderKit/Sources/Recording/DriveOnlyMoveOffer.swift @@ -1,7 +1,9 @@ /// What to do when a Drive connects while Drive only Takes (#196, #630) wait on the Device (#805): move them now, /// ask the operator first, or leave them. public enum DriveOnlyMoveOffer: Equatable, Sendable { - case move, ask(takeCount: Int), leave + case move + case ask(takeCount: Int) + case leave /// Never during a Take. Where Record to isn't offered, or with Drive or Both chosen, the Takes move as before; /// with the Device chosen the operator is asked, once per Drive connection. Mark the connection asked only on `ask`: diff --git a/Packages/ShowRecorderKit/Sources/Recording/DriveSpeedTest.swift b/Packages/ShowRecorderKit/Sources/Recording/DriveSpeedTest.swift index ce423777..0c7e4d70 100644 --- a/Packages/ShowRecorderKit/Sources/Recording/DriveSpeedTest.swift +++ b/Packages/ShowRecorderKit/Sources/Recording/DriveSpeedTest.swift @@ -58,7 +58,7 @@ public enum DriveSpeedTest { for index in 0.., within timeout: Duration = hangGuard) async -> Outcome { let (outcomes, sink) = AsyncStream.makeStream() diff --git a/Packages/ShowRecorderKit/Tests/RecordingTests/PeakMetersLevelTests.swift b/Packages/ShowRecorderKit/Tests/RecordingTests/PeakMetersLevelTests.swift index 5df99057..82ce7aea 100644 --- a/Packages/ShowRecorderKit/Tests/RecordingTests/PeakMetersLevelTests.swift +++ b/Packages/ShowRecorderKit/Tests/RecordingTests/PeakMetersLevelTests.swift @@ -13,7 +13,7 @@ struct PeakMetersLevelTests { buffer.initialize(from: samples, count: samples.count) return buffer } - defer { buffers.forEach { $0.deallocate() } } + defer { for buffer in buffers { buffer.deallocate() } } var pointers = buffers.map { UnsafePointer($0) } pointers.withUnsafeMutableBufferPointer { meters.record(AudioBlock(channels: $0.baseAddress!, channelCount: channels, frameCount: samples.count, hostTime: 0)) diff --git a/docs/DEVELOPING.md b/docs/DEVELOPING.md index b76afd8f..1e95fed7 100644 --- a/docs/DEVELOPING.md +++ b/docs/DEVELOPING.md @@ -25,6 +25,8 @@ xcodebuild -project ShowRecorder.xcodeproj -scheme ShowRecorder \ `scripts/verify.sh` runs the checks CI runs, but only those the branch's changes need: the vocabulary check, package tests, macOS and iOS Simulator builds, the app's unit tests (`AppTests`, hosted on the Mac build, so no Simulator; CI runs them on its macOS leg), and the website's lint, tests and build. It prints its plan first; a docs-only change needs none (except `docs/release-notes/`, which the site's changelog test reads, so it runs the site checks), and a change to `verify.sh`, CI or an unlisted path runs everything. `VERIFY_ALL=1` runs everything, `VERIFY_QUICK=1` skips the macOS and iOS app builds and `AppTests` and leaves them to CI (everything else runs as the changes need; a signed device build is skipped too, and CI doesn't run that one), `VERIFY_PLAN_ONLY=1` prints the plan and stops, and the header of `verify.sh` lists which paths pick which checks. Set `DEVICE_ID` and `DEVELOPMENT_TEAM` to also build for a device. The package tests, both app builds and the website run side by side, as CI runs them: each writes its own log, and at the end `verify.sh` prints each step's result and time and the log of any that failed. Each app build has its own build folder (`build/dd-mac`, `build/dd-ios`, `build/dd-device`; `DERIVED_DATA` changes the `build/dd` prefix), so they don't wait on each other; an older `build/dd` can be deleted. Ctrl-C stops every step. CI runs on every pull request on GitHub's free hosted `macos-26` runner and must pass before a PR merges. +`scripts/swift-format-lint.sh` runs `swift format lint` (#1165; swift-format comes with the toolchain) on every tracked Swift file outside `spikes/`, in every `verify.sh` plan and in CI's package tests leg. It changes no file, takes about a second, and any finding fails it. The rules are in `.swift-format`; the header of the script lists the four that are off because the code breaks them widely, and says why layout (indentation, line length, line breaks) isn't checked yet. + ### Two heavy builds at a time Several agents often work on this Mac at once, in their own worktrees. Many builds run side by side starve each other, and tests with time limits fail under the load. So every heavy build takes one of two build slots, shared by all worktrees of the repo: slot 1 is the lock file `.git/verify.lock`, slot 2 is `.git/verify.lock.2`. A build takes the first free slot; a third one waits until either frees and says so: "== Waiting for another build on this Mac to finish". Builds that hold a slot run at low priority (`nice -n 10`). diff --git a/scripts/swift-format-lint.sh b/scripts/swift-format-lint.sh new file mode 100755 index 00000000..5bfdc428 --- /dev/null +++ b/scripts/swift-format-lint.sh @@ -0,0 +1,32 @@ +#!/bin/sh +# `swift format lint` (#1165), the check CI runs: swift-format comes with the Swift toolchain, so nothing to install. +# It changes no file. Every finding fails it. +# +# What it checks is in .swift-format at the top of the repo: +# - The rules list is complete on purpose. A rule left out is off, and a name the toolchain doesn't know fails +# every file ("unrecognized rule"), so add a rule only when CI's Xcode and your own toolchain both have it. +# - Off because the code breaks them widely (counts from 2026-12-03): DoNotUseSemicolons (820), OrderedImports (218, +# mostly `@testable import` first), OneVariableDeclarationPerLine (161) and NoAccessLevelOnExtensionDeclaration +# (7 `private extension`s). Turning one on is its own PR, with the cleanup. +# - Layout (indentation, line length, line breaks, spacing, trailing commas) isn't checked at all: +# --debug-disable-pretty-print turns that half of the linter off. The code is laid out by hand, and with the +# config's 4 spaces and 130 columns swift-format still wants about 3,200 changes. The layout settings in +# .swift-format are there for Xcode's "Format with swift-format" and for a later reformat. +# +# spikes/ (experiments) isn't checked. With no Swift toolchain it says so and passes: CI still checks. +# SHOWRECORDER_REAL_SWIFT= the swift to use (default /usr/bin/swift, then `swift` on PATH), as scripts/bin/swift +set -eu +cd "$(dirname "$0")/.." + +swift="${SHOWRECORDER_REAL_SWIFT:-/usr/bin/swift}" +[ -x "$swift" ] || swift=$(command -v swift || true) +if [ -z "$swift" ] || ! version=$("$swift" format --version 2>/dev/null); then + echo "== swift format lint: no swift format here; skipped, CI still checks" + exit 0 +fi +echo "swift-format $version" + +# Tracked files only, so build folders and package checkouts stay out. +files=$(git ls-files -- '*.swift' ':!spikes/') +# shellcheck disable=SC2086 # one path per word: no tracked Swift file has a space in its name +"$swift" format lint --strict --parallel --debug-disable-pretty-print $files diff --git a/scripts/test-verify-plan.sh b/scripts/test-verify-plan.sh index cb6a646f..59e2cd7a 100755 --- a/scripts/test-verify-plan.sh +++ b/scripts/test-verify-plan.sh @@ -100,7 +100,7 @@ else printf '%s\n' "$f" | grep -qE "$sim_pattern" && { echo "FAIL: CI runs the mixer-sim job for $f"; fail=1; } done fi -grep -q "needs: \[changes, app, site, mixer-sim\]" .github/workflows/ci.yml || +grep -q "needs: \[changes, app, site, mixer-sim, scripts\]" .github/workflows/ci.yml || { echo "FAIL: the required Test and build check doesn't wait for the mixer-sim job"; fail=1; } [ $fail -eq 0 ] && echo "verify.sh plan: all cases pass" diff --git a/scripts/verify.sh b/scripts/verify.sh index baf96079..73fbf754 100755 --- a/scripts/verify.sh +++ b/scripts/verify.sh @@ -1,6 +1,7 @@ #!/bin/sh # Runs the checks CI runs, but only the ones the changed files need: # spelling scripts/spelling-check.sh every plan: CI's American spelling check, on the whole repo +# format scripts/swift-format-lint.sh every plan: CI's swift format lint (#1165), about a second, no build # take grep every plan: Take control on the recorder only in TakeSequencer (#551) # vocab scripts/vocab-check.sh App/, package Sources/, CONTEXT.md, scripts/vocab-* # package swift test Packages/ @@ -139,6 +140,9 @@ fi echo "== American spelling (CI's check)" ./scripts/spelling-check.sh +echo "== swift format lint (CI's check)" +./scripts/swift-format-lint.sh + echo "== Take control (#551)" if grep -rnE 'recorder\.(startTake|stopTake|addMarker|endShow|startNewShow|prepareNextShow)\(' App Packages/ShowRecorderKit/Sources \ --include='*.swift' | grep -vE '^Packages/ShowRecorderKit/Sources/Recording/(TakeSequencer|Recorder)\.swift:'; then