-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.mjs
70 lines (57 loc) · 1.83 KB
/
index.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import core from '@actions/core';
import exec from '@actions/exec';
async function installXcode(xcodeVersion, appleID, appleIDPassword) {
const IS_MACOS = process.platform === 'darwin';
if (!IS_MACOS) {
throw new Error(`${process.platform} is not supported!`);
}
if (
(await exec.exec('xcversion', ['select', xcodeVersion], {
ignoreReturnCode: true
})) != 0
) {
core.warning(`Xcode ${xcodeVersion} not avilable in local.`);
if (!appleID) {
throw new Error(`apple-id is required to download Xcode.`);
}
if (!appleIDPassword) {
throw new Error(`apple-id-password is required to download Xcode.`);
}
core.startGroup('Install Xcode');
await exec.exec('xcversion', ['update'], {
cwd: process.env.TMPDIR,
env: {
...process.env,
XCODE_INSTALL_USER: appleID,
XCODE_INSTALL_PASSWORD: appleIDPassword,
SPACESHIP_SKIP_2FA_UPGRADE: 1,
SPACESHIP_ONLY_ALLOW_INTERACTIVE_2FA: 1,
}
});
await exec.exec('xcversion', ['install', xcodeVersion], {
cwd: process.env.TMPDIR,
env: {
...process.env,
XCODE_INSTALL_USER: appleID,
XCODE_INSTALL_PASSWORD: appleIDPassword,
SPACESHIP_SKIP_2FA_UPGRADE: 1,
SPACESHIP_ONLY_ALLOW_INTERACTIVE_2FA: 1,
}
});
core.endGroup();
await exec.exec('xcversion', ['select', xcodeVersion]);
}
await exec.exec(`sudo xcodebuild -license accept`);
}
// most @actions toolkit packages have async methods
export async function run() {
try {
let xcodeVersion = core.getInput('xcode-version', { required: true });
let appleID = core.getInput('apple-id');
let appleIDPassword = core.getInput('apple-id-password');
await installXcode(xcodeVersion, appleID, appleIDPassword);
} catch (error) {
core.setFailed(error.message);
}
}
run();