Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support to declare actions for which a target should be built #48

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 56 additions & 35 deletions .github/workflows/XcodeGraph.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ name: XcodeGraph
on:
push:
branches:
- '**'
- "**"
tags-ignore:
- '**'
- "**"
paths:
- '**/*.swift'
- '.github/workflows/*.yml'
- "**/*.swift"
- ".github/workflows/*.yml"
pull_request:
paths:
- '**/*.swift'
- '.github/workflows/*.yml'
- "**/*.swift"
- ".github/workflows/*.yml"

concurrency:
group: XcodeGraph-${{ github.workflow }}-${{ github.ref }}
Expand All @@ -30,43 +30,43 @@ jobs:
- ubuntu-22.04
- macOS-13
swift-version:
- '5.9'
- "5.9"
swift-compat-ver:
- '5'
- "5"
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- uses: SwiftyLab/setup-swift@latest
with:
swift-version: ${{ matrix.swift-version }}
# DEBUG mode
- name: Build with debug mode.
id: debug_build
run: swift build --configuration debug -Xswiftc -swift-version -Xswiftc ${{ matrix.swift-compat-ver }}
continue-on-error: true
- name: Retry build with debug mode if necessary
if: steps.debug_build.outcome == 'failure'
run: |
swift build --configuration debug -Xswiftc -swift-version -Xswiftc ${{ matrix.swift-compat-ver }}
# RELEASE mode
- name: Build with release mode.
id: release_build
run: swift build --configuration release -Xswiftc -enable-testing -Xswiftc -swift-version -Xswiftc ${{ matrix.swift-compat-ver }}
continue-on-error: true
- name: Retry build with release mode if necessary
if: steps.release_build.outcome == 'failure'
run: |
swift build --configuration release -Xswiftc -swift-version -Xswiftc ${{ matrix.swift-compat-ver }}
- uses: actions/checkout@v4
- uses: SwiftyLab/setup-swift@latest
with:
swift-version: ${{ matrix.swift-version }}
# DEBUG mode
- name: Build with debug mode.
id: debug_build
run: swift build --configuration debug -Xswiftc -swift-version -Xswiftc ${{ matrix.swift-compat-ver }}
continue-on-error: true
- name: Retry build with debug mode if necessary
if: steps.debug_build.outcome == 'failure'
run: |
swift build --configuration debug -Xswiftc -swift-version -Xswiftc ${{ matrix.swift-compat-ver }}
# RELEASE mode
- name: Build with release mode.
id: release_build
run: swift build --configuration release -Xswiftc -enable-testing -Xswiftc -swift-version -Xswiftc ${{ matrix.swift-compat-ver }}
continue-on-error: true
- name: Retry build with release mode if necessary
if: steps.release_build.outcome == 'failure'
run: |
swift build --configuration release -Xswiftc -swift-version -Xswiftc ${{ matrix.swift-compat-ver }}
tuist_build:
name: Tuist Build
strategy:
matrix:
os:
- macOS-13
swift-version:
- '5.9'
- "5.9"
swift-compat-ver:
- '5'
- "5"
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
Expand All @@ -78,16 +78,37 @@ jobs:
run: tuist install
- name: Build
run: tuist build
tuist_test:
name: Tuist Test
strategy:
matrix:
os:
- macOS-13
swift-version:
- "5.9"
swift-compat-ver:
- "5"
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- uses: SwiftyLab/setup-swift@latest
with:
swift-version: ${{ matrix.swift-version }}
- uses: jdx/mise-action@v2
- name: Install dependencies
run: tuist install
- name: Build
run: tuist test
lint:
name: Lint
strategy:
matrix:
os:
- macOS-13
swift-version:
- '5.9'
- "5.9"
swift-compat-ver:
- '5'
- "5"
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
Expand All @@ -96,4 +117,4 @@ jobs:
swift-version: ${{ matrix.swift-version }}
- uses: jdx/mise-action@v2
- name: Lint
run: mise run lint
run: mise run lint
4 changes: 2 additions & 2 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/tuist/Path.git",
"state" : {
"revision" : "e137d6db7a31decd77077613f5c59c745102603e",
"version" : "0.3.5"
"revision" : "bee1e910422f5c817b58dc593c50d747c4637b9c",
"version" : "0.3.6"
}
}
],
Expand Down
49 changes: 46 additions & 3 deletions Sources/XcodeGraph/Models/BuildAction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,56 @@ import Foundation
import Path

public struct BuildAction: Equatable, Codable, Sendable {
/// It represents the reference to a target from a build action, along with the actions when the target
/// should be built.
public struct Target: Equatable, Codable, Sendable {
/// Xcode project actions when a build scheme action can build a target.
public enum BuildFor: Codable, CaseIterable, Sendable {
case running, testing, profiling, archiving, analyzing
}

/// The target reference.
public var reference: TargetReference

/// A list of Xcode actions when a target should build.
public var buildFor: [BuildFor]?

public init(_ reference: TargetReference, buildFor: [BuildFor]? = nil) {
self.reference = reference
self.buildFor = buildFor
}
}

// MARK: - Attributes

public var targets: [TargetReference]
public var targets: [Target]
public var preActions: [ExecutionAction]
public var postActions: [ExecutionAction]
public var runPostActionsOnFailure: Bool

// MARK: - Init

@available(
*, deprecated,
message: "Use the initializer that takes targets as instances of BuildAction.Target"
)
public init(
targets: [TargetReference] = [],
preActions: [ExecutionAction] = [],
postActions: [ExecutionAction] = [],
runPostActionsOnFailure: Bool = false
) {
self.targets = targets.map { Target($0, buildFor: nil) }
self.preActions = preActions
self.postActions = postActions
self.runPostActionsOnFailure = runPostActionsOnFailure
}

public init(
targets: [BuildAction.Target],
preActions: [ExecutionAction] = [],
postActions: [ExecutionAction] = [],
runPostActionsOnFailure: Bool = false
) {
self.targets = targets
self.preActions = preActions
Expand All @@ -25,10 +61,17 @@ public struct BuildAction: Equatable, Codable, Sendable {
}

#if DEBUG
extension BuildAction.Target {
public static func test(
_ reference: TargetReference = TargetReference.test(), buildFor: [BuildFor]? = nil
) -> Self {
return Self(reference, buildFor: buildFor)
}
}

extension BuildAction {
public static func test(
// swiftlint:disable:next force_try
targets: [TargetReference] = [TargetReference(projectPath: try! AbsolutePath(validating: "/Project"), name: "App")],
targets: [BuildAction.Target] = [],
preActions: [ExecutionAction] = [],
postActions: [ExecutionAction] = []
) -> BuildAction {
Expand Down
12 changes: 12 additions & 0 deletions Sources/XcodeGraph/Models/TargetReference.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,15 @@ public struct TargetReference: Hashable, Codable, Sendable {
self.name = name
}
}

#if DEBUG
extension TargetReference {
public static func test(
// swiftlint:disable:next force_try
projectPath: AbsolutePath = try! AbsolutePath(validating: "/Project"),
name: String = "TestTarget"
) -> Self {
return TargetReference(projectPath: projectPath, name: name)
}
}
#endif
2 changes: 1 addition & 1 deletion Sources/XcodeGraph/Models/Workspace.swift
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ extension Workspace {

// having empty `codeCoverageTargets` means that we should gather code coverage for all build targets
if schemeCoverageTargets.isEmpty, let buildAction = scheme.buildAction {
resultTargets.formUnion(buildAction.targets)
resultTargets.formUnion(buildAction.targets.map(\.reference))
} else {
resultTargets.formUnion(schemeCoverageTargets)
}
Expand Down
4 changes: 2 additions & 2 deletions Tests/XcodeGraphTests/Models/BuildActionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ final class BuildActionTests: XCTestCase {
// Given
let subject = BuildAction(
targets: [
.init(
BuildAction.Target(TargetReference(
projectPath: try! AbsolutePath(validating: "/path/to/project"),
name: "name"
),
), buildFor: [.running]),
],
preActions: [
.init(
Expand Down
21 changes: 2 additions & 19 deletions Tests/XcodeGraphTests/Models/TargetTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,8 @@ final class TargetTests: XCTestCase {

func test_validSourceExtensions() {
XCTAssertEqual(
Target.validSourceExtensions,
[
"m",
"swift",
"mm",
"cpp",
"cc",
"c",
"d",
"s",
"intentdefinition",
"xcmappingmodel",
"metal",
"mlmodel",
"docc",
"playground",
"rcproject",
"mlpackage",
]
Target.validSourceExtensions.sorted(),
["c", "cc", "cpp", "d", "intentdefinition", "m", "metal", "mlmodel", "mm", "s", "swift"]
)
}

Expand Down
Loading