diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ce27d16..96f46e8 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -45,3 +45,45 @@ jobs: -skipMacroValidation \ -destination "generic/platform=iOS Simulator" \ clean build + + - name: Run unit tests (all *Tests schemes) + run: | + set -euo pipefail + + TEST_SCHEMES="$(xcodebuild -workspace Dori-iOS.xcworkspace -list | awk ' + /Schemes:/ { in_schemes=1; next } + in_schemes && NF { + gsub(/^[[:space:]]+|[[:space:]]+$/, "", $0) + print + } + ' | grep 'Tests$' || true)" + + if [ -z "${TEST_SCHEMES}" ]; then + echo "No *Tests schemes found. Skipping test step." + exit 0 + fi + + SIMULATOR_ID="$(xcrun simctl list devices available | awk -F '[()]' ' + /iPhone/ && /(Shutdown|Booted)/ { print $2; exit } + ')" + + if [ -z "${SIMULATOR_ID}" ]; then + echo "No available iPhone simulator found." + exit 1 + fi + + echo "Using simulator id: ${SIMULATOR_ID}" + echo "Test schemes:" + echo "${TEST_SCHEMES}" + + while IFS= read -r scheme; do + [ -z "${scheme}" ] && continue + echo "Running tests for scheme: ${scheme}" + xcodebuild \ + -workspace Dori-iOS.xcworkspace \ + -scheme "${scheme}" \ + -configuration Debug \ + -skipMacroValidation \ + -destination "id=${SIMULATOR_ID}" \ + test + done <<< "${TEST_SCHEMES}"