# runmacos

> 프로젝트 소스와 함께 또는 소스 없이 클라우드 macOS 빌더에서 셸 스크립트를 실행하고, 지정한 파일을 가져옵니다.

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

`runmacos`는 팀의 환경에서 Xcode가 있는 macOS 빌더로 Bash 스크립트 하나를 실행합니다. `airbuild.yaml`이 필요 없습니다. macOS와 Xcode 버전 확인, `swift test` 실행, macOS 앱 도구 실행처럼 샌드박스만으로는 할 수 없는 일에 쓰세요.

**클라우드 팀 전용**입니다. Mac 팀에서는 `runmacos is only available in cloud Teams; local Teams provide runtest.`와 함께 멈춥니다.

## 개요

```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
```

## 옵션

| 옵션 | 값 | 기본값 | 하는 일 |
| --- | --- | --- | --- |
| `--command` | 셸 스크립트 | 필수 | 실행할 Bash 스크립트. 업로드된 루트에서 `-e -o pipefail`로 실행됩니다. |
| `<project-id>` | UUID | 없음 | 이 프로젝트를 업로드하고 그 루트에서 실행합니다. |
| `--source` | 디렉터리 | 없음 | 대신 이 디렉터리를 업로드합니다. 현재 디렉터리 기준입니다. 둘 다 있으면 `--source`가 업로드됩니다. |
| `--output` | 상대 경로 | 없음 | 가져올 파일이나 디렉터리. 더 있으면 반복합니다. |
| `--environment` | `--list-environments`의 ID | 기본값 | 다른 빌더 환경(macOS와 Xcode 버전)에서 실행합니다. |
| `--no-cache` | — | 캐시 사용 | 빌더 캐시 없이 실행하고 아무것도 저장하지 않습니다. |
| `--follow` | — | — | 진행 중인 실행에 모드와 상관없이 다시 연결합니다. 끝난 실행이면 그렇다고 알리고 저장된 출력을 다시 보여 줍니다. |
| `--run` | 실행 ID | 실행 중인 실행, 없으면 가장 최근 것 | `--follow`나 `--cancel`과 함께 씁니다. |
| `--cancel` | — | — | 실행에 중지를 요청하고 확인을 최대 30초 기다립니다. |
| `--list-environments` | — | — | 빌더 환경을 나열합니다. |

프로젝트 ID나 `--source`가 없으면 스크립트는 빈 디렉터리에서 실행되고 소스는 업로드되지 않습니다. 다만 명령과 그 도우미가 담긴 작은 패키지는 전송됩니다. `runmacos`는 `--platform`, `--sign`, `--unsigned`, `--script`, `--additional-options`를 받지 않습니다.

## 빌더에서

- `PATH`에 `airbuild-xcode`가 있습니다. 실행에서 처음 실행하는 `airbuild-xcode install`이나 `test`가 프로젝트의 DerivedData를 되살리고, 스크립트가 끝나면 실행이 이를 저장합니다. `archive`와 일반 `xcodebuild`에는 적용되지 않습니다. [airbuild-xcode](https://air.build/ko/docs/cli/airbuild-xcode/)를 참고하세요.
- 다른 파일을 실행 사이에 보관할 수 있도록 `PATH`에 `airbuild-cache`가 있습니다. 스크립트가 복원한 것은 끝날 때마다 매번 다시 저장됩니다. [airbuild-cache](https://air.build/ko/docs/cli/airbuild-cache/)를 참고하세요.
- Node, npm, pnpm이 설치되어 있습니다.
- 서명 자료는 제공되지 않습니다.

## 출력물

각 `--output`은 작업 디렉터리 기준의 구체적인 경로여야 합니다. 절대 경로, `..`, 와일드카드, 심볼릭 링크, 특수 파일은 안 되며, 다른 경로 안에 들어 있는 경로도 안 됩니다. 스크립트가 실패해도 존재하는 출력물은 가져오며, 스크립트 자체의 0이 아닌 종료 코드로 끝납니다. 스크립트가 통과했지만 선언한 출력물을 만들지 않으면 종료 코드 `65`로 실패합니다.

## 출력

```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>
```

`--output`이 없으면 `No outputs requested; skipping artifact download.`를 출력합니다.

## 여러 개 실행하기

`runmacos`에는 `runbuild`, `runtest`, `runlinux`와 별개인 자기 슬롯이 있습니다. 여러 `runmacos` 실행을 동시에 돌릴 수 있습니다. 실행을 시작하면 실행 ID가 출력되며, 여러 개가 실행 중이면 `--follow`와 `--cancel`에 `--run ID`(또는 그중 하나만 쓰는 프로젝트 ID)가 필요합니다. Ctrl-C는 연결만 끊습니다.

## 종료 코드

| 코드 | 의미 |
| --- | --- |
| `0` | 스크립트가 통과했고 모든 출력물이 쓰였습니다. |
| `1` | 실행을 시작할 수 없었거나 잃어버렸습니다. |
| `2` | 잘못된 옵션이거나 `--command`가 빠져서 아무것도 실행되지 않았습니다. |
| `65` | 선언한 출력물이 없거나 내보낼 수 없습니다. |
| `130` | 취소되었거나 Ctrl-C로 연결을 끊었습니다. |
| 기타 | 스크립트 자체의 종료 코드. |

## 오류

| 메시지 | 해야 할 일 |
| --- | --- |
| `--command requires a nonempty shell script and is only available with runmacos and runlinux.` | 스크립트를 넘기세요. |
| `--output requires a working-directory-relative path and is only available with runmacos and runlinux.` | 상대 경로를 지정하세요. |
| `--platform takes a platform (…) and is only available with runbuild and runtest.` | `--platform`을 빼세요. |
| `runmacos does not accept build or signing options.` | `--sign` / `--unsigned`를 빼세요. |
| `--follow and --cancel cannot submit a command, outputs, or test options.` | follow하거나 취소할 때는 명령을 빼세요. |
| `Declared output was not produced: <path>` | 스크립트가 그 파일을 쓰게 하거나 `--output`을 빼세요. |
| `The command failed and its output files could not be downloaded.` | 다시 실행하세요. 종료 코드는 스크립트의 것입니다. |
| `N runmacos executions are running; choose one with --run.` | 나열된 실행 ID 중 하나를 넘기세요. |
| `This Team's Environment is already running N runmacos executions, the limit.` | 하나가 끝나기를 기다리거나 하나를 follow하세요. |

## 예시

```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'
```
