Skip to content

Commit

Permalink
Destination arch (#96)
Browse files Browse the repository at this point in the history
* Add optional arch to destination as input

* Add missing arch input def in action.yml

* withArch in destination(), print selected arch

* xcodebuild arch

- remove arch print
- fix lint
- run prepare

* xcodebuild destination arch

- move arch to arg -arch

* xcodebuild arch

- fix arch= syntax

---------

Co-authored-by: Max Howell <mxcl@me.com>
  • Loading branch information
idan-fido and mxcl committed Sep 9, 2024
1 parent ba8e153 commit 3deab1d
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 10 deletions.
5 changes: 5 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ inputs:
`mac-catalyst`
Leave unset and `xcodebuild` decides itself.
required: false
arch:
description: |
Either `arm64` `x86_64 `i386`
Leave unset and `xcodebuild` decides itself.
required: false
action:
description: |
* The most common actions are `test`, `build`.
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

21 changes: 15 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
verbosity,
xcselect,
} from './lib'
import type { Platform } from './lib'
import type { Arch, Platform } from './lib'
import xcodebuildX from './xcodebuild'
import * as artifact from '@actions/artifact'
import * as core from '@actions/core'
Expand All @@ -34,6 +34,7 @@ async function main() {

const swiftPM = fs.existsSync('Package.swift')
const platform = getPlatformInput('platform')
const arch = getArchInput('arch')
const selected = await xcselect(
getRangeInput('xcode'),
getRangeInput('swift')
Expand All @@ -58,7 +59,7 @@ async function main() {
await configureKeychain()
await configureProvisioningProfiles()

await build(await getScheme(workspace), workspace)
await build(await getScheme(workspace), workspace, arch)

if (core.getInput('upload-logs') == 'always') {
await uploadLogs()
Expand All @@ -72,6 +73,12 @@ async function main() {
return value as Platform
}

function getArchInput(input: string): Arch | undefined {
const value = core.getInput(input)
if (!value) return undefined
return value as Arch
}

function getRangeInput(input: string): Range | undefined {
const value = core.getInput(input)
if (!value) return undefined
Expand Down Expand Up @@ -179,26 +186,28 @@ async function main() {
await createProvisioningProfiles(mobileProfiles, profiles)
}

async function build(scheme?: string, workspace?: string) {
async function build(scheme?: string, workspace?: string, arch?: Arch) {
if (warningsAsErrors && actionIsTestable(action)) {
await xcodebuild('build', scheme, workspace)
await xcodebuild('build', scheme, workspace, arch)
}
await xcodebuild(action, scheme, workspace)
await xcodebuild(action, scheme, workspace, arch)
}

//// helper funcs

async function xcodebuild(
action?: string,
scheme?: string,
workspace?: string
workspace?: string,
arch?: Arch
) {
if (action === 'none') return

const title = ['xcodebuild', action].filter((x) => x).join(' ')
await core.group(title, async () => {
let args = destination
if (scheme) args = args.concat(['-scheme', scheme])
if (arch) args = args.concat([`-arch=${arch}`])
if (workspace) args = args.concat(['-workspace', workspace])
if (identity) args = args.concat(identity)
if (verbosity() == 'quiet') args.push('-quiet')
Expand Down
6 changes: 4 additions & 2 deletions src/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,8 @@ export type Platform =
| 'mac-catalyst'
| 'visionOS'

export type Arch = 'arm64' | 'x86_64' | 'i386'

export function getAction(
xcodeVersion: SemVer,
platform?: Platform
Expand Down Expand Up @@ -333,9 +335,9 @@ export async function getDestination(
return ['-destination', `id=${id}`]
}
case 'macOS':
return ['-destination', 'platform=macOS']
return ['-destination', `platform=macOS`]
case 'mac-catalyst':
return ['-destination', 'platform=macOS,variant=Mac Catalyst']
return ['-destination', `platform=macOS,variant=Mac Catalyst`]
case undefined:
if (semver.gte(xcodeVersion, '13.0.0')) {
//FIXME should parse output from xcodebuild -showdestinations
Expand Down

0 comments on commit 3deab1d

Please sign in to comment.