Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 76 additions & 0 deletions .github/workflows/native-swift.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# Copyright (c) Meta Platforms, Inc. and affiliates.

# Native Swift: builds and tests every Swift package in @astryxdesign/native
# (AST-082) on macOS, for macOS and the iOS Simulator. The package is
# experimental and canary-only. Its contract drift check runs with the rest of
# the package in the Node tests; this lane is where its Swift compiles and its
# Swift tests run.
name: Native Swift

on:
pull_request:
branches: ['main']
paths:
- 'packages/native/**/*.swift'
- 'packages/native/**/Package.swift'
- '.github/workflows/native-swift.yml'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This pull_request path filter makes the Swift build a separately routed lane. The CI classifier already routes packages/native/** to shared-or-unknown, and AST-030 FR11 says new coverage inside an existing surface must join that owner instead of creating a separately routed lane. Consider running this job from the broad lane in ci.yml, added to the test join, or admitting a native surface through an FR10 amendment first. The push: main trigger below is outside AST-030's scope.

push:
branches: ['main']
paths:
- 'packages/native/**/*.swift'
- 'packages/native/**/Package.swift'
- '.github/workflows/native-swift.yml'

permissions: {}

concurrency:
group: 'native-swift-${{ github.head_ref || github.run_id }}'
cancel-in-progress: true

jobs:
swift:
runs-on: macos-15
timeout-minutes: 30
permissions:
contents: read
steps:
- uses: actions/checkout@v7

- name: Show the toolchain
run: |
xcodebuild -version
swift --version

# One package per directory that holds a Package.swift, such as apple/
# (generated contracts) and each versioned swift-ios-<n>/. A package
# that supports macOS runs its tests there; every package builds for
# the iOS Simulator, and an iOS-only package runs its tests there.
- name: Build and test each package
run: |
set -euo pipefail
packages=$(find packages/native -name Package.swift -not -path '*/.build/*' -not -path '*/node_modules/*' -exec dirname {} \; | sort)
if [ -z "$packages" ]; then
echo 'No Swift package found under packages/native.'
exit 1
fi
for package in $packages; do
echo "::group::$package"
(
cd "$package"
swift package dump-package > "$RUNNER_TEMP/package.json"
read -r macos tests < <(python3 -c 'import json,sys; d=json.load(open(sys.argv[1])); print(any(p["platformName"]=="macos" for p in d.get("platforms",[])) or not d.get("platforms"), any(t["type"]=="test" for t in d["targets"]))' "$RUNNER_TEMP/package.json")
# Xcode names the whole-package scheme <name>-Package when a
# package has several products, and after its product otherwise.
xcodebuild -list -json > "$RUNNER_TEMP/schemes.json"
scheme=$(python3 -c 'import json,sys; s=json.load(open(sys.argv[1]))["workspace"]["schemes"]; print(next((x for x in s if x.endswith("-Package")), s[0]))' "$RUNNER_TEMP/schemes.json")
if [ "$macos" = True ]; then
swift test

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

swift test runs here even when $tests is False. For a package without a test target, SwiftPM stops with error: no tests found, and set -euo pipefail then skips the iOS Simulator build and every later package. Guarding it with [ "$tests" = True ], and running swift build otherwise, avoids that once such a package exists.

xcodebuild build -scheme "$scheme" -destination 'generic/platform=iOS Simulator' -quiet
elif [ "$tests" = True ]; then
xcodebuild test -scheme "$scheme" -destination 'platform=iOS Simulator,name=iPhone 16' -quiet
else
xcodebuild build -scheme "$scheme" -destination 'generic/platform=iOS Simulator' -quiet
fi
)
echo '::endgroup::'
done
Loading