Skip to content

Commit 004c2f4

Browse files
Haraldgreenrobot
authored andcommitted
Add integration test for Swift Package manager
1 parent 01545dd commit 004c2f4

File tree

5 files changed

+97
-1
lines changed

5 files changed

+97
-1
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,7 @@ Package.resolved
3030

3131
# generated on the fly by test.sh
3232
objectbox-framework-spec.json
33+
34+
# SPM default artifacts
35+
**/.build/
36+
**/Package.resolved

.gitlab-ci.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,17 @@ stages:
1717
# extends: .common
1818
# script:
1919
# - ./test.sh --clean --version "4.3.0-rc3" --staging
20+
spm:
21+
extends: .common
22+
script:
23+
- ./test.sh --clean --spm
24+
25+
latest:
26+
extends: .common
27+
script:
28+
- ./test.sh
29+
- ./test.sh --clean -v 4.0.1
30+
- ./test.sh --clean -v 4.0.1-sync
2031

2132
cocoapods-latest:
2233
extends: .common

IntTestiOSRegular/Package.swift

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// swift-tools-version:5.9
2+
import PackageDescription
3+
import Foundation
4+
5+
let packageURL: String
6+
if let envURL = ProcessInfo.processInfo.environment["OBX_SPM_PACKAGE_REPO"] {
7+
packageURL = envURL
8+
} else {
9+
packageURL = "https://github.com/objectbox/objectbox-swift-spm"
10+
}
11+
let packageBranch: String
12+
if let envURL = ProcessInfo.processInfo.environment["OBX_SPM_PACKAGE_BRANCH"] {
13+
packageBranch = envURL
14+
} else {
15+
packageBranch = "main"
16+
}
17+
18+
19+
let package = Package(
20+
name: "YourPackageName",
21+
defaultLocalization: "en", // Set the default localization
22+
platforms: [
23+
.macOS(.v12)
24+
],
25+
dependencies: [
26+
.package(url: packageURL, branch: packageBranch)
27+
],
28+
targets: [
29+
.target(
30+
name: "IntTestiOSRegular",
31+
dependencies: [
32+
.product(name: "ObjectBox.xcframework", package: "objectbox-swift-spm")
33+
],
34+
path: "./IntTestiOSRegular",
35+
exclude: [
36+
"AppDelegate.swift",
37+
"ViewController.swift",
38+
"Assets.xcassets",
39+
"Info.plist"
40+
]
41+
),
42+
.testTarget(
43+
name: "IntTestiOSRegularTest",
44+
dependencies: ["IntTestiOSRegular"],
45+
path: "./IntTestiOSRegularTests"
46+
)
47+
]
48+
)

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,20 @@ Does something like 'git clean -fdx && git reset --hard'
4646
(this creates a local Cartfile pointing to the URL)
4747
```
4848

49+
#### SPM test
50+
51+
This is also the project which has a Package.swift file, which makes it eligible for the spm test.
52+
53+
To run the swift test, run `test.sh --clean --spm`
54+
55+
There are 2 environment variables for the configuration
56+
57+
- OBX_SPM_PACKAGE_REPO
58+
- OBX_SPM_PACKAGE_BRANCH
59+
60+
Per default, these point to the public github repository and the main branch.
61+
To re-point the to a custom developer repository / branch, set them accordantly.
62+
4963
What is this doing?
5064
-------------------
5165
The process for each project is like this:

test.sh

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ do_clean=""
1111
use_carthage=""
1212
use_staging=""
1313
framework=""
14+
swift_spm=""
1415

1516
skip_project=""
1617
carthage_bin="carthage"
@@ -32,6 +33,7 @@ while [ $# -ge 1 ]; do
3233
echo " --skip: specify a project to skip"
3334
echo " --framework: specify a HTTPS URL to an uploaded framework to be tested"
3435
echo " (this creates a local Cartfile pointing to the URL)"
36+
echo " --spm Run Swift Package tests"
3537
exit 0
3638
;;
3739
-v|--version)
@@ -67,6 +69,9 @@ while [ $# -ge 1 ]; do
6769
shift
6870
skip_project="$1"
6971
;;
72+
--spm)
73+
swift_spm="true"
74+
;;
7075
*) break # Assuming project comes next, stop parsing here
7176
;;
7277
esac
@@ -96,6 +101,20 @@ if [ -n "$do_clean" ]; then
96101
git reset --hard
97102
fi
98103

104+
if [ -n "${swift_spm}" ]; then
105+
echo "Running Swift Package tests only"
106+
(
107+
cd IntTestiOSRegular
108+
swift package reset
109+
swift package purge-cache
110+
swift package update
111+
swift package plugin --allow-writing-to-package-directory objectbox-generator --target IntTestiOSRegular
112+
swift build
113+
swift test
114+
)
115+
exit 0
116+
fi
117+
99118
if [ -n "$framework" ]; then
100119
source="$script_dir/objectbox-framework-spec.json"
101120
if [ -z "$version" ]; then # didn't work without a version
@@ -283,6 +302,6 @@ fi # End CocoaPods
283302

284303
xcodebuild clean build "${options[@]}"
285304

286-
if [ -d "${project}Tests" ]; then
305+
if [ -d "${project}Tests" ]; then
287306
xcodebuild test "${options[@]}" -destination 'platform=iOS Simulator,name=iPhone 11'
288307
fi

0 commit comments

Comments
 (0)
close