Merge pull request #1707 from sparkle-project/github-ci-1.x

This commit is contained in:
Kornel authored and GitHub committed 2021-01-03 10:09:01 +00:00
commit 5f47ce3dea
3 files changed
+92 -83

No files matched your search

+47
View File
@@ -0,0 +1,47 @@
name: Build & Tests
on:
push:
branches: [ 2.x, master ]
pull_request:
branches: [ 2.x, master ]
jobs:
build:
strategy:
matrix:
xcode: ['/Applications/Xcode_12.2.app/Contents/Developer', '/Applications/Xcode_11.7.app/Contents/Developer']
name: Build and Test Sparkle
runs-on: macos-10.15
steps:
- name: Checkout
uses: actions/checkout@v2
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
if: failure()
uses: actions/upload-artifact@v2
with:
name: build-logs
path: build/Logs
-7
View File
@@ -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
+45 -76
View File
@@ -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()
}
}