Skip to content

Commit

Permalink
Support for visionOS and watchOS-based Swift Packages (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
PSchmiedmayer authored Jul 30, 2023
1 parent 38af224 commit 1b116ed
Show file tree
Hide file tree
Showing 11 changed files with 652 additions and 56 deletions.
49 changes: 41 additions & 8 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,57 @@ on:
workflow_dispatch:

jobs:
buildandtest:
name: Build and Test Swift Package
packageios:
name: Build and Test Swift Package iOS
uses: StanfordBDHG/.github/.github/workflows/xcodebuild-or-fastlane.yml@v2
with:
scheme: TemplatePackage
artifactname: TemplatePackage.xcresult
runsonlabels: '["macOS", "self-hosted"]'
packagewatchos:
name: Build and Test Swift Package watchOS
uses: StanfordBDHG/.github/.github/workflows/xcodebuild-or-fastlane.yml@v2
with:
scheme: TemplatePackage
buildandtestuitests:
name: Build and Test UI Tests
resultBundle: TemplatePackageWatchOS.xcresult
destination: 'platform=watchOS Simulator,name=Apple Watch Series 8 (45mm)'
artifactname: TemplatePackageWatchOS.xcresult
packagevisionos:
name: Build and Test Swift Package visionOS
uses: StanfordBDHG/.github/.github/workflows/xcodebuild-or-fastlane.yml@v2
with:
xcodeversion: latest
scheme: TemplatePackage
resultBundle: TemplatePackageVisionOS.xcresult
destination: 'platform=visionOS Simulator,name=Apple Vision Pro'
artifactname: TemplatePackageVisionOS.xcresult
ios:
name: Build and Test iOS
uses: StanfordBDHG/.github/.github/workflows/xcodebuild-or-fastlane.yml@v2
with:
path: 'Tests/UITests'
scheme: TestApp
artifactname: TestApp.xcresult
runsonlabels: '["macOS", "self-hosted"]'
ipados:
name: Build and Test iPadOS
uses: StanfordBDHG/.github/.github/workflows/xcodebuild-or-fastlane.yml@v2
with:
path: 'Tests/UITests'
scheme: TestApp
resultBundle: TestAppiPadOS.xcresult
destination: 'platform=iOS Simulator,name=iPad mini (6th generation)'
artifactname: TestAppiPadOS.xcresult
watchos:
name: Build and Test watchOS
uses: StanfordBDHG/.github/.github/workflows/xcodebuild-or-fastlane.yml@v2
with:
path: 'Tests/UITests'
scheme: TestAppWatchApp
resultBundle: TestAppWatchApp.xcresult
destination: 'platform=watchOS Simulator,name=Apple Watch Series 8 (45mm)'
artifactname: TestAppWatchApp.xcresult
uploadcoveragereport:
name: Upload Coverage Report
needs: [buildandtest, buildandtestuitests]
needs: [packageios, packagewatchos, packagevisionos, ios, ipados, watchos]
uses: StanfordBDHG/.github/.github/workflows/create-and-upload-coverage-report.yml@v2
with:
coveragereports: TemplatePackage.xcresult TestApp.xcresult
coveragereports: TemplatePackage.xcresult TemplatePackageWatchOS.xcresult TemplatePackageVisionOS.xcresult TestApp.xcresult TestAppiPadOS.xcresult TestAppWatchApp.xcresult
9 changes: 5 additions & 4 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,6 @@ only_rules:
- implicitly_unwrapped_optional
# Identifiers should use inclusive language that avoids discrimination against groups of people based on race, gender, or socioeconomic status
- inclusive_language
# If defer is at the end of its parent scope, it will be executed right where it is anyway.
- inert_defer
# Prefer using Set.isDisjoint(with:) over Set.intersection(_:).isEmpty.
- is_disjoint
# Discouraged explicit usage of the default separator.
Expand Down Expand Up @@ -329,8 +327,6 @@ only_rules:
- unowned_variable_capture
# Catch statements should not declare error variables without type casting.
- untyped_error_in_catch
# Unused reference in a capture list should be removed.
- unused_capture_list
# Unused parameter in a closure should be replaced with _.
- unused_closure_parameter
# Unused control flow label should be removed.
Expand Down Expand Up @@ -371,13 +367,18 @@ only_rules:
# The variable should be placed on the left, the constant on the right of a comparison operator.
- yoda_condition

attributes:
attributes_with_arguments_always_on_line_above: false

deployment_target: # Availability checks or attributes shouldn’t be using older versions that are satisfied by the deployment target.
iOSApplicationExtension_deployment_target: 16.0
iOS_deployment_target: 16.0

excluded: # paths to ignore during linting. Takes precedence over `included`.
- .build
- .swiftpm
- .derivedData
- Tests/UITests/.derivedData

closure_body_length: # Closure bodies should not span too many lines.
- 35 # warning - default: 20
Expand Down
5 changes: 3 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.7
// swift-tools-version:5.8

//
// This source file is part of the TemplatePackage open source project
Expand All @@ -14,7 +14,8 @@ import PackageDescription
let package = Package(
name: "TemplatePackage",
platforms: [
.iOS(.v16)
.iOS(.v16),
.watchOS(.v9)
],
products: [
.library(name: "TemplatePackage", targets: ["TemplatePackage"])
Expand Down
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,19 @@ SPDX-License-Identifier: MIT

## How To Use This Template

The template repository contains a template Swift Package, including a continuous integration setup. Follow these steps to customize it to your needs:
The template repository contains a template Swift Package, including a continuous integration setup.

Follow these steps to customize it to your needs:
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`.
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.
3. If your Swift Package uses UI test, you need to ...
- ... 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".
- ... 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*).
- ... 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*).
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.
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.
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.
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.
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).
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).


## Installation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
"idiom" : "universal",
"platform" : "ios",
"size" : "1024x1024"
},
{
"idiom" : "universal",
"platform" : "watchos",
"size" : "1024x1024"
}
],
"info" : {
Expand Down
37 changes: 37 additions & 0 deletions Tests/UITests/TestAppWatchApp.xctestplan
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"configurations" : [
{
"id" : "B8537494-39D3-45EC-98D4-B3C417844ADD",
"name" : "Default",
"options" : {

}
}
],
"defaultOptions" : {
"codeCoverage" : {
"targets" : [
{
"containerPath" : "container:..\/..",
"identifier" : "TemplatePackage",
"name" : "TemplatePackage"
}
]
},
"targetForVariableExpansion" : {
"containerPath" : "container:UITests.xcodeproj",
"identifier" : "2F9CBEA52A76C40E009818FF",
"name" : "TestAppWatchApp"
}
},
"testTargets" : [
{
"target" : {
"containerPath" : "container:UITests.xcodeproj",
"identifier" : "2F9CBEBE2A76C412009818FF",
"name" : "TestAppWatchAppUITests"
}
}
],
"version" : 1
}
5 changes: 5 additions & 0 deletions Tests/UITests/TestAppWatchApp.xctestplan.license
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
This source file is part of the TemplatePackage open-source project

SPDX-FileCopyrightText: 2022 Stanford University and the project authors (see CONTRIBUTORS.md)

SPDX-License-Identifier: MIT
Loading

0 comments on commit 1b116ed

Please sign in to comment.