Skip to content
Merged
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
20 changes: 11 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,17 @@ or if you really need OS version, leave it on the loose side (e.g.
a device with Apple Developer account, because a Simulator UDID
[can not be used there](https://developer.apple.com/forums/thread/693026).

| Name | Sample values | Description |
| -------------------- | ------------------------ | ---------------------------------------------------------------------------------------------------------------------------------- |
| `model` | `iPhone 8` | Model of the device you'd like to launch |
| `os` | `iOS`, `tvOS`, `watchOS` | OS type of the device |
| `os_version` | `>=14.0` | OS version specification in semver format |
| `udid` | `ABCD-EFGH` | Specific UDID you'd like to launch |
| `erase_before_boot` | `true` | Whether the data should be erased from device before boot. Starting from a clean state helps getting a stable environment for tests |
| `wait_for_boot` | `false` | Whether the action must wait for the Simulator to finish booting requested image |
| `shutdown_after_job` | `true` | Whether to shutdown the launched Simulator after the workflow job has been finished |
| Name | Sample values | Description |
| ---------------------- | ------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `model` | `iPhone 8` | Model of the device you'd like to launch |
| `os` | `iOS`, `tvOS`, `watchOS` | OS type of the device |
| `os_version` | `>=14.0` | OS version specification in semver format |
| `udid` | `ABCD-EFGH` | Specific UDID you'd like to launch |
| `erase_before_boot` | `true` | Whether the data should be erased from device before boot. Starting from a clean state helps getting a stable environment for tests |
| `wait_for_boot` | `false` | Whether the action must wait for the Simulator to finish booting requested image |
| `boot_timeout_seconds` | `360` | Maximum number of seconds to wait for the Simulator to finish booting (0 disables the timeout) |
| `boot_retries` | `2` | Number of times to retry booting when waiting for the Simulator to finish booting fails. Setting this to 2 will result in 3 attempts: one normal attempt and two retries. |
| `shutdown_after_job` | `true` | Whether to shutdown the launched Simulator after the workflow job has been finished |

## Outputs

Expand Down
12 changes: 12 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,18 @@ inputs:
image
required: false
default: 'false'
boot_timeout_seconds:
description: >
Maximum number of seconds to wait for the Simulator to finish booting. Use
0 to disable the timeout.
required: false
default: '360'
boot_retries:
description: >
Number of times to retry booting when waiting for the Simulator to finish
booting fails.
required: false
default: '3'
shutdown_after_job:
description: >
Whether the Simulator should be shut down after the job has finished. This
Expand Down
127 changes: 79 additions & 48 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

25 changes: 24 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,31 @@ async function run(): Promise<void> {
await simctl('boot', device.udid)

if (boolean(core.getInput('wait_for_boot'))) {
const bootTimeoutSeconds = Number(core.getInput('boot_timeout_seconds'))
const bootRetries = Number(core.getInput('boot_retries'))

const bootTimeoutMs =
bootTimeoutSeconds > 0 ? bootTimeoutSeconds * 1000 : undefined

core.info(`Waiting for device to finish booting.`)
await simctl('bootstatus', device.udid)
const maxAttempts = bootRetries + 1
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
try {
await simctl('bootstatus', device.udid, {timeoutMs: bootTimeoutMs})
break
} catch (error) {
const message = error instanceof Error ? error.message : String(error)
core.warning(
`Bootstatus attempt ${attempt}/${maxAttempts} failed: ${message}`
)
if (attempt === maxAttempts) {
throw error
}
core.warning(`Retrying simulator boot...`)
await simctl('shutdown', device.udid)
await simctl('boot', device.udid)
}
}
}

core.setOutput('udid', device.udid)
Expand Down
21 changes: 16 additions & 5 deletions src/xcrun.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,28 @@ export async function getDevices(): Promise<DeviceInfo[]> {
return allDevices
}

export async function simctl(action: string, udid: string): Promise<void> {
await xcrun(`simctl ${action} ${udid}`)
type ExecOptions = {
timeoutMs?: number
}

async function xcrun(tail: string): Promise<string> {
export async function simctl(
action: string,
udid: string,
options: ExecOptions = {}
): Promise<void> {
await xcrun(`simctl ${action} ${udid}`, options)
}

async function xcrun(tail: string, options: ExecOptions = {}): Promise<string> {
const command = `xcrun ${tail}`
core.info(`$ ${command}`)

const execOptions =
options.timeoutMs === undefined
? {encoding: 'utf8'}
: {timeout: options.timeoutMs, encoding: 'utf8'}
let res: {stdout?: string; stderr?: string} | undefined
try {
res = await execAsync(command)
res = await execAsync(command, execOptions)
return res.stdout || ''
} catch (e) {
res = e as {stdout?: string; stderr?: string}
Expand Down
Loading