From 61ca1fbdaf90dc84e08f6adeea5a5aea0e68ba93 Mon Sep 17 00:00:00 2001 From: Lawrence Forooghian Date: Mon, 5 Aug 2024 13:06:06 +0100 Subject: [PATCH] try generating matrices --- .github/workflows/check.yaml | 36 ++++++++++++++----------------- Sources/BuildTool/BuildTool.swift | 30 +++++++++++++++++++++++++- 2 files changed, 45 insertions(+), 21 deletions(-) diff --git a/.github/workflows/check.yaml b/.github/workflows/check.yaml index 7b891cf9..613b08e1 100644 --- a/.github/workflows/check.yaml +++ b/.github/workflows/check.yaml @@ -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 @@ -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 @@ -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 diff --git a/Sources/BuildTool/BuildTool.swift b/Sources/BuildTool/BuildTool.swift index 9c219b38..e9ed410b 100644 --- a/Sources/BuildTool/BuildTool.swift +++ b/Sources/BuildTool/BuildTool.swift @@ -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? @@ -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