Skip to content

Commit

Permalink
Add swift-syntax 510 support; matrix testing for swift-syntax versions
Browse files Browse the repository at this point in the history
- Implement matrix strategy for macOS job to test against multiple versions of swift-syntax
- Configure SWIFT_SYNTAX_VERSION environment variable to dictate swift-syntax version per test run
- Add explicit dependency resolution step to macOS job to ensure correct versions are used
- Maintain existing setup for Linux CI without changes
  • Loading branch information
gohanlon committed Apr 12, 2024
1 parent 84f14bc commit 36c15be
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 6 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,18 @@ jobs:
macos:
name: macOS
runs-on: macos-13
strategy:
matrix:
swift-syntax-version: ['509.0.0..<510.0.0', '510.0.0..<511.0.0']

steps:
- uses: actions/checkout@v4
- name: Select Xcode 15
run: sudo xcode-select -s /Applications/Xcode_15.0.app
- name: Set SWIFT_SYNTAX_VERSION environment variable
run: echo "SWIFT_SYNTAX_VERSION=${{ matrix.swift-syntax-version }}" >> $GITHUB_ENV
- name: Resolve Dependencies
run: swift package resolve
- name: Run tests
run: swift test

Expand Down
10 changes: 5 additions & 5 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-snapshot-testing",
"state" : {
"revision" : "59b663f68e69f27a87b45de48cb63264b8194605",
"version" : "1.15.1"
"revision" : "625ccca8570773dd84a34ee51a81aa2bc5a4f97a",
"version" : "1.16.0"
}
},
{
"identity" : "swift-syntax",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-syntax.git",
"location" : "https://github.com/apple/swift-syntax",
"state" : {
"revision" : "6ad4ea24b01559dde0773e3d091f1b9e36175036",
"version" : "509.0.2"
"revision" : "fa8f95c2d536d6620cc2f504ebe8a6167c9fc2dd",
"version" : "510.0.1"
}
}
],
Expand Down
35 changes: 34 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// swift-tools-version: 5.9

import CompilerPluginSupport
import Foundation
import PackageDescription

let package = Package(
Expand All @@ -23,7 +24,8 @@ let package = Package(
],
dependencies: [
.package(url: "https://github.com/pointfreeco/swift-snapshot-testing", from: "1.15.0"),
.package(url: "https://github.com/apple/swift-syntax", from: "509.0.0"),
// .conditionalPackage(url: "https://github.com/apple/swift-syntax", envVar: "SWIFT_SYNTAX_VERSION", default: "509.0.0..<510.0.0")
.conditionalPackage(url: "https://github.com/apple/swift-syntax", envVar: "SWIFT_SYNTAX_VERSION", default: "509.0.0..<511.0.0")
],
targets: [
.macro(
Expand Down Expand Up @@ -68,3 +70,34 @@ let package = Package(
),
]
)

extension Package.Dependency {
/// Creates a package dependency based on an environment variable or uses a default version expression.
static func conditionalPackage(url: String, envVar: String, default versionExpression: String) -> Package.Dependency {
let versionRangeString = ProcessInfo.processInfo.environment[envVar] ?? versionExpression
let (lower, op, upper) = parseVersionExpression(from: versionRangeString)
if op == "..<" {
return .package(url: url, lower..<upper)
} else if op == "..." {
return .package(url: url, lower...upper)
} else {
fatalError("Unsupported version range operator: \(op)")
}
}

private static func parseVersionExpression(from expression: String) -> (Version, String, Version) {
let rangeOperators = ["..<", "..."]
for op in rangeOperators {
if expression.contains(op) {
let parts = expression.split(separator: op, maxSplits: 1, omittingEmptySubsequences: true).map(String.init)
guard parts.count == 2,
let lower = Version(parts[0]),
let upper = Version(parts[1]) else {
fatalError("Invalid version expression format: \(expression)")
}
return (lower, op, upper)
}
}
fatalError("No valid range operator found in expression: \(expression)")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,11 @@ extension ExprSyntax {
else { return nil }
return .tuple(elementTypes)

#if canImport(SwiftSyntax510)
case .thenStmt:
return nil
#endif

case .token, .accessorBlock, .accessorDeclList, .accessorDecl, .accessorEffectSpecifiers,
.accessorParameters, .actorDecl, .arrayElementList, .arrayElement, .arrayType, .arrowExpr,
.assignmentExpr, .associatedTypeDecl, .attributeList, .attribute, .attributedType,
Expand Down

0 comments on commit 36c15be

Please sign in to comment.