diff --git a/.github/workflows/screenshots.yml b/.github/workflows/screenshots.yml new file mode 100644 index 0000000..d330394 --- /dev/null +++ b/.github/workflows/screenshots.yml @@ -0,0 +1,94 @@ +name: Screenshots + +# App Store screenshots (6.9" iPhone, 1320 x 2868) against the App Review demo account. +# Started by hand (Actions → Screenshots → Run workflow) or by pushing to the screenshots branch. +# Needs three secrets: CLOUDROLL_DEMO_SERVER, CLOUDROLL_DEMO_LOGIN and +# CLOUDROLL_DEMO_APP_PASSWORD (an app password for the demo user, revocable in its +# Nextcloud security settings). The SCREENSHOTS flag compiles in the sign-in hook +# (src/Auth/ScreenshotAccount.swift); no other build has it. +on: + workflow_dispatch: + push: + branches: [screenshots] + +jobs: + capture: + runs-on: macos-26 + env: + CLOUDROLL_DEMO_SERVER: ${{ secrets.CLOUDROLL_DEMO_SERVER }} + CLOUDROLL_DEMO_LOGIN: ${{ secrets.CLOUDROLL_DEMO_LOGIN }} + CLOUDROLL_DEMO_APP_PASSWORD: ${{ secrets.CLOUDROLL_DEMO_APP_PASSWORD }} + steps: + - uses: actions/checkout@v4 + - name: Check secrets + run: | + for name in CLOUDROLL_DEMO_SERVER CLOUDROLL_DEMO_LOGIN CLOUDROLL_DEMO_APP_PASSWORD; do + if [ -z "${!name}" ]; then echo "Missing secret $name" >&2; exit 1; fi + done + # The app gives up on the server after 15 seconds; show how the runner fares. + - name: Check the demo server + run: | + for path in status.php index.php/apps/memories/api/describe index.php/apps/memories/; do + curl -s -o /dev/null -m 60 -u "$CLOUDROLL_DEMO_LOGIN:$CLOUDROLL_DEMO_APP_PASSWORD" \ + -w "$path: %{http_code} connect %{time_connect}s total %{time_total}s\n" \ + "$CLOUDROLL_DEMO_SERVER/$path" || echo "$path: curl failed ($?)" + done + - name: Install XcodeGen + run: brew install xcodegen + - name: Generate project + run: xcodegen generate --spec config/project.yml --project . + - name: Boot a 6.9-inch iPhone + run: | + # The newest Pro Max on the runner; its screenshots are 1320 x 2868. + DEVICE_ID=$(xcrun simctl list devices available -j \ + | jq -r '[.devices | to_entries[] | select(.key | contains("iOS")) | .value[] | select(.name | endswith("Pro Max"))] | last | .udid') + if [ -z "$DEVICE_ID" ] || [ "$DEVICE_ID" = "null" ]; then + echo "No Pro Max simulator on this runner" >&2 + xcrun simctl list devices available + exit 1 + fi + echo "DEVICE_ID=$DEVICE_ID" >> "$GITHUB_ENV" + xcrun simctl boot "$DEVICE_ID" + xcrun simctl bootstatus "$DEVICE_ID" + xcrun simctl status_bar "$DEVICE_ID" override --time 9:41 --dataNetwork wifi --wifiMode active \ + --wifiBars 3 --cellularMode active --cellularBars 4 --batteryState charged --batteryLevel 100 + xcrun simctl privacy "$DEVICE_ID" grant photos io.github.keasbeexd.cloudroll || true + - name: Add phone photos + run: | + # Unsplash photos via picsum.photos, free to use. They're dated today, so they + # sit at the top of the timeline above the demo account's server photos. + mkdir -p phone-photos + for id in 1018 1043 1050; do + curl -sfL -o "phone-photos/phone-$id.jpg" "https://picsum.photos/id/$id/1600/1200.jpg" + done + xcrun simctl addmedia "$DEVICE_ID" phone-photos/*.jpg + # Signed ad hoc ("Sign to Run Locally") rather than unsigned: the simulator only + # grants Keychain access to a signed app. + - name: Capture + run: | + mkdir -p "$RUNNER_TEMP/shots" + xcodebuild -project Cloudroll.xcodeproj -scheme Screenshots \ + -destination "id=$DEVICE_ID" -resultBundlePath "$RUNNER_TEMP/Screenshots.xcresult" \ + test CODE_SIGN_STYLE=Manual CODE_SIGN_IDENTITY=- DEVELOPMENT_TEAM= \ + SWIFT_ACTIVE_COMPILATION_CONDITIONS='DEBUG SCREENSHOTS' + env: + TEST_RUNNER_SCREENSHOT_DIR: ${{ runner.temp }}/shots + TEST_RUNNER_CLOUDROLL_DEMO_SERVER: ${{ secrets.CLOUDROLL_DEMO_SERVER }} + TEST_RUNNER_CLOUDROLL_DEMO_LOGIN: ${{ secrets.CLOUDROLL_DEMO_LOGIN }} + TEST_RUNNER_CLOUDROLL_DEMO_APP_PASSWORD: ${{ secrets.CLOUDROLL_DEMO_APP_PASSWORD }} + TEST_RUNNER_CLOUDROLL_DEMO_NAME: App Review + - name: Export attachments + if: always() + run: | + mkdir -p "$RUNNER_TEMP/shots/attachments" + xcrun xcresulttool export attachments --path "$RUNNER_TEMP/Screenshots.xcresult" \ + --output-path "$RUNNER_TEMP/shots/attachments" || true + ls -la "$RUNNER_TEMP/shots" "$RUNNER_TEMP/shots/attachments" + # The accessibility dumps can name the demo server, so the artifact is short-lived + # and gets deleted once downloaded. + - uses: actions/upload-artifact@v4 + if: always() + with: + name: screenshots + path: ${{ runner.temp }}/shots + retention-days: 1 diff --git a/config/project.yml b/config/project.yml index 3fd6b38..8098c58 100644 --- a/config/project.yml +++ b/config/project.yml @@ -85,3 +85,25 @@ targets: base: PRODUCT_BUNDLE_IDENTIFIER: io.github.keasbeexd.cloudroll.tests GENERATE_INFOPLIST_FILE: YES + # App Store screenshots, run only by .github/workflows/screenshots.yml (Screenshots scheme). + CloudrollScreenshots: + type: bundle.ui-testing + platform: iOS + sources: + - path: ../tests/CloudrollScreenshots + dependencies: + - target: Cloudroll + settings: + base: + PRODUCT_BUNDLE_IDENTIFIER: io.github.keasbeexd.cloudroll.screenshots + GENERATE_INFOPLIST_FILE: YES + TEST_TARGET_NAME: Cloudroll +schemes: + Screenshots: + build: + targets: + Cloudroll: all + CloudrollScreenshots: [test] + test: + config: Debug + targets: [CloudrollScreenshots] diff --git a/docs/roadmap.md b/docs/roadmap.md index 89fe8ac..ee03abc 100644 --- a/docs/roadmap.md +++ b/docs/roadmap.md @@ -42,7 +42,7 @@ Cloudroll is free, with every feature included. It's funded by optional donation - [ ] Register the bundle ID `io.github.keasbeexd.cloudroll` (reverse of keasbeexd.github.io, where the site lives; persisted identifiers such as the Keychain services and the PhotoKit edit format keep their `app.cloudroll` prefix) - [ ] Privacy policy (GitHub Pages) and privacy label ("Data not collected") - [ ] Screenshots generated in the simulator, store listing, a demo account for Apple's reviewers -- [ ] Trademark: check the EU/TMview result, avoid Nextcloud and Memories logos, include a "not affiliated" line +- [x] Trademark: US CLOUDROLL (CITE, reg 5056909) is cancelled, but CITE's EU mark 014736896 (figurative, classes 9/35/42) is live until 2035, plus a Greek national mark. Checked on TMview 2026-11-10; decided to keep the name and launch everywhere. No Nextcloud or Memories logos in the listing or screenshots; "not affiliated" line in the listing and README ## Phase 4: Updates diff --git a/src/App/AppModel.swift b/src/App/AppModel.swift index 1aed4a8..343feb6 100644 --- a/src/App/AppModel.swift +++ b/src/App/AppModel.swift @@ -19,6 +19,9 @@ final class AppModel { if try AccountStore.migrateLegacy() != nil { AccountDataStore.clearLegacyLater() } + #if SCREENSHOTS + try ScreenshotAccount.installFromEnvironment() + #endif accounts = try AccountStore.load() currentID = AccountStore.currentID.flatMap { id in accounts.first { $0.id == id }?.id } ?? accounts.first?.id } catch { diff --git a/src/Auth/ScreenshotAccount.swift b/src/Auth/ScreenshotAccount.swift new file mode 100644 index 0000000..b079770 --- /dev/null +++ b/src/Auth/ScreenshotAccount.swift @@ -0,0 +1,24 @@ +#if SCREENSHOTS +import Foundation + +/// Signs in the App Review demo account for the screenshot run, which can't drive the +/// browser sheet. Only compiled with the SCREENSHOTS flag that .github/workflows/screenshots.yml +/// sets, so TestFlight and App Store builds never contain it. +enum ScreenshotAccount { + /// Fixed, so every run replaces the same Keychain item. + private static let id = UUID(uuidString: "5C2EE45A-0000-4000-8000-000000000001")! + + static func installFromEnvironment() throws { + let env = ProcessInfo.processInfo.environment + guard let serverInput = env["CLOUDROLL_DEMO_SERVER"], + let server = ServerURL.root(from: serverInput), + let login = env["CLOUDROLL_DEMO_LOGIN"], !login.isEmpty, + let password = env["CLOUDROLL_DEMO_APP_PASSWORD"], !password.isEmpty + else { return } + + let credential = Credential(server: server, loginName: login, appPassword: password) + try AccountStore.save(Account(id: id, credential: credential, displayName: env["CLOUDROLL_DEMO_NAME"])) + AccountStore.currentID = id + } +} +#endif diff --git a/tests/CloudrollScreenshots/ScreenshotTests.swift b/tests/CloudrollScreenshots/ScreenshotTests.swift new file mode 100644 index 0000000..635b007 --- /dev/null +++ b/tests/CloudrollScreenshots/ScreenshotTests.swift @@ -0,0 +1,206 @@ +import XCTest + +/// Captures the App Store screenshots against the App Review demo account. +/// Run by .github/workflows/screenshots.yml, which passes the account in through +/// TEST_RUNNER_ variables and builds the app with the SCREENSHOTS flag. +/// Each step saves a PNG and the accessibility tree, and a missing element skips that +/// shot instead of failing the run, so one run shows everything that went wrong. +/// +/// The timeline is a web view whose thumbnails aren't in the accessibility tree, so the +/// test opens photos by their place on screen and then checks the native viewer's +/// controls, which it can read: "Play Live Photo" for the Live Photo, a map in the info. +final class ScreenshotTests: XCTestCase { + private let app = XCUIApplication() + private let springboard = XCUIApplication(bundleIdentifier: "com.apple.springboard") + private var outputDir: URL! + private var problems: [String] = [] + + override func setUpWithError() throws { + continueAfterFailure = true + let env = ProcessInfo.processInfo.environment + outputDir = URL(fileURLWithPath: env["SCREENSHOT_DIR"] ?? NSTemporaryDirectory()) + try FileManager.default.createDirectory(at: outputDir, withIntermediateDirectories: true) + for key in ["CLOUDROLL_DEMO_SERVER", "CLOUDROLL_DEMO_LOGIN", "CLOUDROLL_DEMO_APP_PASSWORD", "CLOUDROLL_DEMO_NAME"] { + app.launchEnvironment[key] = env[key] + } + } + + override func tearDownWithError() throws { + try problems.joined(separator: "\n").write(to: outputDir.appending(path: "problems.txt"), atomically: true, encoding: .utf8) + } + + func testCaptureScreenshots() throws { + app.launch() + guard waitForTimeline() else { + save("00-not-loaded") + XCTFail("The timeline never loaded") + return + } + allowPhotoAccess() + pause(12) // the phone photos join the timeline, then thumbnails load + save("01-timeline") + + // The newest photo is one of the phone's. (Cloudroll's editor never finishes + // loading in the CI simulator, so it isn't captured.) + if openPhoto(at: CGVector(dx: 0.3, dy: 0.3), "newest phone photo") { + pause(3) + save("02-viewer") + closeViewer() + } + + var liveFailed = false + + // The demo timeline is the same every run: the aquarium Live Photo is the only + // photo of Aug 1, and the San Clemente railway photo (with a location) leads Jul 4. + if openPhoto(at: CGVector(dx: 0.16, dy: 0.58), "Live Photo") { + // The motion part downloads after the photo; the button appears once it's ready. + if app.buttons["Play Live Photo"].waitForExistence(timeout: 45) { + pause(2) + save("03-live-photo") + } else { + problems.append("The Aug 1 photo isn't a Live Photo") + liveFailed = true + save("dbg-live") + } + closeViewer() + } + + if openPhoto(at: CGVector(dx: 0.5, dy: 0.76), "photo with a location") { + pause(3) + if tap(app.buttons["Info"], "Info") { + pause(12) // map tiles + if app.maps.firstMatch.exists { + save("04-info") + } else { + problems.append("The Jul 4 photo's info has no map") + save("dbg-info") + } + dismissInfo() + } + closeViewer() + } + + // Settings itself shows the demo server's address, so the shot is the icon picker. + if tap(app.buttons["Cloudroll Settings"], "Cloudroll Settings") { + pause(2) + if tap(app.buttons.matching(NSPredicate(format: "label CONTAINS %@", "App Icon")).firstMatch, "App Icon") { + pause(3) + save("05-app-icons") + } + // The viewer logs why a Live Photo's motion didn't load. + if liveFailed { + app.navigationBars.buttons.firstMatch.tap() + pause(1) + if tap(app.buttons.matching(NSPredicate(format: "label CONTAINS %@", "Diagnostics")).firstMatch, "Diagnostics") { + pause(2) + save("dbg-diagnostics") + } + } + } else { + save("dbg-settings") + } + } + + // MARK: - Steps + + /// Taps "Retry" once if the first load times out, as it occasionally does on CI. + private func waitForTimeline() -> Bool { + let settings = app.buttons["Cloudroll Settings"] + let deadline = Date().addingTimeInterval(240) + var retried = false + while Date() < deadline { + if settings.exists { return true } + if !retried, app.buttons["Retry"].exists { + save("00-retry") + app.buttons["Retry"].tap() + retried = true + } + allowPhotoAccess(wait: 0) + pause(2) + } + return false + } + + /// Cloudroll's own prompt comes first, then the system's, a little after the timeline loads. + private func allowPhotoAccess(wait: TimeInterval = 20) { + let deadline = Date().addingTimeInterval(wait) + repeat { + if app.buttons["Allow access"].exists { app.buttons["Allow access"].tap() } + for label in ["Allow Full Access", "Allow Access to All Photos"] where springboard.buttons[label].exists { + springboard.buttons[label].tap() + return + } + if wait > 0 { pause(1) } + } while Date() < deadline + } + + /// Taps a thumbnail by its place on screen; the web timeline's photos aren't in the + /// accessibility tree. + private func openPhoto(at point: CGVector, _ what: String) -> Bool { + app.windows.firstMatch.coordinate(withNormalizedOffset: point).tap() + if app.buttons["Info"].waitForExistence(timeout: 10) { return true } + problems.append("Couldn't open the \(what)") + save("dbg-open-\(what.replacingOccurrences(of: " ", with: "-"))") + return false + } + + /// Waits for spinners to go, e.g. while the editor renders its first preview. + private func waitForLoading(timeout: TimeInterval = 30) { + let deadline = Date().addingTimeInterval(timeout) + pause(2) + while Date() < deadline, app.activityIndicators.firstMatch.exists { pause(1) } + pause(2) + } + + private func closeViewer() { + if app.buttons["Close"].exists { app.buttons["Close"].tap() } + if !app.buttons["Cloudroll Settings"].waitForExistence(timeout: 5) { + // The viewer also closes with a downward swipe. + let window = app.windows.firstMatch + window.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.45)) + .press(forDuration: 0.05, thenDragTo: window.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.9))) + } + if !app.buttons["Cloudroll Settings"].waitForExistence(timeout: 8) { + problems.append("The viewer didn't close") + save("dbg-close") + } + pause(2) + } + + private func dismissInfo() { + // Drag the sheet down by its grabber, which sits near the middle of the screen + // at the medium detent. + let window = app.windows.firstMatch + window.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.48)) + .press(forDuration: 0.1, thenDragTo: window.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.99))) + pause(2) + if !app.buttons["Close"].exists { + problems.append("The info sheet didn't close") + save("dbg-info-close") + } + } + + @discardableResult + private func tap(_ element: XCUIElement, _ what: String) -> Bool { + guard element.waitForExistence(timeout: 10), element.isHittable else { + problems.append("Couldn't tap \(what)") + return false + } + element.tap() + return true + } + + private func pause(_ seconds: TimeInterval) { + Thread.sleep(forTimeInterval: seconds) + } + + private func save(_ name: String) { + let shot = XCUIScreen.main.screenshot() + let attachment = XCTAttachment(screenshot: shot) + attachment.name = name + attachment.lifetime = .keepAlways + add(attachment) + try? shot.pngRepresentation.write(to: outputDir.appending(path: "\(name).png")) + try? app.debugDescription.write(to: outputDir.appending(path: "\(name).txt"), atomically: true, encoding: .utf8) + } +}