mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-02 03:06:37 +00:00
b1ed870474
* Run the tests on iOS 27.0 Bump the required simulator OS in the preview, UI and Compound tests, and the CI tool's default OS, from 26.5 to 27.0. Test devices stay the same. iOS 27 writes transcoded videos 146 bytes larger, so update the expected sizes in MediaUploadingPreprocessorTests. * Build and test on CI with Xcode 27 Select Xcode 27 in ci_common.sh and move every macOS workflow to the xcode-27 runner image, as macos-26 doesn't include Xcode 27. The Compound workflow now also creates its simulator on the iOS 27.0 runtime. The xcode-27 runners are slower, so give the unit, Enterprise, Compound and snapshot recording jobs longer timeouts. * Fix the preview snapshot layout on iOS 27 On iOS 27 the hosting controller applies the window's safe area when rendering, but the snapshot size comes from sizeThatFits, which ignores it. Component previews were shifted down and clipped at the bottom. Disable the hosting controller's safe area regions for these snapshots so the measured and rendered layouts match. swift-snapshot-testing also renders into a window without a scene, and on iOS 27 a navigation stack in such a window reserves space for a large title it never shows, leaving a gap below the navigation bar. Attach the render window to the app's scene until swift-snapshot-testing handles it. The invite users and add rooms screens sized their selected items row from a measured width stored in state, which is zero on the first layout pass, so snapshots could draw the row empty. Use containerRelativeFrame instead. The add rooms search previews now also wait for their results, and the search previews that show a clear button get a small precision tolerance, as it renders inconsistently in snapshots. * Re-record the preview snapshots on iOS 27.0 Recorded on an iPhone SE (3rd generation) simulator running iOS 27.0 with Xcode 27.0 (27A266a). The changes come from iOS 27 rendering: text anti-aliasing, hyphenation and line breaking, navigation bars and toggles that now render in snapshots, lazy stacks that were blank on iOS 26, and pseudo-language locale formatting. * Fix the UI tests on iOS 27 iOS 27 no longer exposes accessibility identifiers on SwiftUI menu items, so the space exploration test now finds them by label within the menu. On iPad, the start chat search field keeps focus after submitting and can swallow the next tap, so retry the tap if the create room screen doesn't appear. * Re-record the UI test snapshots on iOS 27.0 Recorded on iPhone 17 and iPad (A16) simulators running iOS 27.0 with Xcode 27.0. The changes come from iOS 27 styling, like the keyboard height and glass borders. This also removes the iPad app lock setup snapshots, which have been orphaned since those tests stopped running on iPad. * Fix the accessibility tests crashing on iOS 27 The accessibility tests' previews wrapper kept its ImageRenderer alive across the awaits that follow the render. On iOS 27, releasing it at that point tears down its view graph outside of a SwiftUI update, which hits an assertion and crashes the app. Release the renderer as soon as the image has been rendered. * Keep the accessibility tests' image renderers alive on iOS 27 Releasing the ImageRenderer straight away wasn't enough: on iOS 27, releasing one that rendered a preview crashes SwiftUI whichever context it happens in. Keep the renderers alive instead. Each test launches a fresh app, so they only live for the one test. * Share the UI tests' app settings with their mock user session Since the user session flow reads its settings from UserSettings, the UI tests' mock user session was wrapping a fresh volatile AppSettings instead of the one the tests configure. The flags that skip onboarding weren't picked up, so every user session UI test got stuck on the notifications permission screen. * Re-record the Compound snapshots on iOS 27.0 Apply the same safe area fix as the app's preview tests, so size-that-fits snapshots aren't clipped on iOS 27, and re-record the snapshots on an iPhone SE (3rd generation) simulator running iOS 27.0 in English (US). * Fix a race reading the keyboard in the accessibility tests On iOS 27 the QR code login screen's keyboard can be dismissing between checking that it exists and reading its frame, which fails the test. Snapshot it in a single query instead.
183 lines
8.6 KiB
Swift
183 lines
8.6 KiB
Swift
import ArgumentParser
|
|
import Foundation
|
|
import Subprocess
|
|
import XcresultparserLib
|
|
import Yams
|
|
|
|
struct CI: ParsableCommand {
|
|
static let configuration = CommandConfiguration(abstract: "CI workflow commands that can be run both locally and in CI environments.",
|
|
subcommands: [
|
|
PreviewTests.self,
|
|
AccessibilityTests.self,
|
|
UnitTests.self,
|
|
UITests.self,
|
|
IntegrationTests.self,
|
|
RunTests.self,
|
|
ConfigureNightly.self,
|
|
ConfigureProduction.self,
|
|
TagNightly.self,
|
|
UploadDSYMs.self,
|
|
ReleaseToGitHub.self
|
|
])
|
|
|
|
static let defaultOSVersion = "27.0"
|
|
static let testOutputDirectory = "test_output"
|
|
|
|
/// Reads the `MARKETING_VERSION` from `project.yml`.
|
|
static func readMarketingVersion() throws -> String {
|
|
let projectURL = URL.projectDirectory.appending(component: "project.yml")
|
|
let projectString = try String(contentsOf: projectURL, encoding: .utf8)
|
|
|
|
guard let projectConfig = try Yams.compose(yaml: projectString),
|
|
let version = projectConfig["settings"]?["MARKETING_VERSION"]?.string else {
|
|
throw ValidationError("Could not find MARKETING_VERSION in project.yml.")
|
|
}
|
|
|
|
return version
|
|
}
|
|
|
|
// MARK: - Linting
|
|
|
|
/// Runs SwiftFormat in lint mode against the current directory.
|
|
static func lint() async throws {
|
|
logger.info("\n🔍 Running SwiftFormat lint…\n")
|
|
|
|
do {
|
|
try await run(.name("swiftformat"), ["--lint", "."])
|
|
} catch {
|
|
logger.error("\n❌ SwiftFormat failed.\n")
|
|
annotateError(title: "SwiftFormat lint failed", "Run `swiftformat .` from the project root and commit the changes.")
|
|
throw error
|
|
}
|
|
logger.info("\n✅ SwiftFormat passed.\n")
|
|
}
|
|
|
|
// MARK: - GitHub Actions
|
|
|
|
/// Logs an error annotation, surfacing the failure on the workflow run's summary page.
|
|
///
|
|
/// This is printed directly as the workflow command must be at the very start of the line.
|
|
static func annotateError(title: String, _ message: String) {
|
|
print("::error title=\(title)::\(message)")
|
|
}
|
|
|
|
// MARK: - Test Results
|
|
|
|
/// Collects coverage from an xcresult bundle using xcresultparser (cobertura format).
|
|
/// Failures are non-fatal — the output file simply won't be created.
|
|
static func collectCoverage(resultBundle: String, target: String = "ElementX", outputName: String) async {
|
|
let projectPath = URL.projectDirectory.path
|
|
let resultBundlePath = "\(testOutputDirectory)/\(resultBundle)"
|
|
let outputPath = "\(testOutputDirectory)/\(outputName)"
|
|
|
|
guard FileManager.default.fileExists(atPath: resultBundlePath) else {
|
|
logger.error("\n❌ Result bundle not found at \(resultBundlePath), skipping coverage collection.\n")
|
|
return
|
|
}
|
|
|
|
do {
|
|
let converter = try CoberturaCoverageConverter(with: URL(filePath: resultBundlePath),
|
|
projectRoot: projectPath,
|
|
coverageTargets: [target],
|
|
strictPathnames: false)
|
|
try converter.xmlString(quiet: true).write(toFile: outputPath, atomically: true, encoding: .utf8)
|
|
logger.info("\n📊 Coverage report: \(outputPath)\n")
|
|
} catch {
|
|
logger.error("\n❌ Failed to collect coverage for \(resultBundle): \(error.localizedDescription)\n")
|
|
}
|
|
}
|
|
|
|
/// Collects test results from an xcresult bundle using xcresultparser (junit format).
|
|
/// Failures are non-fatal — the output file simply won't be created.
|
|
static func collectTestResults(resultBundle: String, outputName: String) async {
|
|
let projectPath = URL.projectDirectory.path
|
|
let resultBundlePath = "\(testOutputDirectory)/\(resultBundle)"
|
|
let outputPath = "\(testOutputDirectory)/\(outputName)"
|
|
|
|
guard FileManager.default.fileExists(atPath: resultBundlePath) else {
|
|
logger.info(" Result bundle not found at \(resultBundlePath), skipping test result collection.")
|
|
return
|
|
}
|
|
|
|
do {
|
|
let junitXML = try JunitXML(with: URL(filePath: resultBundlePath), projectRoot: projectPath)
|
|
try junitXML.xmlString.write(toFile: outputPath, atomically: true, encoding: .utf8)
|
|
logger.info("📋 Test results: \(outputPath)")
|
|
} catch {
|
|
logger.error("\n❌ Failed to collect test results for \(resultBundle): \(error.localizedDescription)\n")
|
|
}
|
|
}
|
|
|
|
/// Zips xcresult bundles in the test output directory for faster artifact uploads.
|
|
static func zipResults(bundles: [String], outputName: String) async {
|
|
let bundleArgs = bundles.joined(separator: " ")
|
|
do {
|
|
logger.info("\n📦 Zipping test results…")
|
|
try await run(.path("/bin/zsh"), ["-cu", "cd \(testOutputDirectory) && zip -rq \(outputName) \(bundleArgs)"])
|
|
logger.info("📦 Zipped: \(testOutputDirectory)/\(outputName)\n")
|
|
} catch {
|
|
logger.error("\n❌ Failed to zip results: \(error.localizedDescription)\n")
|
|
}
|
|
}
|
|
|
|
// MARK: - Shell Interaction
|
|
|
|
@discardableResult
|
|
static func run<Output: OutputProtocol, Error: ErrorOutputProtocol>(_ executable: Executable,
|
|
_ arguments: Arguments = [],
|
|
environment: Environment = .inherit,
|
|
output: Output = .standardOutput,
|
|
error: Error = .standardError) async throws -> CollectedResult<Output, Error> {
|
|
logger.info("Running \(executable), with arguments: \(arguments)")
|
|
|
|
let result = try await Subprocess.run(executable,
|
|
arguments: arguments,
|
|
environment: environment,
|
|
output: output,
|
|
error: error)
|
|
|
|
if case let .exited(code) = result.terminationStatus, code != 0 {
|
|
throw ExitCode.failure
|
|
}
|
|
|
|
return result
|
|
}
|
|
|
|
// MARK: - Git
|
|
|
|
static func gitConfigureGlobals() async throws {
|
|
try await CI.run(.name("git"), ["config", "--global", "user.name", "Element CI"])
|
|
try await CI.run(.name("git"), ["config", "--global", "user.email", "ci@element.io"])
|
|
}
|
|
|
|
static func gitRepositoryURL() async throws -> String {
|
|
guard let rawURL = try await CI.run(.name("git"), ["ls-remote", "--get-url", "origin"],
|
|
output: .string(limit: 4096)).standardOutput else {
|
|
throw ValidationError("Could not determine the git remote URL.")
|
|
}
|
|
|
|
return rawURL
|
|
.replacingOccurrences(of: "http://", with: "")
|
|
.replacingOccurrences(of: "https://", with: "")
|
|
.replacingOccurrences(of: "git@", with: "")
|
|
.replacingOccurrences(of: ".git", with: "")
|
|
.trimmingCharacters(in: .whitespacesAndNewlines)
|
|
}
|
|
|
|
static func gitPush(tagName: String? = nil) async throws {
|
|
guard let apiToken = ProcessInfo.processInfo.environment["GITHUB_TOKEN"], !apiToken.isEmpty
|
|
else {
|
|
throw ValidationError("GITHUB_TOKEN environment variable is not set.")
|
|
}
|
|
|
|
let repoURL = try await CI.gitRepositoryURL()
|
|
|
|
if let tagName {
|
|
try await CI.run(.name("git"), ["tag", tagName])
|
|
try await CI.run(.name("git"), ["push", "https://\(apiToken)@\(repoURL)", tagName])
|
|
} else {
|
|
try await CI.run(.name("git"), ["push", "https://\(apiToken)@\(repoURL)"])
|
|
}
|
|
}
|
|
}
|