# runmacos

> Run a shell script on a cloud macOS builder, with or without the Project's source, and bring back the files you name.

Source: https://air.build/docs/cli/runmacos/

`runmacos` runs one Bash script on a macOS builder with Xcode, from a Team's Environment. It needs no `airbuild.yaml`. Use it for anything the sandbox cannot do on its own: checking the macOS and Xcode versions, running `swift test`, running a macOS app's tools.

It is for **cloud Teams only**. On a Mac Team it stops with `runmacos is only available in cloud Teams; local Teams provide runtest.`

## Synopsis

```bash
runmacos [<project-id>] [--source <directory>] [--output <relative-path>]... --command '<shell script>' [--environment ID] [--no-cache]
runmacos --follow [--run ID]    # reattach; starts nothing
runmacos --cancel [--run ID]
runmacos --list-environments
runmacos --help
```

## Options

| Option | Value | Default | What it does |
| --- | --- | --- | --- |
| `--command` | shell script | required | The Bash script to run. It runs at the uploaded root with `-e -o pipefail`. |
| `<project-id>` | UUID | none | Upload this Project and run at its root. |
| `--source` | directory | none | Upload this directory instead. Relative to your current directory. With both, `--source` is what is uploaded. |
| `--output` | relative path | none | A file or directory to bring back. Repeat for more. |
| `--environment` | ID from `--list-environments` | the default | Run on another builder environment (macOS and Xcode version). |
| `--no-cache` | — | caches on | Runs without the builder caches and saves none. |
| `--follow` | — | — | Reattaches to a run already in progress, in any mode. On a finished run, says so and replays its saved output. |
| `--run` | run ID | the running run, else the newest | With `--follow` or `--cancel`. |
| `--cancel` | — | — | Asks the run to stop; waits up to 30 seconds for confirmation. |
| `--list-environments` | — | — | Lists the builder environments. |

Without a Project ID or `--source`, the script runs in an empty directory and no source is uploaded; a small package with the command and its helpers is still sent. `runmacos` takes no `--platform`, `--sign`, `--unsigned`, `--script` or `--additional-options`.

## On the builder

- `airbuild-xcode` is on `PATH`. The first `airbuild-xcode install` or `test` of a run brings back the Project's DerivedData, and the run saves it after the script; `archive` and plain `xcodebuild` get none. See [airbuild-xcode](https://air.build/docs/cli/airbuild-xcode/).
- `airbuild-cache` is on `PATH` to keep other files between runs. Whatever the script restores is saved again after it ends, every time. See [airbuild-cache](https://air.build/docs/cli/airbuild-cache/).
- Node, npm and pnpm are installed.
- No signing material is provided.

## Outputs

Each `--output` must be a concrete path relative to the working directory: no absolute paths, `..`, wildcards, symbolic links or special files, and no path inside another. A failed script still brings back the outputs that exist, with its own nonzero exit code. A script that passes but leaves out a declared output fails with exit code `65`.

## Output

```text
• Build started in the Environment. Run: <run-id>
• It runs to completion even if this command is interrupted (reattach with: runmacos --follow --run <run-id>).
Airbuild remote execution
… the script's output …
✓ Command succeeded in <time>.

✓ Command finished.
  Build: <build-id>
  Artifact: <path to the collected outputs>
```

Without `--output`, it prints `No outputs requested; skipping artifact download.`

## Running several

`runmacos` has its own slot, separate from `runbuild`, `runtest` and `runlinux`. Several `runmacos` executions can run at once. Starting one prints its run ID; when several are running, `--follow` and `--cancel` need `--run ID` (or a project ID only one of them uses). Ctrl-C only detaches.

## Exit codes

| Code | Meaning |
| --- | --- |
| `0` | The script passed and every output was written. |
| `1` | The run could not start or was lost. |
| `2` | A wrong option, or `--command` missing; nothing ran. |
| `65` | A declared output is missing or cannot be exported. |
| `130` | Canceled, or detached with Ctrl-C. |
| other | The script's own exit code. |

## Errors

| Message | What to do |
| --- | --- |
| `--command requires a nonempty shell script and is only available with runmacos and runlinux.` | Pass a script. |
| `--output requires a working-directory-relative path and is only available with runmacos and runlinux.` | Give a relative path. |
| `--platform takes a platform (…) and is only available with runbuild and runtest.` | Drop `--platform`. |
| `runmacos does not accept build or signing options.` | Drop `--sign` / `--unsigned`. |
| `--follow and --cancel cannot submit a command, outputs, or test options.` | Leave the command out when following or canceling. |
| `Declared output was not produced: <path>` | Make the script write it, or drop the `--output`. |
| `The command failed and its output files could not be downloaded.` | Run again; the exit code is the script's. |
| `N runmacos executions are running; choose one with --run.` | Pass one of the run IDs it lists. |
| `This Team's Environment is already running N runmacos executions, the limit.` | Wait for one to finish, or follow one. |

## Examples

```bash
# What the builder has, no source uploaded
runmacos --command 'xcodebuild -version; swift --version'
```

```bash
# Run a package's tests in the Project
runmacos 3f6c1a2e-8b4d-4f0a-9c1e-2d7b5a6e9f10 --command 'swift test'
```

```bash
# Build a worktree and bring back a report
runmacos --source ../feature-branch --output build/report.txt \
  --command 'mkdir -p build && swift build 2>&1 | tee build/report.txt'
```
