Skip to content

Commit 9e76319

Browse files
Merge pull request #5 from SomeRandomiOSDev/WorkflowTests
Added 'workflowtests.sh' script for mock running all of the workflows locally
2 parents f1bcc00 + 97cd787 commit 9e76319

File tree

7 files changed

+425
-212
lines changed

7 files changed

+425
-212
lines changed

scripts/carthage.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env bash
2-
2+
#
33
# Needed to circumvent an issue with Carthage version < 0.37.0: https://github.com/Carthage/Carthage/issues/3019
44
#
55
# carthage.sh

scripts/config.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env bash
2-
2+
#
33
# config.sh
44
# Usage example: ./config.sh -name <project_name> [-test] [-verbose]
55

scripts/resolvepath.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env bash
2-
2+
#
33
# resolvepath.sh
44
# Usage example: ./resolvepath.sh "./some/random/path/../../"
55

scripts/unittests.sh

Lines changed: 39 additions & 201 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,53 @@
11
#!/usr/bin/env bash
2-
2+
#
33
# unittests.sh
4-
# Usage example: ./unittests.sh [--no-clean]
4+
# Usage example: ./unittests.sh [--no-clean | --no-clean-on-fail]
55

66
# Set Script Variables
77

88
SCRIPT="$("$(dirname "$0")/resolvepath.sh" "$0")"
99
SCRIPTS_DIR="$(dirname "$SCRIPT")"
1010
ROOT_DIR="$(dirname "$SCRIPTS_DIR")"
11-
CURRENT_DIR="$(pwd -P)"
1211

1312
TEMP_DIR="$(mktemp -d)"
1413
PROJECT_NAME="$(basename "$(mktemp -u $TEMP_DIR/ProjectTemplateUnitTests_XXXXXX)")"
1514
OUTPUT_DIR="$TEMP_DIR/$PROJECT_NAME"
1615

16+
NO_CLEAN=0
17+
NO_CLEAN_ON_FAIL=0
18+
1719
EXIT_CODE=0
1820
EXIT_MESSAGE=""
1921

20-
if [ "$1" == "--no-clean" ]; then
21-
NO_CLEAN=1
22-
fi
22+
# Parse Arguments
2323

24-
# Function Definitions
24+
while [[ $# -gt 0 ]]; do
25+
case "$1" in
26+
--no-clean)
27+
NO_CLEAN=1
28+
shift # --no-clean
29+
;;
2530

26-
function cleanup() {
27-
if [ -z ${NO_CLEAN+x} ]; then
28-
cd "$CURRENT_DIR"
29-
rm -rf "$TEMP_DIR"
30-
else
31-
echo "Test Project: $OUTPUT_DIR"
32-
fi
31+
--no-clean-on-fail)
32+
NO_CLEAN_ON_FAIL=1
33+
shift # --no-clean-on-fail
34+
;;
3335

34-
#
36+
*)
37+
echo "Unknown argument: $1"
38+
print_help
39+
esac
40+
done
3541

36-
local CARTHAGE_CACHE="$HOME/Library/Caches/org.carthage.CarthageKit"
37-
if [ -e "$CARTHAGE_CACHE" ]; then
38-
if [ -e "$CARTHAGE_CACHE/dependencies/$PROJECT_NAME" ]; then
39-
rm -rf "$CARTHAGE_CACHE/dependencies/$PROJECT_NAME"
40-
fi
42+
# Function Definitions
4143

42-
for DIR in $(find "$CARTHAGE_CACHE/DerivedData" -mindepth 1 -maxdepth 1 -type d); do
43-
if [ -e "$DIR/$PROJECT_NAME" ]; then
44-
rm -rf "$DIR/$PROJECT_NAME"
45-
fi
46-
done
44+
function cleanup() {
45+
if [[ "$NO_CLEAN" == "1" ]] || [[ "$NO_CLEAN_ON_FAIL" == "1" && "$EXIT_CODE" != "0" ]]; then
46+
echo "Test Project: $OUTPUT_DIR"
47+
else
48+
rm -rf "$TEMP_DIR"
4749
fi
4850

49-
#
50-
5151
if [ ${#EXIT_MESSAGE} -gt 0 ]; then
5252
echo -e "$EXIT_MESSAGE"
5353
fi
@@ -75,44 +75,10 @@ printstep "Setting Up Test Project..."
7575
"$SCRIPTS_DIR/config.sh" -name "$PROJECT_NAME" -output "$TEMP_DIR"
7676
checkresult $? "'config.sh' script failed"
7777

78-
# Check For Unit Test Dependencies
79-
80-
cd "$OUTPUT_DIR"
81-
printstep "Checking Dependencies..."
78+
# Check For Dependencies
8279

83-
### Carthage
80+
printstep "Checking for Configuration Dependencies..."
8481

85-
if which carthage >/dev/null; then
86-
CARTHAGE_VERSION="$(carthage version)"
87-
echo "Carthage: $CARTHAGE_VERSION"
88-
89-
"$SCRIPTS_DIR/versions.sh" "$CARTHAGE_VERSION" "0.37.0"
90-
91-
if [ $? -lt 0 ]; then
92-
echo -e "\033[33mCarthage version of at least 0.37.0 is recommended for running these unit tests\033[0m"
93-
fi
94-
else
95-
checkresult -1 "Carthage is not installed and is required for running unit tests: \033[4;34mhttps://github.com/Carthage/Carthage#installing-carthage"
96-
fi
97-
98-
### CocoaPods
99-
100-
if which pod >/dev/null; then
101-
PODS_VERSION="$(pod --version)"
102-
"$SCRIPTS_DIR/versions.sh" "$PODS_VERSION" "1.7.3"
103-
104-
if [ $? -ge 0 ]; then
105-
echo "CocoaPods: $(pod --version)"
106-
else
107-
checkresult -1 "These unit tests require version 1.7.3 or later of CocoaPods: \033[4;34mhttps://guides.cocoapods.org/using/getting-started.html#updating-cocoapods"
108-
fi
109-
else
110-
checkresult -1 "CocoaPods is not installed and is required for running unit tests: \033[4;34mhttps://guides.cocoapods.org/using/getting-started.html#installation"
111-
fi
112-
113-
### Xcodeproj
114-
115-
# This should be installed with CocoaPods, but we'll include it just in case CocoaPods removes it from its dependencies in a future release
11682
if which xcodeproj >/dev/null; then
11783
echo "Xcodeproj: $(xcodeproj --version)"
11884
else
@@ -126,150 +92,22 @@ printstep "Configuring Test Project..."
12692
echo -e "class SomeClass {\n var value: Int = 3\n}" > "$OUTPUT_DIR/Sources/$PROJECT_NAME/SomeClass.swift"
12793
echo -e "@testable import $PROJECT_NAME\nimport XCTest\n\nclass SomeClassTests: XCTestCase {\n\n func testSomeClass() {\n let object = SomeClass()\n XCTAssertEqual(object.value, 3)\n }\n}" > "$OUTPUT_DIR/Tests/${PROJECT_NAME}Tests/SomeClassTests.swift"
12894

129-
echo "SCRIPTS_DIR: $SCRIPTS_DIR"
13095
ruby "$SCRIPTS_DIR/unittests.rb" "$OUTPUT_DIR/$PROJECT_NAME.xcodeproj" "$OUTPUT_DIR/Sources/$PROJECT_NAME/SomeClass.swift" "$OUTPUT_DIR/Tests/${PROJECT_NAME}Tests/SomeClassTests.swift"
13196
checkresult $? "Unable to configure the test project for testing"
13297

133-
# Run Unit Tests
134-
135-
printstep "Running Unit Tests..."
136-
137-
### Carthage Workflow
138-
139-
printstep "Testing 'carthage.yml' Workflow..."
140-
141-
git add .
142-
git commit -m "Commit" --no-gpg-sign
143-
git tag | xargs git tag -d
144-
git tag --no-sign 1.0
145-
checkresult $? "Unable to tag local git repo for running Carthage unit tests"
146-
147-
echo "git \"file://$OUTPUT_DIR\"" > ./Cartfile
148-
149-
./scripts/carthage.sh update
150-
checkresult $? "Carthage Unit Test failed: \"Build\""
151-
152-
printstep "'carthage.yml' Workflow Tests Passed\n"
153-
154-
### CocoaPods Workflow
155-
156-
printstep "Testing 'cocoapods.yml' Workflow..."
157-
158-
pod lib lint
159-
checkresult $? "CocoaPods Unit Test failed: \"Lint (Dynamic Library)\""
160-
161-
pod lib lint --use-libraries
162-
checkresult $? "CocoaPods Unit Test failed: \"Lint (Static Library)\""
98+
# Run Tests
16399

164-
printstep "'cocoapods.yml' Workflow Tests Passed\n"
100+
ARGS=(--is-running-in-temp-env --project-name "$PROJECT_NAME")
165101

166-
### Swift Package Workflow
167-
168-
printstep "Testing 'swift-package.yml' Workflow..."
169-
170-
swift build -v
171-
checkresult $? "Swift Package Unit Test failed: \"Build\""
172-
173-
swift test -v
174-
checkresult $? "Swift Package Unit Test failed: \"Test\""
175-
176-
printstep "'swift-package.yml' Workflow Tests Passed\n"
177-
178-
### XCFramework Workflow
179-
180-
printstep "Testing 'xcframework.yml' Workflow..."
181-
182-
./scripts/xcframework.sh -output "./$PROJECT_NAME.xcframework"
183-
checkresult $? "XCFramework Unit Test failed: \"Build\""
184-
185-
printstep "'xcframework.yml' Workflow Tests Passed\n"
186-
187-
### Upload Assets Workflow
188-
189-
printstep "Testing 'upload-assets.yml' Workflow..."
190-
191-
zip -rX "$PROJECT_NAME.xcframework.zip" "$PROJECT_NAME.xcframework"
192-
checkresult $? "XCFramework Unit Test failed: \"Zip\""
193-
194-
tar -zcvf "$PROJECT_NAME.xcframework.tar.gz" "$PROJECT_NAME.xcframework"
195-
checkresult $? "XCFramework Unit Test failed: \"Tar\""
196-
197-
printstep "'upload-assets.yml' Workflow Tests Passed\n"
198-
199-
### Xcodebuild Workflow
200-
201-
printstep "Testing 'xcodebuild.yml' Workflow..."
202-
203-
xcodebuild -project "$PROJECT_NAME.xcodeproj" -scheme "$PROJECT_NAME" -destination "generic/platform=iOS" -configuration Debug
204-
checkresult $? "Xcodebuild Unit Test failed: \"Build iOS\""
205-
206-
xcodebuild -project "$PROJECT_NAME.xcodeproj" -scheme "$PROJECT_NAME" -destination "generic/platform=iOS Simulator" -configuration Debug
207-
checkresult $? "Xcodebuild Unit Test failed: \"Build iOS Simulator\""
208-
209-
IOS_SIM="$(xcrun simctl list devices available | grep "iPhone [0-9]" | sort -rV | head -n 1 | sed -E 's/(.+)[ ]*\([^)]*\)[ ]*\([^)]*\)/\1/' | awk '{$1=$1};1')"
210-
211-
xcodebuild -project "$PROJECT_NAME.xcodeproj" -scheme "$PROJECT_NAME" -testPlan "${PROJECT_NAME}Tests" -destination "platform=iOS Simulator,name=$IOS_SIM" -configuration Debug ONLY_ACTIVE_ARCH=YES test
212-
checkresult $? "Xcodebuild Unit Test failed: \"Test iOS\""
213-
214-
xcodebuild -project "$PROJECT_NAME.xcodeproj" -scheme "${PROJECT_NAME}Tests" -testPlan "${PROJECT_NAME}Tests" -destination "platform=iOS Simulator,name=$IOS_SIM" -configuration Debug ONLY_ACTIVE_ARCH=YES test
215-
checkresult $? "Xcodebuild Unit Test failed: \"Test iOS\""
216-
217-
###
218-
219-
xcodebuild -project "$PROJECT_NAME.xcodeproj" -scheme "$PROJECT_NAME" -destination "generic/platform=macOS,variant=Mac Catalyst" -configuration Debug
220-
checkresult $? "Xcodebuild Unit Test failed: \"Build MacCatalyst\""
221-
222-
xcodebuild -project "$PROJECT_NAME.xcodeproj" -scheme "$PROJECT_NAME" -testPlan "${PROJECT_NAME}Tests" -destination "platform=macOS,variant=Mac Catalyst" -configuration Debug ONLY_ACTIVE_ARCH=YES test
223-
checkresult $? "Xcodebuild Unit Test failed: \"Test MacCatalyst\""
224-
225-
xcodebuild -project "$PROJECT_NAME.xcodeproj" -scheme "${PROJECT_NAME}Tests" -testPlan "${PROJECT_NAME}Tests" -destination "platform=macOS,variant=Mac Catalyst" -configuration Debug ONLY_ACTIVE_ARCH=YES test
226-
checkresult $? "Xcodebuild Unit Test failed: \"Test MacCatalyst\""
227-
228-
###
229-
230-
xcodebuild -project "$PROJECT_NAME.xcodeproj" -scheme "$PROJECT_NAME macOS" -destination "generic/platform=macOS" -configuration Debug
231-
checkresult $? "Xcodebuild Unit Test failed: \"Build macOS\""
232-
233-
xcodebuild -project "$PROJECT_NAME.xcodeproj" -scheme "$PROJECT_NAME macOS" -testPlan "$PROJECT_NAME macOS Tests" -configuration Debug ONLY_ACTIVE_ARCH=YES test
234-
checkresult $? "Xcodebuild Unit Test failed: \"Test macOS\""
235-
236-
xcodebuild -project "$PROJECT_NAME.xcodeproj" -scheme "$PROJECT_NAME macOS Tests" -testPlan "$PROJECT_NAME macOS Tests" -configuration Debug ONLY_ACTIVE_ARCH=YES test
237-
checkresult $? "Xcodebuild Unit Test failed: \"Test macOS\""
238-
239-
###
240-
241-
xcodebuild -project "$PROJECT_NAME.xcodeproj" -scheme "$PROJECT_NAME tvOS" -destination "generic/platform=tvOS" -configuration Debug
242-
checkresult $? "Xcodebuild Unit Test failed: \"Build tvOS\""
243-
244-
xcodebuild -project "$PROJECT_NAME.xcodeproj" -scheme "$PROJECT_NAME tvOS" -destination "generic/platform=tvOS Simulator" -configuration Debug
245-
checkresult $? "Xcodebuild Unit Test failed: \"Build tvOS Simulator\""
246-
247-
TVOS_SIM="$(xcrun simctl list devices available | grep "Apple TV" | sort -V | head -n 1 | sed -E 's/(.+)[ ]*\([^)]*\)[ ]*\([^)]*\)/\1/' | awk '{$1=$1};1')"
248-
249-
xcodebuild -project "$PROJECT_NAME.xcodeproj" -scheme "$PROJECT_NAME tvOS" -testPlan "$PROJECT_NAME tvOS Tests" -destination "platform=tvOS Simulator,name=$TVOS_SIM" -configuration Debug ONLY_ACTIVE_ARCH=YES test
250-
checkresult $? "Xcodebuild Unit Test failed: \"Test tvOS\""
251-
252-
xcodebuild -project "$PROJECT_NAME.xcodeproj" -scheme "$PROJECT_NAME tvOS Tests" -testPlan "$PROJECT_NAME tvOS Tests" -destination "platform=tvOS Simulator,name=$TVOS_SIM" -configuration Debug ONLY_ACTIVE_ARCH=YES test
253-
checkresult $? "Xcodebuild Unit Test failed: \"Test tvOS\""
254-
255-
###
256-
257-
xcodebuild -project "$PROJECT_NAME.xcodeproj" -scheme "$PROJECT_NAME watchOS" -destination "generic/platform=watchOS" -configuration Debug
258-
checkresult $? "Xcodebuild Unit Test failed: \"Build watchOS\""
259-
260-
xcodebuild -project "$PROJECT_NAME.xcodeproj" -scheme "$PROJECT_NAME watchOS" -destination "generic/platform=watchOS Simulator" -configuration Debug
261-
checkresult $? "Xcodebuild Unit Test failed: \"Build watchOS Simulator\""
262-
263-
WATCHOS_SIM="$(xcrun simctl list devices available | grep "Apple Watch" | sort -rV | head -n 1 | sed -E 's/(.+)[ ]*\([^)]*\)[ ]*\([^)]*\)/\1/' | awk '{$1=$1};1')"
264-
265-
xcodebuild -project "$PROJECT_NAME.xcodeproj" -scheme "$PROJECT_NAME watchOS" -testPlan "$PROJECT_NAME watchOS Tests" -destination "platform=watchOS Simulator,name=$WATCHOS_SIM" -configuration Debug ONLY_ACTIVE_ARCH=YES test
266-
checkresult $? "Xcodebuild Unit Test failed: \"Test watchOS\""
267-
268-
xcodebuild -project "$PROJECT_NAME.xcodeproj" -scheme "$PROJECT_NAME watchOS Tests" -testPlan "$PROJECT_NAME watchOS Tests" -destination "platform=watchOS Simulator,name=$WATCHOS_SIM" -configuration Debug ONLY_ACTIVE_ARCH=YES test
269-
checkresult $? "Xcodebuild Unit Test failed: \"Test watchOS\""
102+
if [ "$NO_CLEAN" == "1" ]; then
103+
ARGS+=(--no-clean)
104+
elif [ "$NO_CLEAN_ON_FAIL" == "1" ]; then
105+
ARGS+=(--no-clean-on-fail)
106+
fi
270107

271-
printstep "'xcodebuild.yml' Workflow Tests Passed\n"
108+
"$OUTPUT_DIR/$(basename "$SCRIPTS_DIR")/workflowtests.sh" "${ARGS[@]}"
109+
checkresult $? "Unit tests failed"
272110

273-
### Success
111+
# Success
274112

275113
cleanup

0 commit comments

Comments
 (0)