Skip to content

Commit

Permalink
try generating matrices
Browse files Browse the repository at this point in the history
  • Loading branch information
lawrence-forooghian committed Aug 5, 2024
1 parent 9b901ac commit 61ca1fb
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 21 deletions.
36 changes: 16 additions & 20 deletions .github/workflows/check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,23 @@ jobs:
- run: script/format/check
- run: script/lint/check

generate-matrices:
runs-on: macos-latest
outputs:
matrix: ${{ steps.generation-step.outputs.matrix }}
steps:
- uses: actions/checkout@v4
- id: generation-step
run: swift run BuildTool generate-matrices

check-spm:
name: SPM (Xcode ${{ matrix.tooling.xcode-version }}, Swift ${{ matrix.tooling.swift-version }})
runs-on: macos-latest
needs: generate-matrices
strategy:
fail-fast: false
matrix:
tooling:
- xcode-version: 15.3
swift-version: 5
- xcode-version: 16-beta
swift-version: 6
matrix: ${{ fromJson(needs.generate-matrices.outputs.matrix) }}

steps:
- uses: actions/checkout@v4
- uses: maxim-lobanov/setup-xcode@v1
Expand All @@ -57,16 +63,11 @@ jobs:
check-xcode:
name: Library, ${{matrix.platform}} (Xcode ${{ matrix.tooling.xcode-version }}, Swift ${{ matrix.tooling.swift-version }})
runs-on: macos-latest
needs: generate-matrices

strategy:
fail-fast: false
matrix:
tooling:
- xcode-version: 15.3
swift-version: 5
- xcode-version: 16-beta
swift-version: 6
platform: [macOS, iOS, tvOS]
matrix: ${{ fromJson(needs.generate-matrices.outputs.matrix) }}

steps:
- uses: actions/checkout@v4
Expand All @@ -80,16 +81,11 @@ jobs:
check-example-app:
name: Example app, ${{matrix.platform}} (Xcode ${{ matrix.tooling.xcode-version }}, Swift ${{ matrix.tooling.swift-version }})
runs-on: macos-latest
needs: generate-matrices

strategy:
fail-fast: false
matrix:
tooling:
- xcode-version: 15.3
swift-version: 5
- xcode-version: 16-beta
swift-version: 6
platform: [macOS, iOS, tvOS]
matrix: ${{ fromJson(needs.generate-matrices.outputs.matrix) }}

steps:
- uses: actions/checkout@v4
Expand Down
30 changes: 29 additions & 1 deletion Sources/BuildTool/BuildTool.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,13 @@ enum Error: Swift.Error {
@main
@available(macOS 14, *)
struct BuildTool: ParsableCommand {
static let configuration = CommandConfiguration(subcommands: [BuildAndTestLibrary.self, BuildExampleApp.self])
static let configuration = CommandConfiguration(
subcommands: [
BuildAndTestLibrary.self,
BuildExampleApp.self,
GenerateMatrices.self,
]
)
}

// TODO: Is there a better way to make sure that this script has access to macOS APIs that are more recent than the package’s deployment target?
Expand All @@ -91,6 +97,28 @@ struct BuildAndTestLibrary: ParsableCommand {
}
}

struct GenerateMatrices: ParsableCommand {
mutating func run() throws {
let matrix: [String: Any] = [
"tooling": [
[
"xcode-version": "15.3",
"swift-version": 5,
],
[
"xcode-version": "16-beta",
"swift-version": 6,
],
],
"platforms": Platform.allCases.map(\.rawValue),
]

// I’m assuming the JSONSerialization output has no newlines
let keyValue = try "matrix=\(String(decoding: JSONSerialization.data(withJSONObject: matrix), as: UTF8.self))"
print(keyValue)
}
}

@available(macOS 14, *)
struct BuildExampleApp: ParsableCommand {
@Option var platform: Platform
Expand Down

0 comments on commit 61ca1fb

Please sign in to comment.