Skip to content

Commit 1b116ed

Browse files
Support for visionOS and watchOS-based Swift Packages (#12)
1 parent 38af224 commit 1b116ed

File tree

11 files changed

+652
-56
lines changed

11 files changed

+652
-56
lines changed

.github/workflows/build-and-test.yml

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,57 @@ on:
1616
workflow_dispatch:
1717

1818
jobs:
19-
buildandtest:
20-
name: Build and Test Swift Package
19+
packageios:
20+
name: Build and Test Swift Package iOS
2121
uses: StanfordBDHG/.github/.github/workflows/xcodebuild-or-fastlane.yml@v2
2222
with:
23+
scheme: TemplatePackage
2324
artifactname: TemplatePackage.xcresult
24-
runsonlabels: '["macOS", "self-hosted"]'
25+
packagewatchos:
26+
name: Build and Test Swift Package watchOS
27+
uses: StanfordBDHG/.github/.github/workflows/xcodebuild-or-fastlane.yml@v2
28+
with:
2529
scheme: TemplatePackage
26-
buildandtestuitests:
27-
name: Build and Test UI Tests
30+
resultBundle: TemplatePackageWatchOS.xcresult
31+
destination: 'platform=watchOS Simulator,name=Apple Watch Series 8 (45mm)'
32+
artifactname: TemplatePackageWatchOS.xcresult
33+
packagevisionos:
34+
name: Build and Test Swift Package visionOS
2835
uses: StanfordBDHG/.github/.github/workflows/xcodebuild-or-fastlane.yml@v2
2936
with:
37+
xcodeversion: latest
38+
scheme: TemplatePackage
39+
resultBundle: TemplatePackageVisionOS.xcresult
40+
destination: 'platform=visionOS Simulator,name=Apple Vision Pro'
41+
artifactname: TemplatePackageVisionOS.xcresult
42+
ios:
43+
name: Build and Test iOS
44+
uses: StanfordBDHG/.github/.github/workflows/xcodebuild-or-fastlane.yml@v2
45+
with:
46+
path: 'Tests/UITests'
47+
scheme: TestApp
3048
artifactname: TestApp.xcresult
31-
runsonlabels: '["macOS", "self-hosted"]'
49+
ipados:
50+
name: Build and Test iPadOS
51+
uses: StanfordBDHG/.github/.github/workflows/xcodebuild-or-fastlane.yml@v2
52+
with:
3253
path: 'Tests/UITests'
3354
scheme: TestApp
55+
resultBundle: TestAppiPadOS.xcresult
56+
destination: 'platform=iOS Simulator,name=iPad mini (6th generation)'
57+
artifactname: TestAppiPadOS.xcresult
58+
watchos:
59+
name: Build and Test watchOS
60+
uses: StanfordBDHG/.github/.github/workflows/xcodebuild-or-fastlane.yml@v2
61+
with:
62+
path: 'Tests/UITests'
63+
scheme: TestAppWatchApp
64+
resultBundle: TestAppWatchApp.xcresult
65+
destination: 'platform=watchOS Simulator,name=Apple Watch Series 8 (45mm)'
66+
artifactname: TestAppWatchApp.xcresult
3467
uploadcoveragereport:
3568
name: Upload Coverage Report
36-
needs: [buildandtest, buildandtestuitests]
69+
needs: [packageios, packagewatchos, packagevisionos, ios, ipados, watchos]
3770
uses: StanfordBDHG/.github/.github/workflows/create-and-upload-coverage-report.yml@v2
3871
with:
39-
coveragereports: TemplatePackage.xcresult TestApp.xcresult
72+
coveragereports: TemplatePackage.xcresult TemplatePackageWatchOS.xcresult TemplatePackageVisionOS.xcresult TestApp.xcresult TestAppiPadOS.xcresult TestAppWatchApp.xcresult

.swiftlint.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,6 @@ only_rules:
141141
- implicitly_unwrapped_optional
142142
# Identifiers should use inclusive language that avoids discrimination against groups of people based on race, gender, or socioeconomic status
143143
- inclusive_language
144-
# If defer is at the end of its parent scope, it will be executed right where it is anyway.
145-
- inert_defer
146144
# Prefer using Set.isDisjoint(with:) over Set.intersection(_:).isEmpty.
147145
- is_disjoint
148146
# Discouraged explicit usage of the default separator.
@@ -329,8 +327,6 @@ only_rules:
329327
- unowned_variable_capture
330328
# Catch statements should not declare error variables without type casting.
331329
- untyped_error_in_catch
332-
# Unused reference in a capture list should be removed.
333-
- unused_capture_list
334330
# Unused parameter in a closure should be replaced with _.
335331
- unused_closure_parameter
336332
# Unused control flow label should be removed.
@@ -371,13 +367,18 @@ only_rules:
371367
# The variable should be placed on the left, the constant on the right of a comparison operator.
372368
- yoda_condition
373369

370+
attributes:
371+
attributes_with_arguments_always_on_line_above: false
372+
374373
deployment_target: # Availability checks or attributes shouldn’t be using older versions that are satisfied by the deployment target.
375374
iOSApplicationExtension_deployment_target: 16.0
376375
iOS_deployment_target: 16.0
377376

378377
excluded: # paths to ignore during linting. Takes precedence over `included`.
379378
- .build
380379
- .swiftpm
380+
- .derivedData
381+
- Tests/UITests/.derivedData
381382

382383
closure_body_length: # Closure bodies should not span too many lines.
383384
- 35 # warning - default: 20

Package.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version:5.7
1+
// swift-tools-version:5.8
22

33
//
44
// This source file is part of the TemplatePackage open source project
@@ -14,7 +14,8 @@ import PackageDescription
1414
let package = Package(
1515
name: "TemplatePackage",
1616
platforms: [
17-
.iOS(.v16)
17+
.iOS(.v16),
18+
.watchOS(.v9)
1819
],
1920
products: [
2021
.library(name: "TemplatePackage", targets: ["TemplatePackage"])

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,19 @@ SPDX-License-Identifier: MIT
1919

2020
## How To Use This Template
2121

22-
The template repository contains a template Swift Package, including a continuous integration setup. Follow these steps to customize it to your needs:
22+
The template repository contains a template Swift Package, including a continuous integration setup.
23+
24+
Follow these steps to customize it to your needs:
2325
1. Rename the Swift Package. Be sure that you update the name in the `build-and-test.yml` GitHub Action accordingly. If you have multiple targets in your Swift Package, you need to pass the name of the Swift Package followed by an `-Package` as the scheme to the GitHub Action, e.g., `StanfordProject-Package` if your Swift Package is named `StanfordProject`.
2426
2. If your Swift Package does not provide any user interface or does not require an iOS application environment to function, you can remove the `UITests` application from the `Tests` folder. You need to update the `build-and-test.yml` GitHub Action accordingly by removing the GitHub Action that builds and tests the application, removing the dependency from the code coverage upload step, and removing the UI test `.xresult` input from the code coverage test.
2527
3. If your Swift Package uses UI test, you need to ...
2628
- ... add it to the scheme editor (*Scheme > Edit Scheme*) and your targets to the "Build" configuration and ensure that it is built before the test app target when building for the "Test" configuration. It is not required to enable building for other configurations like "Analyze", "Run", "Profile", or "Archive".
2729
- ... add it as a linked framework in the main target configuration (In your Xcode project settings, select your *test app target > General > Frameworks, Libraries, and Embedded Comments*).
2830
- ... add ensure that the targets are all added in the code coverage settings of your .xctestplan file in the Xcode Project (*Shared Settings > Code Coverage > Code Coverage*).
2931
4. You will either need to add the [CodeCov GitHub App](https://github.com/apps/codecov) or add a codecov.io token to your [GitHub Actions Secrets](https://docs.github.com/en/actions/security-guides/encrypted-secrets#creating-encrypted-secrets-for-an-environment) following the instructions of the [Codecov GitHub Action](https://github.com/marketplace/actions/codecov#usage). The StanfordBDHG organization already has the [CodeCov GitHub App](https://github.com/apps/codecov) installed. If you do not want to cover test coverage data, you can remove the code coverage job in the `build-and-test.yml` GitHub Action.
30-
5. Adjust this README to describe your project and adjust the badges at the top to point to the correct GitHub Action of your repository and Codecov badge.
32+
5. Adjust this README.md to describe your project and adjust the badges at the top to point to the correct GitHub Action of your repository and Codecov badge.
3133
6. The Swift Package template includes a Swift Package Index configuration file to automatically build the package and [host the documentation on the Swift Package Index website](https://blog.swiftpackageindex.com/posts/auto-generating-auto-hosting-and-auto-updating-docc-documentation/). Adjust the `.spi.yml` file to include all targets that you want to build documentation for. You can follow the [instructions of the Swift Package Index](https://swiftpackageindex.com/add-a-package) to include your Swift Package in the Swift Package Index. You can link to the [API documentation](https://swiftpackageindex.com/StanfordBDHG/SwiftPackageTemplate/documentation) from your README file.
32-
7. Adjust the CITATION.cff file to admend information about the new Swift Package ([learn more about CITATION files on GitHub](https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/about-citation-files)) and [register the Swift Package on Zenodo](https://docs.github.com/en/repositories/archiving-a-github-repository/referencing-and-citing-content).
34+
7. Adjust the CITATION.cff file to amend information about the new Swift Package ([learn more about CITATION files on GitHub](https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/about-citation-files)) and [register the Swift Package on Zenodo](https://docs.github.com/en/repositories/archiving-a-github-repository/referencing-and-citing-content).
3335

3436

3537
## Installation

Tests/UITests/TestApp/Assets.xcassets/AppIcon.appiconset/Contents.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
"idiom" : "universal",
55
"platform" : "ios",
66
"size" : "1024x1024"
7+
},
8+
{
9+
"idiom" : "universal",
10+
"platform" : "watchos",
11+
"size" : "1024x1024"
712
}
813
],
914
"info" : {
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"configurations" : [
3+
{
4+
"id" : "B8537494-39D3-45EC-98D4-B3C417844ADD",
5+
"name" : "Default",
6+
"options" : {
7+
8+
}
9+
}
10+
],
11+
"defaultOptions" : {
12+
"codeCoverage" : {
13+
"targets" : [
14+
{
15+
"containerPath" : "container:..\/..",
16+
"identifier" : "TemplatePackage",
17+
"name" : "TemplatePackage"
18+
}
19+
]
20+
},
21+
"targetForVariableExpansion" : {
22+
"containerPath" : "container:UITests.xcodeproj",
23+
"identifier" : "2F9CBEA52A76C40E009818FF",
24+
"name" : "TestAppWatchApp"
25+
}
26+
},
27+
"testTargets" : [
28+
{
29+
"target" : {
30+
"containerPath" : "container:UITests.xcodeproj",
31+
"identifier" : "2F9CBEBE2A76C412009818FF",
32+
"name" : "TestAppWatchAppUITests"
33+
}
34+
}
35+
],
36+
"version" : 1
37+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
This source file is part of the TemplatePackage open-source project
2+
3+
SPDX-FileCopyrightText: 2022 Stanford University and the project authors (see CONTRIBUTORS.md)
4+
5+
SPDX-License-Identifier: MIT

0 commit comments

Comments
 (0)