Skip to content

Commit

Permalink
Check that the library builds in release configuration
Browse files Browse the repository at this point in the history
To catch anything that's incorrectly gated behind an `#if DEBUG`, for
example.

Resolves #68.
  • Loading branch information
lawrence-forooghian committed Dec 10, 2024
1 parent b436fe5 commit c6223a5
Show file tree
Hide file tree
Showing 3 changed files with 68 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: String?
@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
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: String? = nil, scheme: String, destination: DestinationSpecifier) async throws {
var arguments: [String] = []

if let action {
arguments.append(action)
}

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

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

Expand Down

0 comments on commit c6223a5

Please sign in to comment.