Skip to content

Commit

Permalink
Rewrite make scripts to seperate bash script making it more robust
Browse files Browse the repository at this point in the history
  • Loading branch information
radeknovis committed Aug 1, 2023
1 parent 45b589a commit 2aaf026
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 74 deletions.
84 changes: 10 additions & 74 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,94 +16,30 @@ ifeq "${EXISTS_FASTLANE}" ""
endif
@echo "All dependencies was installed"

test_setup:
defaults write com.apple.dt.XCBuild IgnoreFileSystemDeviceInodeChanges -bool YES
rm -rf test_results
mkdir test_results

build_all:
rm -rf test_results
set -o pipefail && xcodebuild -scheme "WalletConnect-Package" -destination "platform=iOS Simulator,name=iPhone 11" -derivedDataPath DerivedDataCache -clonedSourcePackagesDirPath ../SourcePackagesCache RELAY_HOST='$(RELAY_HOST)' PROJECT_ID='$(PROJECT_ID)' build-for-testing | xcpretty
set -o pipefail && xcodebuild -project "Example/ExampleApp.xcodeproj" -scheme "BuildAll" -destination "platform=iOS Simulator,name=iPhone 11" -derivedDataPath DerivedDataCache -clonedSourcePackagesDirPath ../SourcePackagesCache RELAY_HOST='$(RELAY_HOST)' PROJECT_ID='$(PROJECT_ID)' CAST_HOST='$(CAST_HOST)' build-for-testing | xcpretty

build_dapp:
fastlane build scheme:DApp

build_wallet:
fastlane build scheme:WalletApp

echo_ui_tests:
echo "EchoUITests disabled"

ui_tests:
echo "UI Tests disabled"

unitxctestrun = $(shell find . -name '*WalletConnect-Package*.xctestrun')

unit_tests: test_setup
ifneq ($(unitxctestrun),)
set -o pipefail && env NSUnbufferedIO=YES xcodebuild -destination 'platform=iOS Simulator,name=iPhone 13' -derivedDataPath DerivedDataCache -clonedSourcePackagesDirPath ../SourcePackagesCache -resultBundlePath 'test_results/UnitTests.xcresult' -xctestrun '$(unitxctestrun)' test-without-building | tee ./test_results/xcodebuild.log | xcpretty --report junit --output ./test_results/report.junit
else
set -o pipefail && env NSUnbufferedIO=YES xcodebuild -scheme WalletConnect-Package -destination 'platform=iOS Simulator,name=iPhone 13' -derivedDataPath DerivedDataCache -clonedSourcePackagesDirPath ../SourcePackagesCache -resultBundlePath 'test_results/UnitTests.xcresult' test | tee ./test_results/xcodebuild.log | xcpretty --report junit --output ./test_results/report.junit
endif

integrationxctestrun = $(shell find . -name '*_IntegrationTests*.xctestrun')

integration_tests: test_setup
ifneq ($(integrationxctestrun),)
# override ENV variables
plutil -replace TestConfigurations.0.TestTargets.0.EnvironmentVariables.RELAY_HOST -string $(RELAY_HOST) $(integrationxctestrun)
plutil -replace TestConfigurations.0.TestTargets.0.EnvironmentVariables.PROJECT_ID -string $(PROJECT_ID) $(integrationxctestrun)
plutil -replace TestConfigurations.0.TestTargets.0.EnvironmentVariables.GM_DAPP_PROJECT_ID -string $(GM_DAPP_PROJECT_ID) $(integrationxctestrun)
plutil -replace TestConfigurations.0.TestTargets.0.EnvironmentVariables.GM_DAPP_PROJECT_SECRET -string $(GM_DAPP_PROJECT_SECRET) $(integrationxctestrun)
plutil -replace TestConfigurations.0.TestTargets.0.EnvironmentVariables.CAST_HOST -string $(CAST_HOST) $(integrationxctestrun)
# test-without-building
set -o pipefail && env NSUnbufferedIO=YES xcodebuild -destination 'platform=iOS Simulator,name=iPhone 14' -derivedDataPath DerivedDataCache -clonedSourcePackagesDirPath ../SourcePackagesCache -resultBundlePath 'test_results/IntegrationTests.xcresult' -xctestrun '$(integrationxctestrun)' test-without-building | tee ./test_results/xcodebuild.log | xcpretty --report junit --output ./test_results/report.junit
else
set -o pipefail && env NSUnbufferedIO=YES xcodebuild -project Example/ExampleApp.xcodeproj -scheme IntegrationTests -testPlan IntegrationTests -destination 'platform=iOS Simulator,name=iPhone 14' -derivedDataPath DerivedDataCache -clonedSourcePackagesDirPath ../SourcePackagesCache -resultBundlePath 'test_results/IntegrationTests.xcresult' RELAY_HOST='$(RELAY_HOST)' PROJECT_ID='$(PROJECT_ID)' GM_DAPP_PROJECT_ID='$(GM_DAPP_PROJECT_ID)' GM_DAPP_PROJECT_SECRET='$(GM_DAPP_PROJECT_SECRET)' CAST_HOST='$(CAST_HOST)' test | tee ./test_results/xcodebuild.log | xcpretty --report junit --output ./test_results/report.junit
endif

relayxctestrun = $(shell find . -name '*_RelayIntegrationTests*.xctestrun')

relay_tests: test_setup
ifneq ($(relayxctestrun),)
# override ENV variables
plutil -replace TestConfigurations.0.TestTargets.0.EnvironmentVariables.RELAY_HOST -string $(RELAY_HOST) $(relayxctestrun)
plutil -replace TestConfigurations.0.TestTargets.0.EnvironmentVariables.PROJECT_ID -string $(PROJECT_ID) $(relayxctestrun)
# test-without-building
set -o pipefail && env NSUnbufferedIO=YES xcodebuild -destination 'platform=iOS Simulator,name=iPhone 12' -derivedDataPath DerivedDataCache -resultBundlePath 'test_results/RelayIntegrationTests.xcresult' -xctestrun '$(relayxctestrun)' test-without-building | tee ./test_results/xcodebuild.log | xcpretty --report junit --output ./test_results/report.junit
else
set -o pipefail && env NSUnbufferedIO=YES xcodebuild -project Example/ExampleApp.xcodeproj -scheme RelayIntegrationTests -destination 'platform=iOS Simulator,name=iPhone 12' -derivedDataPath DerivedDataCache -resultBundlePath 'test_results/RelayIntegrationTests.xcresult' RELAY_HOST='$(RELAY_HOST)' PROJECT_ID='$(PROJECT_ID)' test | tee ./test_results/xcodebuild.log | xcpretty --report junit --output ./test_results/report.junit
endif
unit_tests:
./run_tests.sh --scheme WalletConnect-Package

notifyxctestrun = $(shell find . -name '*_NotifyTests*.xctestrun')
integration_tests:
./run_tests.sh --scheme IntegrationTests --testplan IntegrationTests --project Example/ExampleApp.xcodeproj

notify_tests: test_setup
ifneq ($(notifyxctestrun),)
# override ENV variables
plutil -replace TestConfigurations.0.TestTargets.0.EnvironmentVariables.RELAY_HOST -string $(RELAY_HOST) $(notifyxctestrun)
plutil -replace TestConfigurations.0.TestTargets.0.EnvironmentVariables.PROJECT_ID -string $(PROJECT_ID) $(notifyxctestrun)
plutil -replace TestConfigurations.0.TestTargets.0.EnvironmentVariables.GM_DAPP_PROJECT_ID -string $(GM_DAPP_PROJECT_ID) $(notifyxctestrun)
plutil -replace TestConfigurations.0.TestTargets.0.EnvironmentVariables.GM_DAPP_PROJECT_SECRET -string $(GM_DAPP_PROJECT_SECRET) $(notifyxctestrun)
plutil -replace TestConfigurations.0.TestTargets.0.EnvironmentVariables.CAST_HOST -string $(CAST_HOST) $(notifyxctestrun)
# test-without-building
set -o pipefail && env NSUnbufferedIO=YES xcodebuild -destination 'platform=iOS Simulator,name=iPhone 14' -derivedDataPath DerivedDataCache -clonedSourcePackagesDirPath ../SourcePackagesCache -resultBundlePath 'test_results/NotifyTests.xcresult' -xctestrun '$(notifyxctestrun)' test-without-building | tee ./test_results/xcodebuild.log | xcpretty --report junit --output ./test_results/report.junit
else
set -o pipefail && env NSUnbufferedIO=YES xcodebuild -project Example/ExampleApp.xcodeproj -scheme NotifyTests -destination 'platform=iOS Simulator,name=iPhone 14' -derivedDataPath DerivedDataCache -resultBundlePath 'test_results/NotifyTests.xcresult' RELAY_HOST='$(RELAY_HOST)' PROJECT_ID='$(PROJECT_ID)' GM_DAPP_PROJECT_ID='$(GM_DAPP_PROJECT_ID)' GM_DAPP_PROJECT_SECRET='$(GM_DAPP_PROJECT_SECRET)' CAST_HOST='$(CAST_HOST)' test | tee ./test_results/xcodebuild.log | xcpretty --report junit --output ./test_results/report.junit
endif
relay_tests:
./run_tests.sh --scheme RelayIntegrationTests --project Example/ExampleApp.xcodeproj

smokexctestrun = $(shell find . -name '*_SmokeTests*.xctestrun')
notify_tests:
./run_tests.sh --scheme NotifyTests --project Example/ExampleApp.xcodeproj

smoke_tests: test_setup
ifneq ($(smokexctestrun),)
# override ENV variables
plutil -replace TestConfigurations.0.TestTargets.0.EnvironmentVariables.RELAY_HOST -string $(RELAY_HOST) $(smokexctestrun)
plutil -replace TestConfigurations.0.TestTargets.0.EnvironmentVariables.PROJECT_ID -string $(PROJECT_ID) $(smokexctestrun)
# test-without-building
set -o pipefail && env NSUnbufferedIO=YES xcodebuild -destination 'platform=iOS Simulator,name=iPhone 14' -derivedDataPath DerivedDataCache -clonedSourcePackagesDirPath ../SourcePackagesCache -resultBundlePath 'test_results/SmokeTests.xcresult' -xctestrun '$(smokexctestrun)' test-without-building | tee ./test_results/xcodebuild.log | xcpretty --report junit --output ./test_results/report.junit
else
set -o pipefail && env NSUnbufferedIO=YES xcodebuild -project Example/ExampleApp.xcodeproj -scheme IntegrationTests -testPlan SmokeTests -destination 'platform=iOS Simulator,name=iPhone 14' -derivedDataPath DerivedDataCache -clonedSourcePackagesDirPath ../SourcePackagesCache -resultBundlePath 'test_results/SmokeTests.xcresult' RELAY_HOST='$(RELAY_HOST)' PROJECT_ID='$(PROJECT_ID)' test | tee ./test_results/xcodebuild.log | xcpretty --report junit --output ./test_results/report.junit
endif
smoke_tests:
./run_tests.sh --scheme IntegrationTests --testplan SmokeTests --project Example/ExampleApp.xcodeproj

release_wallet:
fastlane release_testflight username:$(APPLE_ID) token:$(TOKEN) relay_host:$(RELAY_HOST) project_id:$(PROJECT_ID) --env WalletApp
Expand Down
104 changes: 104 additions & 0 deletions run_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
#!/bin/bash
set -e

# Parse named arguments
while [[ $# -gt 0 ]]; do
case $1 in
-s|--scheme) SCHEME="$2"; shift;;
-p|--project) PROJECT="$2"; shift;;
-t|--testplan) TESTPLAN="$2"; shift;;
esac
shift
done

if [ -z "$SCHEME" ]; then
echo "No scheme provided"
exit 1
fi

# Function to update xctestrun file
update_xctestrun() {
# Parse named arguments
while [[ $# -gt 0 ]]; do
case $1 in
-k|--key) KEY="$2"; shift;;
-v|--value) VALUE="$2"; shift;;
-t|--target) TARGET="$2"; shift;;
esac
shift
done

if [ -n "$VALUE" ]; then
echo "Updating $KEY with $VALUE"
plutil -replace TestConfigurations.0.TestTargets.0.EnvironmentVariables.$KEY -string "$VALUE" "$TARGET"
else
echo "No value provided for $KEY"
fi
}

# Set XCBuild defaults
defaults write com.apple.dt.XCBuild IgnoreFileSystemDeviceInodeChanges -bool YES

# Remove and recreate test_results directory
echo "Removing and recreating test_results directory"
rm -rf test_results
mkdir test_results

# Create ephemeral simulator
DEVICE_ID=$(xcrun simctl create "EphemeralSim$SCHEME" "iPhone 14")
echo "Created ephemeral simulator with id: $DEVICE_ID"

# If xctestrun file exists, update it and run test-without-building otherwise run regular test
XCTESTRUN=$(find . -name "*_$SCHEME*.xctestrun")

if [ -z "$XCTESTRUN" ]; then
echo "XCTESTRUN file not found"

(
set -x

#If xctestrun file does not exist, run regular test
set -o pipefail && env NSUnbufferedIO=YES \
xcodebuild \
${PROJECT:+-project "$PROJECT"} \
${TESTPLAN:+-testPlan "$TESTPLAN"} \
-scheme "$SCHEME" \
-destination "platform=iOS Simulator,id=$DEVICE_ID" \
-derivedDataPath DerivedDataCache \
-clonedSourcePackagesDirPath ../SourcePackagesCache \
-resultBundlePath "test_results/$SCHEME.xcresult" \
test \
| tee ./test_results/xcodebuild.log \
| xcpretty --report junit --output ./test_results/report.junit
)
else

echo "XCTESTRUN file found: $XCTESTRUN"

update_xctestrun --key "RELAY_HOST" --value "$RELAY_HOST" --target "$XCTESTRUN"
update_xctestrun --key "PROJECT_ID" --value "$PROJECT_ID" --target "$XCTESTRUN"
update_xctestrun --key "GM_DAPP_PROJECT_ID" --value "$GM_DAPP_PROJECT_ID" --target "$XCTESTRUN"
update_xctestrun --key "GM_DAPP_PROJECT_SECRET" --value "$GM_DAPP_PROJECT_SECRET" --target "$XCTESTRUN"
update_xctestrun --key "CAST_HOST" --value "$CAST_HOST" --target "$XCTESTRUN"

(
set -x

set -o pipefail && env NSUnbufferedIO=YES \
xcodebuild \
-xctestrun "$XCTESTRUN" \
-destination "platform=iOS Simulator,id=$DEVICE_ID" \
-derivedDataPath DerivedDataCache \
-clonedSourcePackagesDirPath ../SourcePackagesCache \
-resultBundlePath "test_results/$SCHEME.xcresult" \
test-without-building \
| tee ./test_results/xcodebuild.log \
| xcpretty --report junit --output ./test_results/report.junit
)
fi

# Remove ephemeral simulator
echo "Removing ephemeral simulator"
xcrun simctl delete "$DEVICE_ID"

echo "Done"

0 comments on commit 2aaf026

Please sign in to comment.