Skip to content

Commit

Permalink
Merge pull request #13 from mbernson/feature/github-actions-tests
Browse files Browse the repository at this point in the history
Run tests on GitHub Actions
  • Loading branch information
mbernson authored Jan 24, 2025
2 parents 337f070 + 138342e commit 53e95fd
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 28 deletions.
41 changes: 41 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Test

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
build:
name: Build and Test on iOS Simulator
runs-on: macos-latest
env:
scheme: ${{ 'CCCTube' }}
platform: ${{ 'iOS Simulator' }}

steps:
- name: Checkout
uses: actions/checkout@v4

- uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: "16.1"

- name: Build
run: |
# xcrun xctrace returns via stderr, not the expected stdout (see https://developer.apple.com/forums/thread/663959)
device=`xcrun xctrace list devices 2>&1 | grep -oE 'iPhone.*?[^\(]+' | head -1 | awk '{$1=$1;print}' | sed -e "s/ Simulator$//"`
if [ $scheme = default ]; then scheme=$(cat default); fi
if [ "`ls -A | grep -i \\.xcworkspace\$`" ]; then filetype_parameter="workspace" && file_to_build="`ls -A | grep -i \\.xcworkspace\$`"; else filetype_parameter="project" && file_to_build="`ls -A | grep -i \\.xcodeproj\$`"; fi
file_to_build=`echo $file_to_build | awk '{$1=$1;print}'`
xcodebuild build-for-testing -scheme "$scheme" -"$filetype_parameter" "$file_to_build" -destination "platform=$platform,name=$device"
- name: Test
run: |
# xcrun xctrace returns via stderr, not the expected stdout (see https://developer.apple.com/forums/thread/663959)
device=`xcrun xctrace list devices 2>&1 | grep -oE 'iPhone.*?[^\(]+' | head -1 | awk '{$1=$1;print}' | sed -e "s/ Simulator$//"`
if [ $scheme = default ]; then scheme=$(cat default); fi
if [ "`ls -A | grep -i \\.xcworkspace\$`" ]; then filetype_parameter="workspace" && file_to_build="`ls -A | grep -i \\.xcworkspace\$`"; else filetype_parameter="project" && file_to_build="`ls -A | grep -i \\.xcodeproj\$`"; fi
file_to_build=`echo $file_to_build | awk '{$1=$1;print}'`
xcodebuild test-without-building -scheme "$scheme" -"$filetype_parameter" "$file_to_build" -destination "platform=$platform,name=$device"
8 changes: 4 additions & 4 deletions CCCTube.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@
D59139402895851300369402 /* TVServices.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = TVServices.framework; path = System/Library/Frameworks/TVServices.framework; sourceTree = SDKROOT; };
D591395928958B2600369402 /* CCCTubeTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = CCCTubeTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
D5A156D4289462B3006989FF /* CCCTube.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = CCCTube.app; sourceTree = BUILT_PRODUCTS_DIR; };
D5D2CB292D43EBB300E08E44 /* Screenshots.xctestplan */ = {isa = PBXFileReference; lastKnownFileType = text; path = Screenshots.xctestplan; sourceTree = "<group>"; };
D5D2CB2A2D43EBB300E08E44 /* UnitTests.xctestplan */ = {isa = PBXFileReference; lastKnownFileType = text; path = UnitTests.xctestplan; sourceTree = "<group>"; };
D5EFB19C2B407683008CFE82 /* CCCTubeUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = CCCTubeUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
D5EFB1A72B407792008CFE82 /* UnitTests.xctestplan */ = {isa = PBXFileReference; lastKnownFileType = text; path = UnitTests.xctestplan; sourceTree = SOURCE_ROOT; };
D5EFB1A82B4077A3008CFE82 /* Screenshots.xctestplan */ = {isa = PBXFileReference; lastKnownFileType = text; path = Screenshots.xctestplan; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFileSystemSynchronizedBuildFileExceptionSet section */
Expand Down Expand Up @@ -156,8 +156,8 @@
isa = PBXGroup;
children = (
D557E8BA2896F70400342EE2 /* README.md */,
D5EFB1A72B407792008CFE82 /* UnitTests.xctestplan */,
D5EFB1A82B4077A3008CFE82 /* Screenshots.xctestplan */,
D5D2CB292D43EBB300E08E44 /* Screenshots.xctestplan */,
D5D2CB2A2D43EBB300E08E44 /* UnitTests.xctestplan */,
D5AFD6D92C9BFCF700BF89F5 /* CCCTube */,
D50C6F7328956D770003D1D0 /* CCCApi */,
D5AFD6FB2C9BFCFB00BF89F5 /* TopShelf */,
Expand Down
6 changes: 3 additions & 3 deletions CCCTube.xcodeproj/xcshareddata/xcschemes/CCCTube.xcscheme
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@
shouldUseLaunchSchemeArgsEnv = "YES">
<TestPlans>
<TestPlanReference
reference = "container:CCCTubeTests/UnitTests.xctestplan"
default = "YES">
reference = "container:Screenshots.xctestplan">
</TestPlanReference>
<TestPlanReference
reference = "container:CCCTubeUITests/Screenshots.xctestplan">
reference = "container:UnitTests.xctestplan"
default = "YES">
</TestPlanReference>
</TestPlans>
<Testables>
Expand Down
2 changes: 1 addition & 1 deletion CCCTubeUITests/CCCTubeUIScreenshotTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ final class CCCTubeUIScreenshotTests: XCTestCase {
}

func testConferences() {
app.tabBars.buttons["Conferences"].firstMatch.tap()
app.buttons["Conferences"].firstMatch.tap()
XCTAssertTrue(app.otherElements["ConferencesGrid"].buttons.firstMatch.waitForExistence(timeout: 3.0))
wait(forTimeInterval: 2.0) // Give the app some time to load
takeScreenshot("Conferences")
Expand Down
23 changes: 3 additions & 20 deletions screenshots.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

# This script automates the process of taking screenshots for the App Store.
# It uses UI tests target, which are configured in the Screenshots test plan.
# The final screenshots are saved in a folder named 'screenshots'.

set -e

Expand All @@ -17,23 +18,7 @@ then
exit 1
fi

# xcrun simctl create "iPhone 15 Plus" "iPhone 15 Plus" "iOS17.5"
# xcrun simctl create "iPhone 8 Plus" "iPhone 8 Plus" "iOS16.4"
# xcrun simctl create "iPad Pro 13-inch (M4)" "iPad Pro 13-inch (M4)" "iOS17.5"
# xcrun simctl create "iPad Pro (12.9-inch) (2nd generation)" "iPad Pro (12.9-inch) (2nd generation)" "iOS17.5"

# xcodebuild -verbose \
# -project "CCCTube.xcodeproj" \
# -scheme "CCCTube" \
# -destination "platform=iOS Simulator,name=iPhone 8 Plus" \
# -destination "platform=iOS Simulator,name=iPhone 15 Plus" \
# -destination "platform=iOS Simulator,name=iPad Pro 13-inch (M4)" \
# -destination "platform=iOS Simulator,name=iPad Pro (12.9-inch) (2nd generation)" \
# -resultBundlePath "./Screenshots.xcresult" \
# -testPlan Screenshots \
# clean test

declare -a destinations=("platform=iOS Simulator,name=iPhone 8 Plus" "platform=iOS Simulator,name=iPhone 15 Plus" "platform=iOS Simulator,name=iPad Pro 13-inch (M4)" "platform=iOS Simulator,name=iPad Pro (12.9-inch) (2nd generation)")
declare -a destinations=("platform=iOS Simulator,name=iPhone 16 Plus" "platform=iOS Simulator,name=iPad Pro 13-inch (M4)")

rm -rf ./screenshots
mkdir ./screenshots
Expand All @@ -47,7 +32,7 @@ echo "Taking screenshots for $destination"
xcodebuild -quiet \
-project "CCCTube.xcodeproj" \
-scheme "CCCTube" \
-destination "platform=iOS Simulator,name=iPhone 15 Plus" \
-destination "$destination" \
-resultBundlePath "./Screenshots.xcresult" \
-testPlan Screenshots \
clean test
Expand All @@ -58,5 +43,3 @@ done

# Remove alpha channel from the screenshots, otherwise the App Store will reject them
find ./screenshots -name "*.png" -exec convert "{}" -alpha off "{}" \;

open ./screenshots

0 comments on commit 53e95fd

Please sign in to comment.