From 3695ae6059d97c3bd484c329927e5658429f3d8f Mon Sep 17 00:00:00 2001 From: Zorg Date: Fri, 1 Jan 2021 14:19:02 -0800 Subject: [PATCH 1/3] Adopt GitHub Actions for CI and fix issues with our UI test --- .github/workflows/ci.yml | 39 +++++++++ .travis.yml | 7 -- UITests/SUTestApplicationTest.swift | 121 +++++++++++----------------- 3 files changed, 84 insertions(+), 83 deletions(-) create mode 100644 .github/workflows/ci.yml delete mode 100644 .travis.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..75e43c35 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,39 @@ +name: Build & Tests + +on: + push: + branches: [ 2.x, master ] + pull_request: + branches: [ 2.x, master ] + +jobs: + build: + strategy: + matrix: + os: [macos-11.0, macos-10.15] + name: Build and Test Sparkle + runs-on: ${{ matrix.os }} + + steps: + - name: Checkout + uses: actions/checkout@v2 + with: + submodules: true + - name: Build Unit Tests + run: | + xcodebuild build-for-testing -project Sparkle.xcodeproj -scheme Distribution -enableCodeCoverage YES -derivedDataPath build + - name: Run Unit Tests + run: | + xcodebuild test-without-building -project Sparkle.xcodeproj -scheme Distribution -enableCodeCoverage YES -derivedDataPath build + - name: Build UI Tests + run: | + xcodebuild build-for-testing -project Sparkle.xcodeproj -scheme UITests -configuration Debug -derivedDataPath build + - name: Run UI Tests + run: | + xcodebuild test-without-building -project Sparkle.xcodeproj -scheme UITests -configuration Debug -derivedDataPath build + - name: Archive Test Results + if: failure() + uses: actions/upload-artifact@v2 + with: + name: build-logs + path: build/Logs diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index cda17383..00000000 --- a/.travis.yml +++ /dev/null @@ -1,7 +0,0 @@ -os: osx -language: objective-c -osx_image: - - xcode11.4 - - xcode12 -script: - - set -o pipefail && xcodebuild test -project Sparkle.xcodeproj -scheme Distribution -derivedDataPath build -enableCodeCoverage YES | xcpretty diff --git a/UITests/SUTestApplicationTest.swift b/UITests/SUTestApplicationTest.swift index 36deb7cd..0d0fab30 100644 --- a/UITests/SUTestApplicationTest.swift +++ b/UITests/SUTestApplicationTest.swift @@ -10,102 +10,71 @@ import XCTest class SUTestApplicationTest: XCTestCase { - var testApplicationURL: URL? - var testApplicationBackupURL: URL? - var tempDirectoryURL: URL? + // TODO: don't hardcode bundle ID? + let TEST_APP_BUNDLE_ID = "org.sparkle-project.SparkleTestApp" func runningTestApplication() -> NSRunningApplication { - // TODO: don't hardcode bundle ID? - let runningApplications = NSRunningApplication.runningApplications(withBundleIdentifier: "org.sparkle-project.SparkleTestApp") + let runningApplications = NSRunningApplication.runningApplications(withBundleIdentifier: TEST_APP_BUNDLE_ID) XCTAssertEqual(runningApplications.count, 1, "More than one or zero running instances of the Test Application are found") return runningApplications[0] } - override func setUp() - { - super.setUp() - - let app = XCUIApplication() - app.launch() - - XCTAssertFalse(app.dialogs["alert"].staticTexts["Update succeeded!"].exists, "Update is already installed; please do a clean build") - - // We need to grab the app URL so we can back up the app - // When a successful test is over we'll revert the update - let testApplicationURL = self.runningTestApplication().bundleURL! - - let tempDirectoryURL = try! FileManager.default.url(for: .itemReplacementDirectory, in: FileManager.SearchPathDomainMask.userDomainMask, appropriateFor: testApplicationURL, create: true) - - let testApplicationBackupURL = tempDirectoryURL.appendingPathComponent(testApplicationURL.lastPathComponent) - - try! FileManager.default.copyItem(at: testApplicationURL, to: testApplicationBackupURL) - - self.testApplicationURL = testApplicationURL - self.testApplicationBackupURL = testApplicationBackupURL - self.tempDirectoryURL = tempDirectoryURL - - // when we add more tests we don't want to continue after a failure - // since a test can fail after the new app has been placed in - self.continueAfterFailure = false - } - - override func tearDown() - { - // Terminate just in case the app hasn't already quit - XCUIApplication().terminate() - - // Revert our update with the original test application - - var resultingURL: NSURL? - try! FileManager.default.replaceItem(at: self.testApplicationURL!, withItemAt: self.testApplicationBackupURL!, backupItemName: nil, options: .usingNewMetadataOnly, resultingItemURL: &resultingURL) - - do { - try FileManager.default.removeItem(at: self.tempDirectoryURL!) - } catch let error as NSError { - NSLog("Failed to remove temporary directory \(self.tempDirectoryURL) with error: \(error)") - } - - // The URL we get back from NSFileManager should be the same.. - XCTAssertEqual(self.testApplicationURL, resultingURL as URL?, "Test application was replaced, but at a different location") - - super.tearDown() - } - + // The debugger may catch the Test app receiving a SIGTERM signal when Sparkle quits the app before installing the new one + // So you may have better luck running this test from the command line without the debugger attached: + // xcodebuild -scheme UITests -configuration Debug test func testRegularUpdate() { let app = XCUIApplication() + app.launch() + + XCTAssertFalse(app.dialogs["alert"].staticTexts["Update succeeded!"].exists, "Update is already installed; please do a clean build") + + let initialRunningApplication = runningTestApplication() + + // Give some time for the Test App to initialize its web server, create an update, and start its updater + sleep(60) + let menuBarsQuery = app.menuBars - menuBarsQuery.menuBarItems["Sparkle Test App"].click() - - // If the update window already showed up automatically, this option will be disabled. - // Even if it's disabled, attempting to click it will do no harm and continue on - menuBarsQuery.menuItems["Check for Updates…"].click() - - // Workaround to make sure we can click the install update button later - // This workaround is needed if the alert prompts up automatically *before* we manually check for updates - // I'm not sure why this workaround works or is necessary - app.dialogs["SUUpdateAlert"].staticTexts["Software Update"].click() + + let checkForUpdatesMenuItem = menuBarsQuery.menuItems["Check for Updates…"] + if checkForUpdatesMenuItem.isEnabled { + checkForUpdatesMenuItem.click() + } else { + // We haven't checked for updates in a while so an automatic check was already done + // in this case click the main menu again to deactivate it + menuBarsQuery.menuBarItems["Sparkle Test App"].click() + } app.dialogs["SUUpdateAlert"].buttons["Install Update"].click() + + // Give some time for the update to finish downloading / extracting + sleep(30) + app.windows["SUStatus"].buttons["Install and Relaunch"].click() // Wait for the new updated app to finish launching so we can test if it's the frontmost app - sleep(3) + sleep(10) - // Our new updated app should be launched now. Test if it's the active app + // From now on, do not rely on XCUIApplication as it only works properly when the XCUITest framework launches the app. + + // Our new updated app should be launched now. Test if it's the active app and the old app is terminated. // We used to run into timing issues where the updated app sometimes may not show up as the frontmost one - XCTAssertTrue(self.runningTestApplication().isActive) + XCTAssertTrue(initialRunningApplication.isTerminated) - // Grab another XCUIApplication instance rather than using the old one, just in case - let updatedApp = XCUIApplication() + let newRunningApplication = self.runningTestApplication() + XCTAssertTrue(newRunningApplication.isActive) + + // Verify the new bundle version - // Check if we can click the "Update succeeded!" label rather than using the exists property - // Checking the exists property doesn't reload the "cache" and as such the UI tests still would think we are - // referring to the older app. Clicking does force the UI tests to find the new app however - updatedApp.dialogs["alert"].staticTexts["Update succeeded!"].click() - - updatedApp.dialogs["alert"].buttons["OK"].click() + let infoCFDictionary = CFBundleCopyInfoDictionaryInDirectory(newRunningApplication.bundleURL! as CFURL) + let infoDictionary = infoCFDictionary! as Dictionary + + let updatedVersion = infoDictionary[kCFBundleVersionKey] as! String + XCTAssertEqual(updatedVersion, "2.0") + + // Clean up + newRunningApplication.forceTerminate() } } From 397467e6d7ed7c75bef34e7c5fad04146fb497df Mon Sep 17 00:00:00 2001 From: Zorg Date: Fri, 1 Jan 2021 19:54:10 -0800 Subject: [PATCH 2/3] Specify Xcode version to use instead of macOS version It is more important OS version is stable in their virtual environment setup. --- .github/workflows/ci.yml | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 75e43c35..ea1d869d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,9 +10,9 @@ jobs: build: strategy: matrix: - os: [macos-11.0, macos-10.15] + xcode: ['/Applications/Xcode_12.2.app/Contents/Developer', '/Applications/Xcode_11.7.app/Contents/Developer'] name: Build and Test Sparkle - runs-on: ${{ matrix.os }} + runs-on: macos-latest steps: - name: Checkout @@ -20,15 +20,23 @@ jobs: with: submodules: true - name: Build Unit Tests + env: + DEVELOPER_DIR: ${{ matrix.xcode }} run: | xcodebuild build-for-testing -project Sparkle.xcodeproj -scheme Distribution -enableCodeCoverage YES -derivedDataPath build - name: Run Unit Tests + env: + DEVELOPER_DIR: ${{ matrix.xcode }} run: | xcodebuild test-without-building -project Sparkle.xcodeproj -scheme Distribution -enableCodeCoverage YES -derivedDataPath build - name: Build UI Tests + env: + DEVELOPER_DIR: ${{ matrix.xcode }} run: | xcodebuild build-for-testing -project Sparkle.xcodeproj -scheme UITests -configuration Debug -derivedDataPath build - name: Run UI Tests + env: + DEVELOPER_DIR: ${{ matrix.xcode }} run: | xcodebuild test-without-building -project Sparkle.xcodeproj -scheme UITests -configuration Debug -derivedDataPath build - name: Archive Test Results From 470e3734b9d2b05afa2210acc30ad209635d982e Mon Sep 17 00:00:00 2001 From: Zorg Date: Sat, 2 Jan 2021 12:57:12 -0800 Subject: [PATCH 3/3] Use macos-10.15 instead of macOS-latest --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ea1d869d..3c7db58f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,7 +12,7 @@ jobs: matrix: xcode: ['/Applications/Xcode_12.2.app/Contents/Developer', '/Applications/Xcode_11.7.app/Contents/Developer'] name: Build and Test Sparkle - runs-on: macos-latest + runs-on: macos-10.15 steps: - name: Checkout