Skip to content

Commit

Permalink
Merge pull request #190 from ably/build-in-release-in-CI
Browse files Browse the repository at this point in the history
[ECO-5003] Check that the library builds in `release` configuration
  • Loading branch information
lawrence-forooghian authored Dec 10, 2024
2 parents b436fe5 + 5cac167 commit 9c1e4b1
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 5 deletions.
49 changes: 45 additions & 4 deletions .github/workflows/check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ jobs:
- id: generation-step
run: swift run BuildTool generate-matrices >> $GITHUB_OUTPUT

check-spm:
build-and-test-spm:
name: SPM (Xcode ${{ matrix.tooling.xcodeVersion }})
runs-on: macos-15
needs: generate-matrices
Expand All @@ -94,7 +94,26 @@ jobs:
- run: swift build -Xswiftc -warnings-as-errors
- run: swift test -Xswiftc -warnings-as-errors

check-xcode:
build-release-configuration-spm:
name: SPM, `release` configuration (Xcode ${{ matrix.tooling.xcodeVersion }})
runs-on: macos-15
needs: generate-matrices
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.generate-matrices.outputs.matrix).withoutPlatform }}

steps:
- uses: actions/checkout@v4
with:
submodules: true
- uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: ${{ matrix.tooling.xcodeVersion }}

# https://forums.swift.org/t/warnings-as-errors-for-libraries-frameworks/58393/2
- run: swift build -Xswiftc -warnings-as-errors --configuration release

build-and-test-xcode:
name: Xcode, ${{matrix.platform}} (Xcode ${{ matrix.tooling.xcodeVersion }})
runs-on: macos-15
needs: generate-matrices
Expand All @@ -119,6 +138,26 @@ jobs:
- name: Run tests
run: swift run BuildTool test-library --platform ${{ matrix.platform }}

build-release-configuration-xcode:
name: Xcode, `release` configuration, ${{matrix.platform}} (Xcode ${{ matrix.tooling.xcodeVersion }})
runs-on: macos-15
needs: generate-matrices

strategy:
fail-fast: false
matrix: ${{ fromJson(needs.generate-matrices.outputs.matrix).withPlatform }}

steps:
- uses: actions/checkout@v4
with:
submodules: true
- uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: ${{ matrix.tooling.xcodeVersion }}

- name: Build library
run: swift run BuildTool build-library --platform ${{ matrix.platform }} --configuration release

check-example-app:
name: Example app, ${{matrix.platform}} (Xcode ${{ matrix.tooling.xcodeVersion }})
runs-on: macos-15
Expand Down Expand Up @@ -149,8 +188,10 @@ jobs:
needs:
- lint
- spec-coverage
- check-spm
- check-xcode
- build-and-test-spm
- build-release-configuration-spm
- build-and-test-xcode
- build-release-configuration-xcode
- check-example-app

steps:
Expand Down
18 changes: 18 additions & 0 deletions Sources/BuildTool/BuildTool.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import Table
struct BuildTool: AsyncParsableCommand {
static let configuration = CommandConfiguration(
subcommands: [
BuildLibrary.self,
BuildLibraryForTesting.self,
TestLibrary.self,
BuildExampleApp.self,
Expand All @@ -18,6 +19,23 @@ struct BuildTool: AsyncParsableCommand {
)
}

@available(macOS 14, *)
struct BuildLibrary: AsyncParsableCommand {
static let configuration = CommandConfiguration(
abstract: "Build the AblyChat library"
)

@Option var configuration: Configuration?
@Option var platform: Platform

mutating func run() async throws {
let destinationSpecifier = try await platform.resolve()
let scheme = "AblyChat"

try await XcodeRunner.runXcodebuild(action: "build", configuration: configuration, scheme: scheme, destination: destinationSpecifier)
}
}

@available(macOS 14, *)
struct BuildLibraryForTesting: AsyncParsableCommand {
static let configuration = CommandConfiguration(
Expand Down
12 changes: 12 additions & 0 deletions Sources/BuildTool/Configuration.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import ArgumentParser

enum Configuration: String, CaseIterable {
case debug
case release
}

extension Configuration: ExpressibleByArgument {
init?(argument: String) {
self.init(rawValue: argument)
}
}
6 changes: 5 additions & 1 deletion Sources/BuildTool/XcodeRunner.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@ import Foundation

@available(macOS 14, *)
enum XcodeRunner {
static func runXcodebuild(action: String?, scheme: String, destination: DestinationSpecifier) async throws {
static func runXcodebuild(action: String?, configuration: Configuration? = nil, scheme: String, destination: DestinationSpecifier) async throws {
var arguments: [String] = []

if let action {
arguments.append(action)
}

if let configuration {
arguments.append(contentsOf: ["-configuration", configuration.rawValue])
}

arguments.append(contentsOf: ["-scheme", scheme])
arguments.append(contentsOf: ["-destination", destination.xcodebuildArgument])

Expand Down

0 comments on commit 9c1e4b1

Please sign in to comment.