Build Automation
Automating builds using the ProjectAutomation framework.Overview
The ProjectAutomation framework allows you to programmatically access project structure and automate build processes. This is useful for creating custom CI/CD pipelines, build scripts, and development tools.Loading the Project Graph
The foundation of build automation is loading the project graph:Tuist.graph() Method
String?
default:"nil"
The path at which the graph should be loaded. If
nil, the current directory is used.Graph
Returns the loaded graph containing all projects, targets, and schemes.
Graph Structure
The returnedGraph object contains:
String
The name of the workspace or project.
String
The absolute path to the workspace or project.
[Project]
An array of all projects in the graph.
Project Structure
EachProject in the graph has:
String
The name of the project.
String
The absolute path of the project.
Bool
Indicates whether the project is imported through
Package.swift.[Package]
The Swift packages that this project depends on.
[Target]
The targets this project produces.
[Scheme]
The schemes available to this project.
Target Structure
EachTarget contains:
String
The name of the target.
String
The product type the target produces (e.g., “app”, “framework”, “unit_tests”).
String
The bundle identifier of the target.
[String]
List of file paths that are the target’s sources.
[String]
List of file paths that are the target’s resources.
Settings
The target’s build settings.
[TargetDependency]
The target’s dependencies.
Example: Building All Apps
Example: Conditional Building
Build only specific targets based on criteria:Example: Build Order Analysis
Analyze and determine build order based on dependencies:Example: CI/CD Integration
Integrate with CI/CD systems:Best Practices
- Error Handling: Always handle potential errors when loading the graph or building targets.
- Parallel Builds: Consider building independent targets in parallel for faster execution.
- Configuration: Use environment variables for configuration options (build configuration, platform, etc.).
- Logging: Provide clear logging for build progress and results.
- Validation: Validate the graph structure before attempting builds.
Related APIs
- ProjectAutomation Overview - Framework overview
- Test Automation - Test automation
- Project API - Project manifest definition